Skip to content

Commit

Permalink
Merge pull request #509 from RonnyPfannschmidt/fix-507-dist-metadata-…
Browse files Browse the repository at this point in the history
…passover

fix #507 - use dist.metadata.name
  • Loading branch information
RonnyPfannschmidt authored Dec 13, 2020
2 parents b7e655c + cf54011 commit 03690ec
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/setuptools_scm/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def tag_regex(self, value):
self._tag_regex = _check_tag_regex(value)

@classmethod
def from_file(cls, name="pyproject.toml"):
def from_file(cls, name="pyproject.toml", dist_name=None):
"""
Read Configuration from pyproject.toml (or similar).
Raises exceptions when file is not found or toml is
Expand All @@ -137,4 +137,4 @@ def from_file(cls, name="pyproject.toml"):
with open(name) as strm:
defn = __import__("toml").load(strm)
section = defn.get("tool", {})["setuptools_scm"]
return cls(**section)
return cls(dist_name=dist_name, **section)
16 changes: 12 additions & 4 deletions src/setuptools_scm/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ def version_keyword(dist, keyword, value):
assert (
"dist_name" not in value
), "dist_name may not be specified in the setup keyword "
trace("dist name", dist, dist.name)
dist_name = dist.name if dist.name != 0 else None

trace(
"version keyword",
vars(dist.metadata),
)
dist_name = dist.metadata.name
config = Configuration(dist_name=dist_name, **value)
dist.metadata.version = _get_version(config)

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


def infer_version(dist):

trace(
"finalize hook",
vars(dist.metadata),
)
dist_name = dist.metadata.name
try:
config = Configuration.from_file()
config = Configuration.from_file(dist_name=dist_name)
except Exception:
return trace_exception()
dist.metadata.version = _get_version(config)
2 changes: 1 addition & 1 deletion testing/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def version(self):
return self.get_version()


@pytest.yield_fixture(autouse=True)
@pytest.fixture(autouse=True)
def debug_mode():
from setuptools_scm import utils

Expand Down
17 changes: 14 additions & 3 deletions testing/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ def test_pyproject_support(tmpdir, monkeypatch):


def test_pyproject_support_with_git(tmpdir, monkeypatch, wd):
monkeypatch.delenv("SETUPTOOLS_SCM_DEBUG")
pytest.importorskip("toml")
pkg = tmpdir.join("wd")
pkg.join("pyproject.toml").write("""[tool.setuptools_scm]""")
pkg.join("setup.py").write("__import__('setuptools').setup()")
pkg.join("setup.py").write(
"__import__('setuptools').setup(name='setuptools_scm_example')"
)
res = do((sys.executable, "setup.py", "--version"), pkg)
assert res == "0.1.dev0"
assert res.endswith("0.1.dev0")


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


def test_pretend_version_named_pyproject_integration(tmpdir, monkeypatch, wd):
test_pyproject_support_with_git(tmpdir, monkeypatch, wd)
monkeypatch.setenv(
PRETEND_KEY_NAMED.format(name="setuptools_scm_example".upper()), "3.2.1"
)
res = do((sys.executable, "setup.py", "--version"), tmpdir / "wd")
assert res.endswith("3.2.1")


def test_pretend_version_named(tmpdir, monkeypatch, wd):
monkeypatch.setenv(PRETEND_KEY_NAMED.format(name="test".upper()), "1.0.0")
monkeypatch.setenv(PRETEND_KEY_NAMED.format(name="test2".upper()), "2.0.0")
Expand Down
3 changes: 3 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ testpaths=testing
filterwarnings=error
markers=
issue(id): reference to github issue
# disable unraisable until investigated
addopts = -p no:unraisableexception

[flake8]
max-complexity = 10
Expand All @@ -28,6 +30,7 @@ skip_install=
deps=
pytest
setuptools >= 42
toml
commands=
test: pytest []
selfcheck: python setup.py --version
Expand Down

0 comments on commit 03690ec

Please sign in to comment.