Skip to content

Commit 988688c

Browse files
authored
Use setuptools_scm for version number (#7)
1 parent 479a06f commit 988688c

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

setup.py

+3-11
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,19 @@ def read_file(path_segments):
2929
return f.read()
3030

3131

32-
def exec_file(path_segments, name):
33-
"""Extract a constant from a python file by looking for a line defining
34-
the constant and executing it."""
35-
result = {}
36-
code = read_file(path_segments)
37-
lines = [line for line in code.split('\n') if line.startswith(name)]
38-
exec("\n".join(lines), result)
39-
return result[name]
40-
41-
4232
setup(
4333
name="signedjson",
44-
version=exec_file(("signedjson", "__init__.py",), "__version__"),
4534
packages=["signedjson"],
4635
description="Sign JSON with Ed25519 signatures",
36+
use_scm_version=True,
37+
setup_requires=["setuptools_scm"],
4738
install_requires=[
4839
"canonicaljson>=1.0.0",
4940
"unpaddedbase64>=1.0.1",
5041
"pynacl>=0.3.0",
5142
"typing_extensions>=3.5",
5243
'typing>=3.5;python_version<"3.5"',
44+
"importlib_metadata",
5345
],
5446
long_description=read_file(("README.rst",)),
5547
keywords="json",

signedjson/__init__.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,10 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
__version__ = "1.1.0"
15+
from importlib_metadata import version, PackageNotFoundError
16+
17+
try:
18+
__version__ = version(__name__)
19+
except PackageNotFoundError: # pragma: nocover
20+
# package is not installed
21+
pass

0 commit comments

Comments
 (0)