Skip to content

Commit ea868f3

Browse files
committed
Improved version retrieval in setup.py
1 parent 21438f2 commit ea868f3

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,18 +11,30 @@
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
# Get the long description from the relevant file
19-
with open(path.join(here, 'README.md'), encoding='utf-8') as f:
18+
with open(path.join(HERE, 'README.md'), encoding='utf-8') as f:
2019
long_description = f.read()
2120

2221

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

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

0 commit comments

Comments
 (0)