Skip to content

Use setuptools_scm for version number #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,19 @@ def read_file(path_segments):
return f.read()


def exec_file(path_segments, name):
"""Extract a constant from a python file by looking for a line defining
the constant and executing it."""
result = {}
code = read_file(path_segments)
lines = [line for line in code.split('\n') if line.startswith(name)]
exec("\n".join(lines), result)
return result[name]


setup(
name="signedjson",
version=exec_file(("signedjson", "__init__.py",), "__version__"),
packages=["signedjson"],
description="Sign JSON with Ed25519 signatures",
use_scm_version=True,
setup_requires=["setuptools_scm"],
install_requires=[
"canonicaljson>=1.0.0",
"unpaddedbase64>=1.0.1",
"pynacl>=0.3.0",
"typing_extensions>=3.5",
'typing>=3.5;python_version<"3.5"',
"importlib_metadata",
],
long_description=read_file(("README.rst",)),
keywords="json",
Expand Down
8 changes: 7 additions & 1 deletion signedjson/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "1.1.0"
from importlib_metadata import version, PackageNotFoundError

try:
__version__ = version(__name__)
except PackageNotFoundError: # pragma: nocover
# package is not installed
pass