Skip to content

Commit dd8037c

Browse files
authored
Fix: module did not expose __version__ (#75)
Solution: declare `__version__` in `__init__.py` and parse the file with a regex to determine the version in `setup.py`.
1 parent 599fd56 commit dd8037c

File tree

2 files changed

+50
-27
lines changed

2 files changed

+50
-27
lines changed

aleph_message/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
from .models import MessagesResponse, parse_message
22

33
__all__ = ["parse_message", "MessagesResponse"]
4+
__version__ = "0.4.0"

setup.py

Lines changed: 49 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,60 @@
44
"""
55

66
import os
7+
import re
8+
9+
10+
def get_version():
11+
version_file = os.path.join("aleph_message", "__init__.py")
12+
initfile_lines = open(version_file, "rt").readlines()
13+
version = r"^__version__ = ['\"]([^'\"]*)['\"]"
14+
15+
for line in initfile_lines:
16+
mo = re.search(version, line, re.M)
17+
if mo:
18+
return mo.group(1)
19+
raise RuntimeError(f"Unable to find version string in {version_file}.")
20+
721

822
from setuptools import setup
923

1024
# allow setup.py to be run from any path
1125
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))
1226

13-
with open('README.md') as file:
27+
with open("README.md") as file:
1428
long_description = file.read()
1529

16-
setup(name='aleph-message',
17-
version='0.4.0',
18-
description='Aleph.im message specification ',
19-
long_description=long_description,
20-
long_description_content_type='text/markdown',
21-
author='Hugo Herter',
22-
author_email='[email protected]',
23-
url='https://github.com/aleph-im/aleph-message',
24-
packages=['aleph_message', 'aleph_message.models', 'aleph_message.models.execution'],
25-
package_data={"aleph_message": ["py.typed"],
26-
"aleph_message.models": ["py.typed"],
27-
"aleph_message.models.execution": ["py.typed"]},
28-
data_files=[],
29-
install_requires=[
30-
'pydantic~=1.10.5',
31-
'typing_extensions~=4.5.0',
32-
],
33-
license='MIT',
34-
platform='any',
35-
keywords="aleph.im message validation specification",
36-
classifiers=['Development Status :: 5 - Production/Stable',
37-
'Programming Language :: Python :: 3',
38-
'Intended Audience :: Developers',
39-
'Topic :: System :: Distributed Computing',
40-
],
41-
)
30+
setup(
31+
name="aleph-message",
32+
version=get_version(),
33+
description="Aleph.im message specification ",
34+
long_description=long_description,
35+
long_description_content_type="text/markdown",
36+
author="Hugo Herter",
37+
author_email="[email protected]",
38+
url="https://github.com/aleph-im/aleph-message",
39+
packages=[
40+
"aleph_message",
41+
"aleph_message.models",
42+
"aleph_message.models.execution",
43+
],
44+
package_data={
45+
"aleph_message": ["py.typed"],
46+
"aleph_message.models": ["py.typed"],
47+
"aleph_message.models.execution": ["py.typed"],
48+
},
49+
data_files=[],
50+
install_requires=[
51+
"pydantic~=1.10.5",
52+
"typing_extensions~=4.5.0",
53+
],
54+
license="MIT",
55+
platform="any",
56+
keywords="aleph.im message validation specification",
57+
classifiers=[
58+
"Development Status :: 5 - Production/Stable",
59+
"Programming Language :: Python :: 3",
60+
"Intended Audience :: Developers",
61+
"Topic :: System :: Distributed Computing",
62+
],
63+
)

0 commit comments

Comments
 (0)