Skip to content

Commit d5a1645

Browse files
committed
Improved version retrieval in setup.py
1 parent 3caf782 commit d5a1645

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

setup.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,31 @@
1111
from codecs import open
1212
from os import path
1313

14-
from metsrw import __version__
1514

1615
HERE = path.abspath(path.dirname(__file__))
1716

1817

1918
# Get the long description from the relevant file
20-
with open(path.join(here, 'README.md'), encoding='utf-8') as f:
19+
with open(path.join(HERE, 'README.md'), encoding='utf-8') as f:
2120
long_description = f.read()
2221

2322

23+
def get_version():
24+
version = '0.1.0'
25+
with open(path.join(HERE, 'metsrw', '__init__.py')) as fi:
26+
for line in fi:
27+
if line.startswith('__version__'):
28+
parts = line.strip().split()
29+
try:
30+
version = parts[2].replace("'", '').replace('"', '').strip()
31+
except (IndexError, AttributeError):
32+
continue
33+
return version
34+
35+
2436
setup(
2537
name='metsrw',
26-
version=__version__,
38+
version=get_version(),
2739

2840
description='Library for dealing with METS files.',
2941
long_description=long_description,

0 commit comments

Comments
 (0)