Skip to content

Commit 4338e63

Browse files
author
Sylvain MARIE
committed
Added __version__ attribute. Fixes #20
1 parent fc7e81b commit 4338e63

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ after_success:
7070
else
7171
echo "File 'ci_tools/github_travis_rsa' has not been created, please check your encrypted repo token in .travis.yml, on the line starting with 'openssl aes-256-cbc...'"
7272
fi
73+
# -- create the _version.py file: actually not needed, done in setup now
74+
# - python ci_tools/write_version.py ./mini_lambda
7375

7476
deploy:
7577
# Deploy on PyPI on tags

ci_tools/write_version.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Authors: Sylvain Marie <sylvain.marie@se.com>
2+
#
3+
# License: BSD 3 clause
4+
5+
from os.path import abspath
6+
7+
import click
8+
from setuptools_scm import get_version
9+
10+
11+
@click.command()
12+
@click.argument('dest_folder')
13+
def write_version(dest_folder):
14+
file_name = '%s/_version.py' % dest_folder
15+
print("Writing version to file: %s" % abspath(file_name))
16+
get_version('.', write_to=file_name)
17+
18+
19+
if __name__ == '__main__':
20+
write_version()

mini_lambda/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,18 @@
66
from mini_lambda.main import _, L, F, C, Not, And, Or, Format, Get, In, Slice, InputVar, Constant, \
77
make_lambda_friendly, make_lambda_friendly_method, make_lambda_friendly_class, as_function, is_mini_lambda_expr
88

9+
try:
10+
# Distribution mode : import from _version.py generated by setuptools_scm during release
11+
from ._version import version as __version__
12+
except ImportError:
13+
# Source mode : use setuptools_scm to get the current version from src using git
14+
from setuptools_scm import get_version as _gv
15+
from os import path as _path
16+
__version__ = _gv(_path.join(_path.dirname(__file__), _path.pardir))
17+
18+
919
__all__ = [
20+
'__version__',
1021
# submodules
1122
'base', 'generated_magic_replacements', 'main', 'symbols', 'vars', # generated_magic
1223
# symbols

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
dependency_links=DEPENDENCY_LINKS,
131131

132132
# we're using git
133-
use_scm_version=True, # this provides the version + adds the date if local non-commited changes.
133+
use_scm_version={'write_to': '%s/_version.py' % DISTNAME}, # this provides the version + adds the date if local non-commited changes.
134134
# use_scm_version={'local_scheme':'dirty-tag'}, # this provides the version + adds '+dirty' if local non-commited changes.
135135
setup_requires=SETUP_REQUIRES,
136136

0 commit comments

Comments
 (0)