diff options
author | Ronny Pfannschmidt <opensource@ronnypfannschmidt.de> | 2020-12-13 23:01:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-13 23:01:38 +0100 |
commit | 03690ec63a31a7b17403eae00b639ace8b2f13e2 (patch) | |
tree | bb70df7de7654bb3bf67cd066544cc43ee2aed9a | |
parent | b7e655c1259a0d6bce0d94be41a4ae21a2721102 (diff) | |
parent | cf54011725bb5e6ac9911b06e23ffc5c2938a53f (diff) | |
download | setuptools-scm-5.0.1.tar.gz |
Merge pull request #509 from RonnyPfannschmidt/fix-507-dist-metadata-passoverv5.0.1
fix #507 - use dist.metadata.name
-rw-r--r-- | src/setuptools_scm/config.py | 4 | ||||
-rw-r--r-- | src/setuptools_scm/integration.py | 16 | ||||
-rw-r--r-- | testing/conftest.py | 2 | ||||
-rw-r--r-- | testing/test_integration.py | 17 | ||||
-rw-r--r-- | tox.ini | 3 |
5 files changed, 32 insertions, 10 deletions
diff --git a/src/setuptools_scm/config.py b/src/setuptools_scm/config.py index 8b8fb8e..fe1eb98 100644 --- a/src/setuptools_scm/config.py +++ b/src/setuptools_scm/config.py @@ -127,7 +127,7 @@ class Configuration(object): 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 @@ class Configuration(object): 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) diff --git a/src/setuptools_scm/integration.py b/src/setuptools_scm/integration.py index ffd4521..50eb962 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/conftest.py b/testing/conftest.py index 5f6cdd5..f533e50 100644 --- a/testing/conftest.py +++ b/testing/conftest.py @@ -81,7 +81,7 @@ class Wd(object): return self.get_version() -@pytest.yield_fixture(autouse=True) +@pytest.fixture(autouse=True) def debug_mode(): from setuptools_scm import utils diff --git a/testing/test_integration.py b/testing/test_integration.py index 446aac0..1c87108 100644 --- a/testing/test_integration.py +++ b/testing/test_integration.py @@ -31,12 +31,14 @@ fallback_version = "12.34" 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") @@ -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 @@ -28,6 +30,7 @@ skip_install= deps= pytest setuptools >= 42 + toml commands= test: pytest [] selfcheck: python setup.py --version |