Skip to content

Commit 03690ec

Browse files
Merge pull request #509 from RonnyPfannschmidt/fix-507-dist-metadata-passover
fix #507 - use dist.metadata.name
2 parents b7e655c + cf54011 commit 03690ec

File tree

5 files changed

+32
-10
lines changed

5 files changed

+32
-10
lines changed

src/setuptools_scm/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def tag_regex(self, value):
127127
self._tag_regex = _check_tag_regex(value)
128128

129129
@classmethod
130-
def from_file(cls, name="pyproject.toml"):
130+
def from_file(cls, name="pyproject.toml", dist_name=None):
131131
"""
132132
Read Configuration from pyproject.toml (or similar).
133133
Raises exceptions when file is not found or toml is
@@ -137,4 +137,4 @@ def from_file(cls, name="pyproject.toml"):
137137
with open(name) as strm:
138138
defn = __import__("toml").load(strm)
139139
section = defn.get("tool", {})["setuptools_scm"]
140-
return cls(**section)
140+
return cls(dist_name=dist_name, **section)

src/setuptools_scm/integration.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ def version_keyword(dist, keyword, value):
1616
assert (
1717
"dist_name" not in value
1818
), "dist_name may not be specified in the setup keyword "
19-
trace("dist name", dist, dist.name)
20-
dist_name = dist.name if dist.name != 0 else None
19+
20+
trace(
21+
"version keyword",
22+
vars(dist.metadata),
23+
)
24+
dist_name = dist.metadata.name
2125
config = Configuration(dist_name=dist_name, **value)
2226
dist.metadata.version = _get_version(config)
2327

@@ -45,9 +49,13 @@ def _args_from_toml(name="pyproject.toml"):
4549

4650

4751
def infer_version(dist):
48-
52+
trace(
53+
"finalize hook",
54+
vars(dist.metadata),
55+
)
56+
dist_name = dist.metadata.name
4957
try:
50-
config = Configuration.from_file()
58+
config = Configuration.from_file(dist_name=dist_name)
5159
except Exception:
5260
return trace_exception()
5361
dist.metadata.version = _get_version(config)

testing/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def version(self):
8181
return self.get_version()
8282

8383

84-
@pytest.yield_fixture(autouse=True)
84+
@pytest.fixture(autouse=True)
8585
def debug_mode():
8686
from setuptools_scm import utils
8787

testing/test_integration.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ def test_pyproject_support(tmpdir, monkeypatch):
3131

3232

3333
def test_pyproject_support_with_git(tmpdir, monkeypatch, wd):
34-
monkeypatch.delenv("SETUPTOOLS_SCM_DEBUG")
34+
pytest.importorskip("toml")
3535
pkg = tmpdir.join("wd")
3636
pkg.join("pyproject.toml").write("""[tool.setuptools_scm]""")
37-
pkg.join("setup.py").write("__import__('setuptools').setup()")
37+
pkg.join("setup.py").write(
38+
"__import__('setuptools').setup(name='setuptools_scm_example')"
39+
)
3840
res = do((sys.executable, "setup.py", "--version"), pkg)
39-
assert res == "0.1.dev0"
41+
assert res.endswith("0.1.dev0")
4042

4143

4244
def test_pretend_version(tmpdir, monkeypatch, wd):
@@ -46,6 +48,15 @@ def test_pretend_version(tmpdir, monkeypatch, wd):
4648
assert wd.get_version(dist_name="ignored") == "1.0.0"
4749

4850

51+
def test_pretend_version_named_pyproject_integration(tmpdir, monkeypatch, wd):
52+
test_pyproject_support_with_git(tmpdir, monkeypatch, wd)
53+
monkeypatch.setenv(
54+
PRETEND_KEY_NAMED.format(name="setuptools_scm_example".upper()), "3.2.1"
55+
)
56+
res = do((sys.executable, "setup.py", "--version"), tmpdir / "wd")
57+
assert res.endswith("3.2.1")
58+
59+
4960
def test_pretend_version_named(tmpdir, monkeypatch, wd):
5061
monkeypatch.setenv(PRETEND_KEY_NAMED.format(name="test".upper()), "1.0.0")
5162
monkeypatch.setenv(PRETEND_KEY_NAMED.format(name="test2".upper()), "2.0.0")

tox.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ testpaths=testing
66
filterwarnings=error
77
markers=
88
issue(id): reference to github issue
9+
# disable unraisable until investigated
10+
addopts = -p no:unraisableexception
911

1012
[flake8]
1113
max-complexity = 10
@@ -28,6 +30,7 @@ skip_install=
2830
deps=
2931
pytest
3032
setuptools >= 42
33+
toml
3134
commands=
3235
test: pytest []
3336
selfcheck: python setup.py --version

0 commit comments

Comments
 (0)