Skip to content

Commit 19e3c8d

Browse files
Merge pull request #302 from RonnyPfannschmidt/prepare-3.1.0
Prepare 3.1.0
2 parents 730aaf4 + a91b40c commit 19e3c8d

File tree

10 files changed

+67
-32
lines changed

10 files changed

+67
-32
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ v3.1.0
22
=======
33

44
* fix #297 - correct the invocation in version_from_scm and deprecate it as its exposed by accident
5+
* fix #298 - handle git file listing on empty repositories
6+
* fix #268 - deprecate ScmVersion.extra
57

68
v3.0.6
79
======

src/setuptools_scm/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ def _call_entrypoint_fn(config, fn):
4141
warnings.warn(
4242
"parse functions are required to provide a named argument"
4343
" 'config' in the future.",
44-
PendingDeprecationWarning,
44+
category=PendingDeprecationWarning,
45+
stacklevel=2,
4546
)
4647
return fn(config.absolute_root)
4748

@@ -77,7 +78,7 @@ def _do_parse(config):
7778
if pretended:
7879
# we use meta here since the pretended version
7980
# must adhere to the pep to begin with
80-
return meta(tag=pretended, preformatted=True)
81+
return meta(tag=pretended, preformatted=True, config=config)
8182

8283
if config.parse:
8384
parse_result = _call_entrypoint_fn(config, config.parse)

src/setuptools_scm/git.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,15 @@ def parse(
108108
dirty = wd.is_dirty()
109109

110110
if rev_node is None:
111-
return meta("0.0", distance=0, dirty=dirty)
111+
return meta("0.0", distance=0, dirty=dirty, config=config)
112112

113113
return meta(
114114
"0.0",
115115
distance=wd.count_all_nodes(),
116116
node="g" + rev_node,
117117
dirty=dirty,
118118
branch=wd.get_branch(),
119+
config=config,
119120
)
120121
else:
121122
tag, number, node, dirty = _git_parse_describe(out)

src/setuptools_scm/hacks.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33
from .version import meta
44

55

6-
def parse_pkginfo(root):
6+
def parse_pkginfo(root, config=None):
77

88
pkginfo = os.path.join(root, "PKG-INFO")
99
trace("pkginfo", pkginfo)
1010
data = data_from_mime(pkginfo)
1111
version = data.get("Version")
1212
if version != "UNKNOWN":
13-
return meta(version, preformatted=True)
13+
return meta(version, preformatted=True, config=config)
1414

1515

16-
def parse_pip_egg_info(root):
16+
def parse_pip_egg_info(root, config=None):
1717
pipdir = os.path.join(root, "pip-egg-info")
1818
if not os.path.isdir(pipdir):
1919
return
2020
items = os.listdir(pipdir)
2121
trace("pip-egg-info", pipdir, items)
2222
if not items:
2323
return
24-
return parse_pkginfo(os.path.join(pipdir, items[0]))
24+
return parse_pkginfo(os.path.join(pipdir, items[0]), config=config)

src/setuptools_scm/hg.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from .version import meta, tags_to_versions
55

66

7-
def _hg_tagdist_normalize_tagcommit(root, tag, dist, node, branch):
7+
def _hg_tagdist_normalize_tagcommit(config, tag, dist, node, branch):
88
dirty = node.endswith("+")
99
node = "h" + node.strip("+")
1010

@@ -19,14 +19,19 @@ def _hg_tagdist_normalize_tagcommit(root, tag, dist, node, branch):
1919
tag=tag
2020
)
2121
if tag != "0.0":
22-
commits = do(["hg", "log", "-r", revset, "--template", "{node|short}"], root)
22+
commits = do(
23+
["hg", "log", "-r", revset, "--template", "{node|short}"],
24+
config.absolute_root,
25+
)
2326
else:
2427
commits = True
2528
trace("normalize", locals())
2629
if commits or dirty:
27-
return meta(tag, distance=dist, node=node, dirty=dirty, branch=branch)
30+
return meta(
31+
tag, distance=dist, node=node, dirty=dirty, branch=branch, config=config
32+
)
2833
else:
29-
return meta(tag)
34+
return meta(tag, config=config)
3035

3136

3237
def parse(root, config=None):
@@ -40,12 +45,13 @@ def parse(root, config=None):
4045
return
4146
node = identity_data.pop(0)
4247
branch = identity_data.pop(0)
48+
if "tip" in identity_data:
49+
# tip is not a real tag
50+
identity_data.remove("tip")
4351
tags = tags_to_versions(identity_data)
44-
# filter tip in degraded mode on old setuptools
45-
tags = [x for x in tags if x != "tip"]
4652
dirty = node[-1] == "+"
4753
if tags:
48-
return meta(tags[0], dirty=dirty, branch=branch)
54+
return meta(tags[0], dirty=dirty, branch=branch, config=config)
4955

5056
if node.strip("+") == "0" * 12:
5157
trace("initial node", config.absolute_root)
@@ -57,9 +63,7 @@ def parse(root, config=None):
5763
if tag == "null":
5864
tag = "0.0"
5965
dist = int(dist) + 1
60-
return _hg_tagdist_normalize_tagcommit(
61-
config.absolute_root, tag, dist, node, branch
62-
)
66+
return _hg_tagdist_normalize_tagcommit(config, tag, dist, node, branch)
6367
except ValueError:
6468
pass # unpacking failed, old hg
6569

@@ -80,20 +84,25 @@ def get_graph_distance(root, rev1, rev2="."):
8084
return len(out.strip().splitlines()) - 1
8185

8286

83-
def archival_to_version(data):
87+
def archival_to_version(data, config=None):
8488
trace("data", data)
8589
node = data.get("node", "")[:12]
8690
if node:
8791
node = "h" + node
8892
if "tag" in data:
89-
return meta(data["tag"])
93+
return meta(data["tag"], config=config)
9094
elif "latesttag" in data:
91-
return meta(data["latesttag"], distance=data["latesttagdistance"], node=node)
95+
return meta(
96+
data["latesttag"],
97+
distance=data["latesttagdistance"],
98+
node=node,
99+
config=config,
100+
)
92101
else:
93-
return meta("0.0", node=node)
102+
return meta("0.0", node=node, config=config)
94103

95104

96-
def parse_archival(root):
105+
def parse_archival(root, config=None):
97106
archival = os.path.join(root, ".hg_archival.txt")
98107
data = data_from_mime(archival)
99-
return archival_to_version(data)
108+
return archival_to_version(data, config=config)

src/setuptools_scm/version.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,18 +141,27 @@ def __init__(
141141
self.distance = distance
142142
self.node = node
143143
self.time = datetime.datetime.now()
144-
self.extra = kw
144+
self._extra = kw
145145
self.dirty = dirty
146146
self.preformatted = preformatted
147147
self.branch = branch
148148

149+
@property
150+
def extra(self):
151+
warnings.warn(
152+
"ScmVersion.extra is deprecated and will be removed in future",
153+
category=DeprecationWarning,
154+
stacklevel=2,
155+
)
156+
return self._extra
157+
149158
@property
150159
def exact(self):
151160
return self.distance is None
152161

153162
def __repr__(self):
154163
return self.format_with(
155-
"<ScmVersion {tag} d={distance}" " n={node} d={dirty} b={branch} x={extra}>"
164+
"<ScmVersion {tag} d={distance} n={node} d={dirty} b={branch}>"
156165
)
157166

158167
def format_with(self, fmt, **kw):
@@ -162,7 +171,6 @@ def format_with(self, fmt, **kw):
162171
distance=self.distance,
163172
node=self.node,
164173
dirty=self.dirty,
165-
extra=self.extra,
166174
branch=self.branch,
167175
**kw
168176
)

testing/test_git.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ def test_version_from_git(wd):
6363

6464
wd.commit_testfile()
6565
wd("git tag version-0.2.post210+gbe48adfpost3+g0cc25f2")
66-
assert wd.version.startswith("0.2")
66+
with pytest.warns(
67+
UserWarning, match="tag '.*' will be stripped of its suffix '.*'"
68+
):
69+
assert wd.version.startswith("0.2")
6770

6871
wd.commit_testfile()
6972
wd("git tag 17.33.0-rc")

testing/test_mercurial.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from setuptools_scm import format_version
22
from setuptools_scm.hg import archival_to_version, parse
33
from setuptools_scm import integration
4-
4+
from setuptools_scm.config import Configuration
55
import pytest
66

77

@@ -26,7 +26,8 @@ def wd(wd):
2626

2727
@pytest.mark.parametrize("expected,data", sorted(archival_mapping.items()))
2828
def test_archival_to_version(expected, data):
29-
version = archival_to_version(data)
29+
config = Configuration()
30+
version = archival_to_version(data, config=config)
3031
assert (
3132
format_version(
3233
version, version_scheme="guess-next-dev", local_scheme="node-and-date"

testing/test_version.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,20 @@ def test_next_semver(version, expected_next):
4949
],
5050
)
5151
def test_tag_regex1(tag, expected):
52-
Configuration().tag_regex = r"^(?P<prefix>v)?(?P<version>[^\+]+)(?P<suffix>.*)?$"
53-
result = meta(tag)
52+
config = Configuration()
53+
config.tag_regex = r"^(?P<prefix>v)?(?P<version>[^\+]+)(?P<suffix>.*)?$"
54+
if "+" in tag:
55+
# pytest bug wrt cardinality
56+
with pytest.warns(UserWarning):
57+
result = meta(tag, config=config)
58+
else:
59+
result = meta(tag, config=config)
60+
5461
assert result.tag.public == expected
5562

5663

5764
@pytest.mark.issue("https://github.com/pypa/setuptools_scm/issues/286")
5865
def test_tags_to_versions():
5966
config = Configuration()
60-
versions = tags_to_versions(["1", "2", "3"], config=config)
67+
versions = tags_to_versions(["1.0", "2.0", "3.0"], config=config)
6168
assert isinstance(versions, list) # enable subscription

tox.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
[tox]
22
envlist=py{27,34,35,36,37}-test,flake8,check_readme,py{27,36}-selfcheck
33

4+
[pytest]
5+
filterwarnings=error
6+
47
[flake8]
58
max-complexity = 10
69
max-line-length = 88

0 commit comments

Comments
 (0)