Skip to content

Commit 8e8663d

Browse files
committed
Automatically determine version from git tag
1 parent b3a469a commit 8e8663d

File tree

3 files changed

+40
-25
lines changed

3 files changed

+40
-25
lines changed

setup.py

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,12 @@
44
import re
55
from setuptools import setup
66
from setuptools.command.test import test as TestCommand
7+
from setuptools.command.build_py import build_py as BuildCommand
78

89
def read(fname):
910
with open(os.path.join(os.path.dirname(__file__), fname)) as fildes:
1011
return fildes.read()
1112

12-
def get_version():
13-
with open('vhdeps/__init__.py', 'r') as fildes:
14-
for line in fildes:
15-
match = re.match("__version__ = '([^']+)'\n", line)
16-
if match:
17-
return match.group(1)
18-
raise ValueError('Could not find package version')
19-
2013
class NoseTestCommand(TestCommand):
2114
def finalize_options(self):
2215
TestCommand.finalize_options(self)
@@ -28,25 +21,37 @@ def run_tests(self):
2821
import nose
2922
nose.run_exit(argv=['nosetests'])
3023

24+
class BuildWithVersionCommand(BuildCommand):
25+
def run(self):
26+
if not self.dry_run:
27+
version_fname = os.path.join(self.build_lib, 'vhdeps', 'version.py')
28+
with open(version_fname, 'w') as fildes:
29+
fildes.write('__version__ = """' + self.distribution.metadata.version + '"""\n')
30+
31+
BuildCommand.run(self)
32+
3133
setup(
32-
name = "vhdeps",
33-
version = get_version(),
34-
author = "Jeroen van Straten",
35-
author_email = "[email protected]",
34+
name = 'vhdeps',
35+
version_config={
36+
'version_format': '{tag}+{sha}',
37+
'starting_version': '0.0.1'
38+
},
39+
author = 'Jeroen van Straten',
40+
author_email = '[email protected]',
3641
description = (
37-
"VHDL dependency analyzer and simulation driver."
42+
'VHDL dependency analyzer and simulation driver.'
3843
),
39-
license = "Apache",
40-
keywords = "vhdl dependency analyzer simulation",
41-
url = "https://github.com/abs-tudelft/vhdeps",
44+
license = 'Apache',
45+
keywords = 'vhdl dependency analyzer simulation',
46+
url = 'https://github.com/abs-tudelft/vhdeps',
4247
long_description = read('README.md'),
4348
long_description_content_type = 'text/markdown',
4449
classifiers = [
45-
"Development Status :: 3 - Alpha",
46-
"Intended Audience :: Developers",
47-
"Topic :: Software Development :: Build Tools",
48-
"License :: OSI Approved :: Apache Software License",
49-
"Programming Language :: Python :: 3",
50+
'Development Status :: 3 - Alpha',
51+
'Intended Audience :: Developers',
52+
'Topic :: Software Development :: Build Tools',
53+
'License :: OSI Approved :: Apache Software License',
54+
'Programming Language :: Python :: 3',
5055
],
5156
project_urls = {
5257
'Source': 'https://github.com/abs-tudelft/vhdeps',
@@ -55,7 +60,14 @@ def run_tests(self):
5560
entry_points = {'console_scripts': ['vhdeps=vhdeps:run_cli']},
5661
python_requires = '>=3',
5762
install_requires = ['plumbum'],
58-
setup_requires = ['setuptools-lint', 'pylint'],
63+
setup_requires = [
64+
'better-setuptools-git-version',
65+
'setuptools-lint',
66+
'pylint'
67+
],
5968
tests_require = ['nose', 'coverage'],
60-
cmdclass = {'test': NoseTestCommand},
69+
cmdclass = {
70+
'test': NoseTestCommand,
71+
'build_py': BuildWithVersionCommand,
72+
},
6173
)

vhdeps/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
import argparse
2323
import vhdeps.vhdl as vhdl
2424
import vhdeps.target as target_mod
25-
26-
__version__ = '0.0.4'
25+
from vhdeps.version import __version__
2726

2827
def run_cli(args=None):
2928
"""Runs the vhdeps CLI. The command-line arguments are taken from `args`

vhdeps/version.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""Version metadata file. This file is overridden by setuptools with the
2+
actual version when the module is "built"."""
3+
4+
__version__ = 'not-installed'

0 commit comments

Comments
 (0)