diff options
| -rw-r--r-- | CHANGELOG.rst | 7 | ||||
| -rw-r--r-- | README.rst | 5 | ||||
| -rw-r--r-- | setuptools_scm/__init__.py | 25 |
3 files changed, 35 insertions, 2 deletions
diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b924c33..8e2cc7f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,10 @@ +v1.5.0 +======= + +* moved setuptools integration related code to own file +* support storing version strings into a module/text file + using the :code:`write_to` coniguration parameter + v1.4.0 ====== @@ -108,6 +108,11 @@ The Currently supported configuration keys are: :local_scheme: configures how the local component of the version is constructed either an entrypoint name or a callable +:write_to: + declares a text file or python file which is replaced with a file + containing the current version. + its ideal or creating a version.py file within the package + To use setuptools_scm in other Python code you can use the ``get_version`` function: diff --git a/setuptools_scm/__init__.py b/setuptools_scm/__init__.py index 80d051a..530a3bc 100644 --- a/setuptools_scm/__init__.py +++ b/setuptools_scm/__init__.py @@ -8,17 +8,37 @@ from .utils import trace from .version import format_version from .discover import find_matching_entrypoint +PYTHON_TEMPLATE = """\ +# coding: utf-8 +# file generated by setuptools_scm +# don't change, don't track in version control +version = {version!r} +""" def version_from_scm(root): ep = find_matching_entrypoint(root, 'setuptools_scm.parse_scm') if ep: return ep.load()(root) +def dump_version(root, version, write_to): + if not write_to: + return + target = os.path.join(root, write_to) + if target.endswith('.txt.'): + dump = version + elif target.endswith('.py'): + dump = PYTHON_TEMPLATE.format(version=version) + + with open(target) as fp: + if fp.read() == dump: + return + with open(target, 'w') as fp: + fp.write(dump) def get_version(root='.', version_scheme='guess-next-dev', local_scheme='node-and-date', - ): + write_to=None): root = os.path.abspath(root) trace('root', repr(root)) @@ -27,8 +47,9 @@ def get_version(root='.', if version: if isinstance(version, str): return version - return format_version( + version = format_version( version, version_scheme=version_scheme, local_scheme=local_scheme) + dump_version(root=root, version=version, write_to=write_to) return version |
