Skip to content

Commit 8c13dfc

Browse files
merge my 2 branches to fix the travis setup and selfinstall testing
2 parents 7493894 + 8f4da52 commit 8c13dfc

File tree

11 files changed

+101
-21
lines changed

11 files changed

+101
-21
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ matrix:
1717
env: TOXENV=flake8
1818
- python: '3.5'
1919
env: TOXENV=flake8
20+
- python: '2.7'
21+
env: SELFINSTALL=1
22+
- python: '3.5'
23+
env: SELFINSTALL=1
2024
cache:
2125
files:
2226
- $HOME/.pip/cache

CHANGELOG.rst

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
1-
v1.15.1
1+
v1.15.3
22
=======
33

44
* bring back correctly getting our version in the own sdist, finalizes #114
55

66

7+
v1.15.2
8+
=======
9+
10+
* fix issue #128: return None when a scm specific parse fails in a worktree to ease parse reuse
11+
12+
13+
v1.15.1
14+
=======
15+
16+
* fix issue #126: the local part of any tags is discarded
17+
when guessing new versions
18+
719
v1.15.0
820
=======
921

@@ -18,6 +30,7 @@ v1.15.0
1830
* address issue #93: provide an experimental api to customize behaviour on shallow git repos
1931
a custom parse function may pick pre parse actions to do when using git
2032

33+
2134
v1.14.1
2235
=======
2336

README.rst

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ To use setuptools_scm just modify your project's setup.py file like this:
1818
1. Add :code:`'setuptools_scm'` to the :code:`setup_requires` parameter
1919
2. Add the :code:`use_scm_version` parameter and set it to ``True``
2020

21-
2221
E.g.:
2322

2423
.. code:: python
@@ -31,18 +30,47 @@ To use setuptools_scm just modify your project's setup.py file like this:
3130
...,
3231
)
3332
33+
Arguments to ``get_version()`` (see below) may be passed as a
34+
dictionary to ``use_scm_version``. For example:
35+
36+
.. code:: python
37+
38+
from setuptools import setup
39+
setup(
40+
...,
41+
use_scm_version = {"root": "..", "relative_to": __file__},
42+
setup_requires=['setuptools_scm'],
43+
...,
44+
)
45+
46+
47+
3. Access the version number in your package via :code:`pkg_resources`
48+
49+
E.g. (`PEP-0396 <https://www.python.org/dev/peps/pep-0396>`_):
50+
51+
.. code:: python
52+
53+
from pkg_resources import get_distribution, DistributionNotFound
54+
try:
55+
__version__ = get_distribution(__name__).version
56+
except DistributionNotFound:
57+
# package is not installed
58+
pass
59+
3460
3561
Programmatic usage
3662
------------------
3763

38-
In order to use setuptools_scm from code
39-
that one directory deeper than the project's root, you can use:
64+
In order to use ``setuptools_scm`` from code that one directory deeper
65+
than the project's root, you can use:
4066

4167
.. code:: python
4268
4369
from setuptools_scm import get_version
4470
version = get_version(root='..', relative_to=__file__)
4571
72+
See `setup.py Usage`_ above for how to use this within setup.py.
73+
4674

4775
Usage from sphinx
4876
-----------------
@@ -53,8 +81,8 @@ instead use ``pkg_resources`` after editable/real installation:
5381
.. code:: python
5482
5583
from pkg_resources import get_distribution
56-
release = pkg_resources('myproject').version
57-
# for the example take major/minor
84+
release = get_distribution('myproject').version
85+
# for example take major/minor
5886
version = '.'.join(release.split('.')[:2])
5987
6088
The underlying reason is, that services like readthedocs sometimes change

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def scm_config():
4747
local_scheme=get_local_node_and_date,
4848
)
4949

50+
5051
with open('README.rst') as fp:
5152
long_description = fp.read()
5253

setuptools_scm/git.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ def parse(root, describe_command=DEFAULT_DESCRIBE, pre_parse=warn_on_shallow):
7777
"""
7878
if not has_command('git'):
7979
return
80-
wd = GitWorkdir(root)
80+
81+
wd = GitWorkdir.from_potential_worktree(root)
82+
if wd is None:
83+
return
8184
if pre_parse:
8285
pre_parse(wd)
8386
rev_node = wd.node()

setuptools_scm/hg.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ def parse(root):
2626
if not has_command('hg'):
2727
return
2828
l = do('hg id -i -t', root).split()
29+
if not l:
30+
return
2931
node = l.pop(0)
3032
tags = tags_to_versions(l)
3133
# filter tip in degraded mode on old setuptools

setuptools_scm/version.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,29 @@ def meta(tag, distance=None, dirty=False, node=None, **kw):
8888

8989

9090
def guess_next_version(tag_version, distance):
91-
version = str(tag_version)
92-
if '.dev' in version:
93-
prefix, tail = version.rsplit('.dev', 1)
94-
assert tail == '0', 'own dev numbers are unsupported'
95-
return '%s.dev%s' % (prefix, distance)
96-
else:
97-
prefix, tail = re.match('(.*?)(\d+)$', version).groups()
98-
return '%s%d.dev%s' % (prefix, int(tail) + 1, distance)
91+
version = _strip_local(str(tag_version))
92+
bumped = _bump_dev(version) or _bump_regex(version)
93+
suffix = '.dev%s' % distance
94+
return bumped + suffix
95+
96+
97+
def _strip_local(version_string):
98+
public, sep, local = version_string.partition('+')
99+
return public
100+
101+
102+
def _bump_dev(version):
103+
if '.dev' not in version:
104+
return
105+
106+
prefix, tail = version.rsplit('.dev', 1)
107+
assert tail == '0', 'own dev numbers are unsupported'
108+
return prefix
109+
110+
111+
def _bump_regex(version):
112+
prefix, tail = re.match('(.*?)(\d+)$', version).groups()
113+
return '%s%d' % (prefix, int(tail) + 1)
99114

100115

101116
def guess_next_dev_version(version):

testing/runtests_travis.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44
import os
55

6-
if os.environ['TOXENV']:
6+
if os.environ.get('TOXENV'):
77
import tox
88
tox.cmdline()
9-
elif os.environ['SELFINSTALL']:
9+
elif os.environ.get('SELFINSTALL'):
1010
call('python setup.py sdist', shell=True)
1111
call('easy_install dist/*', shell=True)
12-
import pkg_ressources
13-
dist = pkg_ressources.get_distribution('setuptools_scm')
14-
assert dist.version != '0.0'
12+
import pkg_resources
13+
dist = pkg_resources.get_distribution('setuptools_scm')
14+
assert set(dist.version) != set(".0"), dist.version

testing/test_functions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def __format__(self, *k):
1414
('1.1', '1.2.dev0'),
1515
('1.2.dev', '1.2.dev0'),
1616
('1.1a2', '1.1a3.dev0'),
17+
('23.24.post2+deadbeef', '23.24.post3.dev0'),
1718
])
1819
def test_next_tag(tag, expected):
1920
version = pkg_resources.parse_version(tag)

testing/test_git.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ def test_find_files_stop_at_root_git(wd):
9292
assert integration.find_files(str(wd.cwd/'project')) == []
9393

9494

95+
@pytest.mark.issue(128)
96+
def test_parse_no_worktree(tmpdir):
97+
ret = git.parse(str(tmpdir))
98+
assert ret is None
99+
100+
95101
def test_alphanumeric_tags_match(wd):
96102
wd.commit_testfile()
97103
wd('git tag newstyle-development-started')

0 commit comments

Comments
 (0)