From 212090fdd7caf7976bc3f1dcd083dac04eb83766 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Sun, 13 Dec 2020 20:20:31 +0100 Subject: [PATCH 1/3] fix #507 - use dist.metadata.name and add pyproject support for dist_name --- src/setuptools_scm/config.py | 4 ++-- src/setuptools_scm/integration.py | 16 ++++++++++++---- testing/test_integration.py | 17 ++++++++++++++--- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/setuptools_scm/config.py b/src/setuptools_scm/config.py index 8b8fb8e1..c451b90f 100644 --- a/src/setuptools_scm/config.py +++ b/src/setuptools_scm/config.py @@ -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 @@ -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(**section, dist_name=dist_name) diff --git a/src/setuptools_scm/integration.py b/src/setuptools_scm/integration.py index ffd4521b..50eb962a 100644 --- a/src/setuptools_scm/integration.py +++ b/src/setuptools_scm/integration.py @@ -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) @@ -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) diff --git a/testing/test_integration.py b/testing/test_integration.py index 446aac0a..1c87108c 100644 --- a/testing/test_integration.py +++ b/testing/test_integration.py @@ -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): @@ -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") From f6e2adf91d2a88049a33d98b066092364412f805 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Sun, 13 Dec 2020 22:33:51 +0100 Subject: [PATCH 2/3] python2 fixups for dist_name passing --- src/setuptools_scm/config.py | 2 +- tox.ini | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/setuptools_scm/config.py b/src/setuptools_scm/config.py index c451b90f..fe1eb984 100644 --- a/src/setuptools_scm/config.py +++ b/src/setuptools_scm/config.py @@ -137,4 +137,4 @@ def from_file(cls, name="pyproject.toml", dist_name=None): with open(name) as strm: defn = __import__("toml").load(strm) section = defn.get("tool", {})["setuptools_scm"] - return cls(**section, dist_name=dist_name) + return cls(dist_name=dist_name, **section) diff --git a/tox.ini b/tox.ini index 030dbd42..9a8c1c23 100644 --- a/tox.ini +++ b/tox.ini @@ -28,6 +28,7 @@ skip_install= deps= pytest setuptools >= 42 + toml commands= test: pytest [] selfcheck: python setup.py --version From cf54011725bb5e6ac9911b06e23ffc5c2938a53f Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Sun, 13 Dec 2020 22:39:37 +0100 Subject: [PATCH 3/3] pytest 6.2.0 support --- testing/conftest.py | 2 +- tox.ini | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/testing/conftest.py b/testing/conftest.py index 5f6cdd50..f533e50d 100644 --- a/testing/conftest.py +++ b/testing/conftest.py @@ -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 diff --git a/tox.ini b/tox.ini index 9a8c1c23..f3a97a94 100644 --- a/tox.ini +++ b/tox.ini @@ -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