[Python-modules-commits] [setuptools-scm] 01/03: Import setuptools-scm_1.10.1.orig.tar.bz2
Dmitry Shachnev
mitya57 at moszumanska.debian.org
Tue Dec 15 17:10:03 UTC 2015
This is an automated email from the git hooks/post-receive script.
mitya57 pushed a commit to branch master
in repository setuptools-scm.
commit b08aa7e7cb402c11adc6e793320215f6f62f54e4
Author: Dmitry Shachnev <mitya57 at gmail.com>
Date: Tue Dec 15 20:06:34 2015 +0300
Import setuptools-scm_1.10.1.orig.tar.bz2
---
.hgtags | 1 +
CHANGELOG.rst | 26 +++++
PKG-INFO | 38 ++++++-
README.rst | 36 +++++-
setup.cfg | 5 +-
setup.py | 8 +-
setuptools_scm.egg-info/PKG-INFO | 38 ++++++-
setuptools_scm.egg-info/SOURCES.txt | 4 +
setuptools_scm.egg-info/entry_points.txt | 6 +
setuptools_scm/__init__.py | 55 +++++++--
setuptools_scm/__main__.py | 5 +-
setuptools_scm/git.py | 7 +-
setuptools_scm/hg.py | 6 +-
setuptools_scm/version.py | 4 +-
testing/conftest.py | 54 +++++++++
testing/test_basic_api.py | 184 +++++--------------------------
testing/test_git.py | 44 ++++++++
testing/test_main.py | 9 ++
testing/test_mercurial.py | 97 ++++++++++++++++
19 files changed, 443 insertions(+), 184 deletions(-)
diff --git a/.hgtags b/.hgtags
new file mode 100644
index 0000000..1af47c2
--- /dev/null
+++ b/.hgtags
@@ -0,0 +1 @@
+1092123ef78598eade56aa9c57e484f3670c8da8 v1.9.0
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 7b789e8..02f25ce 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -1,4 +1,30 @@
+v1.10.1
+=======
+* fix issue #73 - in hg pre commit merge, consider parent1 instead of failing
+
+v1.10.0
+=======
+
+* add support for overriding the version number via the
+ environment variable SETUPTOOLS_SCM_PRETEND_VERSION
+
+* fix isssue #63 by adding the --match parameter to the git describe call
+ and prepare the possibility of passing more options to scm backends
+
+* fix issue #70 and #71 by introducing the parse keyword
+ to specify custom scm parsing, its an expert feature,
+ use with caution
+
+ this change also introduces the setuptools_scm.parse_scm_fallback
+ entrypoint which can be used to register custom archive fallbacks
+
+
+v1.9.0
+======
+
+* Add :code:`relative_to` parameter to :code:`get_version` function;
+ fixes #44 per #45.
v1.8.0
======
diff --git a/PKG-INFO b/PKG-INFO
index 08cf7ae..51a2edb 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: setuptools_scm
-Version: 1.8.0
+Version: 1.10.1
Summary: the blessed package to manage your versions by scm tags
Home-page: https://github.com/pypa/setuptools_scm/
Author: Ronny Pfannschmidt
@@ -13,7 +13,7 @@ Description: setuptools_scm
in scm metadata instead of declaring them as the version argument
or in a scm managed file.
- It also handles file finders for the supperted scm's.
+ It also handles file finders for the supported scm's.
.. image:: https://travis-ci.org/pypa/setuptools_scm.svg?branch=master
:target: https://travis-ci.org/pypa/setuptools_scm
@@ -51,6 +51,17 @@ Description: setuptools_scm
version = get_version()
+ Notable Plugins
+ ----------------
+
+ `setuptools_scm_git_archive <https://pypi.python.org/pypi/setuptools_scm_git_archive>`_
+ provides partial support for obtaining versions from git archvies
+ that belong to tagged versions. The only reason for not including
+ it in setuptools-scm itself is git/github not supporting
+ sufficient metadata for untagged/followup commits,
+ which is preventing a consistent UX.
+
+
Default versioning scheme
--------------------------
@@ -134,6 +145,18 @@ Description: setuptools_scm
a newstyle format string thats given the current version as
the :code:`version` keyword argument for formatting
+ :relative_to:
+ a file from which root may be resolved. typically called by a
+ script or module that is not
+ in the root of the repository to direct setuptools_scm to the
+ root of the repository by supplying ``__file__``.
+
+ :parse:
+ a function that will be used instead of the discovered scm for parsing the version,
+ use with caution, this is a expert function and you should be closely familiar
+ with the setuptools_scm internals to use it
+
+
To use setuptools_scm in other Python code you can use the
``get_version`` function:
@@ -146,6 +169,15 @@ Description: setuptools_scm
keyword arguments.
+ Environment Variables
+ ---------------------
+
+ :SETUPTOOLS_SCM_PRETEND_VERSION:
+ when defined and not empty,
+ its used as the primary source for the version number
+ in which case it will be a unparsed string
+
+
Extending setuptools_scm
------------------------
@@ -205,7 +237,7 @@ Description: setuptools_scm
To support usage in :code:`setup.py` passing a callable into use_scm_version
is supported.
- Within that callable, setuptools_scm is availiable for import.
+ Within that callable, setuptools_scm is available for import.
The callable must return the configuration.
diff --git a/README.rst b/README.rst
index 2feea7e..9b4b857 100644
--- a/README.rst
+++ b/README.rst
@@ -5,7 +5,7 @@ setuptools_scm
in scm metadata instead of declaring them as the version argument
or in a scm managed file.
-It also handles file finders for the supperted scm's.
+It also handles file finders for the supported scm's.
.. image:: https://travis-ci.org/pypa/setuptools_scm.svg?branch=master
:target: https://travis-ci.org/pypa/setuptools_scm
@@ -43,6 +43,17 @@ In oder to use setuptools_scm for sphinx config
version = get_version()
+Notable Plugins
+----------------
+
+`setuptools_scm_git_archive <https://pypi.python.org/pypi/setuptools_scm_git_archive>`_
+provides partial support for obtaining versions from git archvies
+that belong to tagged versions. The only reason for not including
+it in setuptools-scm itself is git/github not supporting
+sufficient metadata for untagged/followup commits,
+which is preventing a consistent UX.
+
+
Default versioning scheme
--------------------------
@@ -126,6 +137,18 @@ The Currently supported configuration keys are:
a newstyle format string thats given the current version as
the :code:`version` keyword argument for formatting
+:relative_to:
+ a file from which root may be resolved. typically called by a
+ script or module that is not
+ in the root of the repository to direct setuptools_scm to the
+ root of the repository by supplying ``__file__``.
+
+:parse:
+ a function that will be used instead of the discovered scm for parsing the version,
+ use with caution, this is a expert function and you should be closely familiar
+ with the setuptools_scm internals to use it
+
+
To use setuptools_scm in other Python code you can use the
``get_version`` function:
@@ -138,6 +161,15 @@ It optionally accepts the keys of the ``use_scm_version`` parameter as
keyword arguments.
+Environment Variables
+---------------------
+
+:SETUPTOOLS_SCM_PRETEND_VERSION:
+ when defined and not empty,
+ its used as the primary source for the version number
+ in which case it will be a unparsed string
+
+
Extending setuptools_scm
------------------------
@@ -197,7 +229,7 @@ Importing in setup.py
To support usage in :code:`setup.py` passing a callable into use_scm_version
is supported.
-Within that callable, setuptools_scm is availiable for import.
+Within that callable, setuptools_scm is available for import.
The callable must return the configuration.
diff --git a/setup.cfg b/setup.cfg
index 0bcdc12..293cc39 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -4,8 +4,11 @@ universal = 1
[devpi:upload]
formats = sdist,bdist_wheel
+[aliases]
+release = sdist bdist_wheel upload
+
[egg_info]
-tag_date = 0
tag_build =
+tag_date = 0
tag_svn_revision = 0
diff --git a/setup.py b/setup.py
index a292c97..23c344b 100644
--- a/setup.py
+++ b/setup.py
@@ -63,7 +63,7 @@ arguments = dict(
url='https://github.com/pypa/setuptools_scm/',
zip_safe=True,
# pass here since entrypints are not yet registred
- version="1.8.0",
+ version="1.10.1",
author='Ronny Pfannschmidt',
author_email='opensource at ronnypfannschmidt.de',
description=('the blessed package to manage your versions by scm tags'),
@@ -82,6 +82,12 @@ arguments = dict(
[setuptools_scm.parse_scm]
.hg = setuptools_scm.hg:parse
.git = setuptools_scm.git:parse
+
+ # those are left here for backward compatibility in the 1.x series
+ .hg_archival.txt = setuptools_scm.hg:parse_archival
+ PKG-INFO = setuptools_scm.hacks:parse_pkginfo
+
+ [setuptools_scm.parse_scm_fallback]
.hg_archival.txt = setuptools_scm.hg:parse_archival
PKG-INFO = setuptools_scm.hacks:parse_pkginfo
diff --git a/setuptools_scm.egg-info/PKG-INFO b/setuptools_scm.egg-info/PKG-INFO
index 94febd6..e1c9149 100644
--- a/setuptools_scm.egg-info/PKG-INFO
+++ b/setuptools_scm.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: setuptools-scm
-Version: 1.8.0
+Version: 1.10.1
Summary: the blessed package to manage your versions by scm tags
Home-page: https://github.com/pypa/setuptools_scm/
Author: Ronny Pfannschmidt
@@ -13,7 +13,7 @@ Description: setuptools_scm
in scm metadata instead of declaring them as the version argument
or in a scm managed file.
- It also handles file finders for the supperted scm's.
+ It also handles file finders for the supported scm's.
.. image:: https://travis-ci.org/pypa/setuptools_scm.svg?branch=master
:target: https://travis-ci.org/pypa/setuptools_scm
@@ -51,6 +51,17 @@ Description: setuptools_scm
version = get_version()
+ Notable Plugins
+ ----------------
+
+ `setuptools_scm_git_archive <https://pypi.python.org/pypi/setuptools_scm_git_archive>`_
+ provides partial support for obtaining versions from git archvies
+ that belong to tagged versions. The only reason for not including
+ it in setuptools-scm itself is git/github not supporting
+ sufficient metadata for untagged/followup commits,
+ which is preventing a consistent UX.
+
+
Default versioning scheme
--------------------------
@@ -134,6 +145,18 @@ Description: setuptools_scm
a newstyle format string thats given the current version as
the :code:`version` keyword argument for formatting
+ :relative_to:
+ a file from which root may be resolved. typically called by a
+ script or module that is not
+ in the root of the repository to direct setuptools_scm to the
+ root of the repository by supplying ``__file__``.
+
+ :parse:
+ a function that will be used instead of the discovered scm for parsing the version,
+ use with caution, this is a expert function and you should be closely familiar
+ with the setuptools_scm internals to use it
+
+
To use setuptools_scm in other Python code you can use the
``get_version`` function:
@@ -146,6 +169,15 @@ Description: setuptools_scm
keyword arguments.
+ Environment Variables
+ ---------------------
+
+ :SETUPTOOLS_SCM_PRETEND_VERSION:
+ when defined and not empty,
+ its used as the primary source for the version number
+ in which case it will be a unparsed string
+
+
Extending setuptools_scm
------------------------
@@ -205,7 +237,7 @@ Description: setuptools_scm
To support usage in :code:`setup.py` passing a callable into use_scm_version
is supported.
- Within that callable, setuptools_scm is availiable for import.
+ Within that callable, setuptools_scm is available for import.
The callable must return the configuration.
diff --git a/setuptools_scm.egg-info/SOURCES.txt b/setuptools_scm.egg-info/SOURCES.txt
index fe48939..2d53d5f 100644
--- a/setuptools_scm.egg-info/SOURCES.txt
+++ b/setuptools_scm.egg-info/SOURCES.txt
@@ -1,4 +1,5 @@
.gitignore
+.hgtags
.travis.yml
CHANGELOG.rst
LICENSE
@@ -25,4 +26,7 @@ setuptools_scm.egg-info/zip-safe
testing/conftest.py
testing/test_basic_api.py
testing/test_functions.py
+testing/test_git.py
+testing/test_main.py
+testing/test_mercurial.py
testing/test_regressions.py
\ No newline at end of file
diff --git a/setuptools_scm.egg-info/entry_points.txt b/setuptools_scm.egg-info/entry_points.txt
index 2dbdcbd..7994f95 100644
--- a/setuptools_scm.egg-info/entry_points.txt
+++ b/setuptools_scm.egg-info/entry_points.txt
@@ -8,6 +8,12 @@
[setuptools_scm.parse_scm]
.hg = setuptools_scm.hg:parse
.git = setuptools_scm.git:parse
+
+ # those are left here for backward compatibility in the 1.x series
+ .hg_archival.txt = setuptools_scm.hg:parse_archival
+ PKG-INFO = setuptools_scm.hacks:parse_pkginfo
+
+ [setuptools_scm.parse_scm_fallback]
.hg_archival.txt = setuptools_scm.hg:parse_archival
PKG-INFO = setuptools_scm.hacks:parse_pkginfo
diff --git a/setuptools_scm/__init__.py b/setuptools_scm/__init__.py
index 66fbff3..002a1f8 100644
--- a/setuptools_scm/__init__.py
+++ b/setuptools_scm/__init__.py
@@ -9,6 +9,9 @@ from .utils import trace
from .version import format_version
from .discover import find_matching_entrypoint
+PRETEND_KEY = 'SETUPTOOLS_SCM_PRETEND_VERSION'
+
+
TEMPLATES = {
'.py': """\
# coding: utf-8
@@ -24,16 +27,13 @@ string_types = (str,) if PY3 else (str, unicode) # noqa
def version_from_scm(root):
- ep = find_matching_entrypoint(root, 'setuptools_scm.parse_scm')
+ return _version_from_entrypoint(root, 'setuptools_scm.parse_scm')
+
+
+def _version_from_entrypoint(root, entrypoint):
+ ep = find_matching_entrypoint(root, entrypoint)
if ep:
return ep.load()(root)
- raise LookupError(
- "setuptools-scm was unable to detect version for %r.\n\n"
- "Make sure you're not using GitHub's tarballs (or similar ones), as "
- "those don't contain the necessary metadata. Use PyPI's tarballs "
- "instead.\n\nFor example, if you're using pip, instead of "
- "https://github.com/user/proj/archive/master.zip "
- "use git+https://github.com/user/proj.git#egg=proj" % root)
def dump_version(root, version, write_to, template=None):
@@ -56,15 +56,50 @@ def dump_version(root, version, write_to, template=None):
fp.write(dump)
+def _do_parse(root, parse):
+ pretended = os.environ.get(PRETEND_KEY)
+ if pretended:
+ return pretended
+
+ if parse:
+ version = parse(root) or _version_from_entrypoint(
+ root, 'setuptools_scm.parse_scm_fallback')
+ else:
+ # include fallbacks after dropping them from the main entrypoint
+ version = version_from_scm(root)
+
+ if version:
+ return version
+
+ raise LookupError(
+ "setuptools-scm was unable to detect version for %r.\n\n"
+ "Make sure you're not using GitHub's tarballs (or similar ones), as "
+ "those don't contain the necessary metadata. Use PyPI's tarballs "
+ "instead.\n\nFor example, if you're using pip, instead of "
+ "https://github.com/user/proj/archive/master.zip "
+ "use git+https://github.com/user/proj.git#egg=proj" % root)
+
+
def get_version(root='.',
version_scheme='guess-next-dev',
local_scheme='node-and-date',
write_to=None,
- write_to_template=None):
+ write_to_template=None,
+ relative_to=None,
+ parse=None,
+ ):
+ """
+ If supplied, relative_to should be a file from which root may
+ be resolved. Typically called by a script or module that is not
+ in the root of the repository to direct setuptools_scm to the
+ root of the repository by supplying ``__file__``.
+ """
+ if relative_to:
+ root = os.path.join(os.path.dirname(relative_to), root)
root = os.path.abspath(root)
trace('root', repr(root))
- version = version_from_scm(root)
+ version = _do_parse(root, parse)
if version:
if isinstance(version, string_types):
diff --git a/setuptools_scm/__main__.py b/setuptools_scm/__main__.py
index 3f772ab..b495aeb 100644
--- a/setuptools_scm/__main__.py
+++ b/setuptools_scm/__main__.py
@@ -1,7 +1,8 @@
from __future__ import print_function
import sys
-from setuptools_scm import get_version, find_files, \
- _warn_if_setuptools_outdated
+from setuptools_scm import get_version
+from setuptools_scm.integration import find_files
+from setuptools_scm.version import _warn_if_setuptools_outdated
if __name__ == '__main__':
_warn_if_setuptools_outdated()
diff --git a/setuptools_scm/git.py b/setuptools_scm/git.py
index b271be0..40b0f77 100644
--- a/setuptools_scm/git.py
+++ b/setuptools_scm/git.py
@@ -4,10 +4,13 @@ from os.path import abspath, realpath
FILES_COMMAND = 'git ls-files'
+DEFAULT_DESCRIBE = 'git describe --dirty --tags --long --match *.*'
-def parse(root):
+def parse(root, describe_command=DEFAULT_DESCRIBE):
real_root, _, ret = do_ex('git rev-parse --show-toplevel', root)
+ if ret:
+ return
trace('real root', real_root)
if abspath(realpath(real_root)) != abspath(realpath(root)):
return
@@ -15,7 +18,7 @@ def parse(root):
if ret:
return meta('0.0')
rev_node = rev_node[:7]
- out, err, ret = do_ex('git describe --dirty --tags --long', root)
+ out, err, ret = do_ex(describe_command, root)
if '-' not in out and '.' not in out:
revs = do('git rev-list HEAD', root)
count = revs.count('\n')
diff --git a/setuptools_scm/hg.py b/setuptools_scm/hg.py
index aafa55f..e7a77e1 100644
--- a/setuptools_scm/hg.py
+++ b/setuptools_scm/hg.py
@@ -31,10 +31,12 @@ def parse(root):
trace('initial node', root)
return meta('0.0', dirty=dirty)
- cmd = 'hg parents --template "{latesttag} {latesttagdistance}"'
+ # the newline is needed for merge stae, see issue 72
+ cmd = 'hg parents --template "{latesttag} {latesttagdistance}\n"'
out = do(cmd, root)
try:
- tag, dist = out.split()
+ # in merge state we assume parent 1 is fine
+ tag, dist = out.splitlines()[0].split()
if tag == 'null':
tag = '0.0'
dist = int(dist) + 1
diff --git a/setuptools_scm/version.py b/setuptools_scm/version.py
index a546e44..4848dfc 100644
--- a/setuptools_scm/version.py
+++ b/setuptools_scm/version.py
@@ -22,8 +22,8 @@ def _warn_if_setuptools_outdated():
def callable_or_entrypoint(group, callable_or_name):
trace('ep', (group, callable_or_name))
if isinstance(callable_or_name, str):
- ep = next(iter_entry_points(group, callable_or_name))
- return ep.load()
+ for ep in iter_entry_points(group, callable_or_name):
+ return ep.load()
else:
return callable_or_name
diff --git a/testing/conftest.py b/testing/conftest.py
index d27814e..724e3ca 100644
--- a/testing/conftest.py
+++ b/testing/conftest.py
@@ -1,4 +1,7 @@
import os
+import itertools
+import pytest
+
os.environ['SETUPTOOLS_SCM_DEBUG'] = '1'
VERSION_PKGS = ['setuptools', 'setuptools_scm']
@@ -10,3 +13,54 @@ def pytest_report_header():
version = pkg_resources.get_distribution(pkg).version
res.append('%s version %s' % (pkg, version))
return res
+
+
+class Wd(object):
+ commit_command = None
+ add_command = None
+
+ def __init__(self, cwd):
+ self.cwd = cwd
+ self.__counter = itertools.count()
+
+ def __call__(self, cmd, **kw):
+ if kw:
+ cmd = cmd.format(**kw)
+ from setuptools_scm.utils import do
+ return do(cmd, self.cwd)
+
+ def write(self, name, value, **kw):
+ filename = self.cwd.join(name)
+ if kw:
+ value = value.format(**kw)
+ filename.write(value)
+ return filename
+
+ def _reason(self, given_reason):
+ if given_reason is None:
+ return 'number-{c}'.format(c=next(self.__counter))
+ else:
+ return given_reason
+
+ def commit(self, reason=None):
+ reason = self._reason(reason)
+ self(self.commit_command, reason=reason)
+
+ def commit_testfile(self, reason=None):
+ reason = self._reason(reason)
+ self.write('test.txt', 'test {reason}', reason=reason)
+ self(self.add_command)
+ self.commit(reason=reason)
+
+ @property
+ def version(self):
+ __tracebackhide__ = True
+ from setuptools_scm import get_version
+ version = get_version(root=str(self.cwd))
+ print(version)
+ return version
+
+
+ at pytest.fixture
+def wd(tmpdir):
+ return Wd(tmpdir)
diff --git a/testing/test_basic_api.py b/testing/test_basic_api.py
index dcd0165..4132c27 100644
--- a/testing/test_basic_api.py
+++ b/testing/test_basic_api.py
@@ -3,22 +3,9 @@ import py
import pytest
import setuptools_scm
-from setuptools_scm import format_version
-from setuptools_scm import integration
from setuptools_scm import dump_version
-
from setuptools_scm.utils import data_from_mime, do
-from setuptools_scm.hg import archival_to_version
-
-
-def get_version(root, method='get_version', __tracebackhide__=False, **kw):
- call = getattr(setuptools_scm, method)
- data = call(root=root.strpath, **kw)
- if isinstance(data, dict):
- return format_version(data)
- else:
- return data
@pytest.mark.parametrize('cmd', ['ls', 'dir'])
@@ -28,35 +15,9 @@ def test_do(cmd, tmpdir):
do(cmd, str(tmpdir))
-class Wd(object):
- def __init__(self, cwd):
- self.cwd = cwd
-
- def __call__(self, cmd):
- return do(cmd, self.cwd)
-
- def write(self, name, value):
- filename = self.cwd.join(name)
- filename.write(value)
- return filename
-
- @property
- def version(self):
- __tracebackhide__ = True
- version = get_version(self.cwd, __tracebackhide__=True)
- print(version)
- return version
-
-
- at pytest.fixture
-def wd(tmpdir):
- return Wd(tmpdir)
-
-
-def test_data_from_mime(wd):
- tmpfile = wd.write(
- 'test.archival',
- 'name: test\nrevision: 1')
+def test_data_from_mime(tmpdir):
+ tmpfile = tmpdir.join('test.archival')
+ tmpfile.write('name: test\nrevision: 1')
res = data_from_mime(str(tmpfile))
assert res == {
@@ -65,135 +26,40 @@ def test_data_from_mime(wd):
}
-archival_mapping = {
- '1.0': {'tag': '1.0'},
- '1.1.dev3+n000000000000': {
- 'latesttag': '1.0',
- 'latesttagdistance': '3',
- 'node': '0'*20,
- },
- '0.0': {
- 'node': '0'*20,
- },
- '1.2.2': {'tag': 'release-1.2.2'},
- '1.2.2.dev0': {'tag': 'release-1.2.2.dev'},
-
-}
-
-
- at pytest.mark.parametrize('expected,data', sorted(archival_mapping.items()))
-def test_archival_to_version(expected, data):
- version = archival_to_version(data)
- assert format_version(
- version,
- version_scheme='guess-next-dev',
- local_scheme='node-and-date') == expected
-
-
-def test_version_from_git(wd):
- wd('git init')
- wd('git config user.email test at example.com')
- wd('git config user.name "a test"')
- assert wd.version == '0.0'
- wd.write('test.txt', 'test')
- wd('git add test.txt')
- wd('git commit -m commit')
-
- assert wd.version.startswith('0.1.dev1+')
- assert not wd.version.endswith('1-')
-
- wd('git tag v0.1')
+def test_version_from_pkginfo(wd):
+ wd.write('PKG-INFO', 'Version: 0.1')
assert wd.version == '0.1'
- wd.write('test.txt', 'test2')
- assert wd.version.startswith('0.2.dev0+')
- wd('git add test.txt')
- wd('git commit -m commit')
- assert wd.version.startswith('0.2.dev1+')
- wd('git tag version-0.2')
- assert wd.version.startswith('0.2')
-
-# XXX: better tests for tag prefixes
-def test_version_from_hg_id(wd):
- wd('hg init')
- assert wd.version == '0.0'
- wd.write('test.txt', 'test')
- wd('hg add test.txt')
- wd('hg commit -m commit -u test -d "0 0"')
-
- assert wd.version.startswith('0.1.dev2+')
-
- # tagging commit is considered the tag
- wd('hg tag v0.1 -u test -d "0 0"')
- assert wd.version == '0.1'
- wd.write('test.txt', 'test2')
-
- wd('hg commit -m commit2 -u test -d "0 0"')
-
- assert wd.version.startswith('0.2.dev2')
-
- wd('hg up v0.1')
- assert wd.version == '0.1'
-
- # commit originating from the taged revision
- # that is not a actual tag
- wd.write('test.txt', 'test2')
- wd('hg commit -m commit3 -u test -d "0 0"')
- assert wd.version.startswith('0.2.dev1+')
-
-
-def test_version_from_archival(tmpdir):
- tmpdir.join('.hg_archival.txt').write(
- 'node: 000000000000\n'
- 'tag: 0.1\n'
- )
- assert get_version(tmpdir) == '0.1'
-
- tmpdir.join('.hg_archival.txt').write(
- 'node: 000000000000\n'
- 'latesttag: 0.1\n'
- 'latesttagdistance: 3\n'
- )
-
- assert get_version(tmpdir) == '0.2.dev3+n000000000000'
-
-
-def test_version_from_pkginfo(tmpdir):
- tmpdir.join('PKG-INFO').write('Version: 0.1')
- assert get_version(tmpdir) == '0.1'
+def assert_root(monkeypatch, expected_root):
+ """
+ Patch version_from_scm to simply assert that root is expected root
+ """
+ def assertion(root, unused_parse):
+ assert root == expected_root
+ monkeypatch.setattr(setuptools_scm, '_do_parse', assertion)
def test_root_parameter_creation(monkeypatch):
- def assert_cwd(root, cache_file=None):
- assert root == os.getcwd()
- monkeypatch.setattr(setuptools_scm, 'version_from_scm', assert_cwd)
+ assert_root(monkeypatch, os.getcwd())
setuptools_scm.get_version()
def test_root_parameter_pass_by(monkeypatch):
- def assert_root_tmp(root):
- assert root == os.path.abspath('/tmp')
- monkeypatch.setattr(setuptools_scm, 'version_from_scm', assert_root_tmp)
+ assert_root(monkeypatch, '/tmp')
setuptools_scm.get_version(root='/tmp')
-def test_find_files_stop_at_root_hg(wd):
- wd('hg init')
- wd.write('test.txt', 'test')
- wd('hg add .')
- wd('hg commit -m test -u test')
- wd.cwd.ensure('project/setup.cfg')
- assert integration .find_files(str(wd.cwd/'project')) == []
+def test_pretended(monkeypatch):
+ pretense = '2345'
+ monkeypatch.setenv(setuptools_scm.PRETEND_KEY, pretense)
+ assert setuptools_scm.get_version() == pretense
-def test_find_files_stop_at_root_git(wd):
- wd('git init')
- wd.write('test.txt', 'test')
- wd('git add .')
- wd('git commit -m test -u test')
- wd.cwd.ensure('project/setup.cfg')
- assert integration.find_files(str(wd.cwd/'project')) == []
+def test_root_relative_to(monkeypatch):
+ assert_root(monkeypatch, '/tmp/alt')
+ __file__ = '/tmp/module/file.py'
+ setuptools_scm.get_version(root='../alt', relative_to=__file__)
def test_dump_version(tmpdir):
@@ -206,3 +72,9 @@ def test_dump_version(tmpdir):
assert repr('1.0') in content
import ast
ast.parse(content)
+
+
+def test_parse_plain():
+ def parse(root):
+ return 'tricked you'
+ assert setuptools_scm.get_version(parse=parse) == 'tricked you'
diff --git a/testing/test_git.py b/testing/test_git.py
new file mode 100644
index 0000000..5401b66
--- /dev/null
+++ b/testing/test_git.py
@@ -0,0 +1,44 @@
+from setuptools_scm import integration
+import pytest
+
+
+ at pytest.fixture
+def wd(wd):
+ wd('git init')
+ wd('git config user.email test at example.com')
+ wd('git config user.name "a test"')
+ wd.add_command = 'git add .'
+ wd.commit_command = 'git commit -m test-{reason}'
+ return wd
+
+
+def test_version_from_git(wd):
+ assert wd.version == '0.0'
+
+ wd.commit_testfile()
+ assert wd.version.startswith('0.1.dev1+')
+ assert not wd.version.endswith('1-')
+
+ wd('git tag v0.1')
+ assert wd.version == '0.1'
+
+ wd.write('test.txt', 'test2')
+ assert wd.version.startswith('0.2.dev0+')
+
+ wd.commit_testfile()
+ assert wd.version.startswith('0.2.dev1+')
+
+ wd('git tag version-0.2')
+ assert wd.version.startswith('0.2')
+
+
+def test_find_files_stop_at_root_git(wd):
+ wd.commit_testfile()
+ wd.cwd.ensure('project/setup.cfg')
+ assert integration.find_files(str(wd.cwd/'project')) == []
+
+
+def test_alphanumeric_tags_match(wd):
+ wd.commit_testfile()
+ wd('git tag newstyle-development-started')
+ assert wd.version.startswith('0.1.dev1+')
diff --git a/testing/test_main.py b/testing/test_main.py
new file mode 100644
index 0000000..a7cbd75
--- /dev/null
+++ b/testing/test_main.py
@@ -0,0 +1,9 @@
+import os.path
+
+
+def test_main():
+ mainfile = os.path.join(
+ os.path.dirname(__file__), "..", "setuptools_scm", "__main__.py")
+ with open(mainfile) as f:
+ code = compile(f.read(), "__main__.py", 'exec')
+ exec(code)
diff --git a/testing/test_mercurial.py b/testing/test_mercurial.py
new file mode 100644
index 0000000..c98d19b
--- /dev/null
+++ b/testing/test_mercurial.py
@@ -0,0 +1,97 @@
+from setuptools_scm import format_version
+from setuptools_scm.hg import archival_to_version
+from setuptools_scm import integration
+
+import pytest
+
+
+ at pytest.fixture
+def wd(wd):
+ wd('hg init')
+ wd.add_command = 'hg add .'
+ wd.commit_command = 'hg commit -m test-{reason} -u test -d "0 0"'
+ return wd
+
+archival_mapping = {
+ '1.0': {'tag': '1.0'},
+ '1.1.dev3+n000000000000': {
+ 'latesttag': '1.0',
+ 'latesttagdistance': '3',
+ 'node': '0'*20,
+ },
+ '0.0': {
+ 'node': '0'*20,
+ },
+ '1.2.2': {'tag': 'release-1.2.2'},
+ '1.2.2.dev0': {'tag': 'release-1.2.2.dev'},
+
+}
+
+
+ at pytest.mark.parametrize('expected,data', sorted(archival_mapping.items()))
+def test_archival_to_version(expected, data):
+ version = archival_to_version(data)
+ assert format_version(
+ version,
+ version_scheme='guess-next-dev',
+ local_scheme='node-and-date') == expected
+
+
+def test_find_files_stop_at_root_hg(wd):
+ wd.commit_testfile()
+ wd.cwd.ensure('project/setup.cfg')
+ assert integration.find_files(str(wd.cwd/'project')) == []
+
+
+# XXX: better tests for tag prefixes
+def test_version_from_hg_id(wd):
+ assert wd.version == '0.0'
+
+ wd.commit_testfile()
+ assert wd.version.startswith('0.1.dev2+')
+
+ # tagging commit is considered the tag
+ wd('hg tag v0.1 -u test -d "0 0"')
+ assert wd.version == '0.1'
+
+ wd.commit_testfile()
+ assert wd.version.startswith('0.2.dev2')
+
+ wd('hg up v0.1')
+ assert wd.version == '0.1'
+
+ # commit originating from the taged revision
+ # that is not a actual tag
+ wd.commit_testfile()
+ assert wd.version.startswith('0.2.dev1+')
+
+
+def test_version_from_archival(wd):
+ # entrypoints are unordered,
+ # cleaning the wd ensure this test wont break randomly
+ wd.cwd.join('.hg').remove()
+ wd.write(
+ '.hg_archival.txt',
+ 'node: 000000000000\n'
+ 'tag: 0.1\n'
... 21 lines suppressed ...
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/setuptools-scm.git
More information about the Python-modules-commits
mailing list