diff options
-rw-r--r-- | MANIFEST.in | 3 | ||||
-rw-r--r-- | setup.cfg | 2 | ||||
-rw-r--r-- | src/setuptools_scm/__init__.py | 2 | ||||
-rw-r--r-- | src/setuptools_scm/git.py | 27 | ||||
-rw-r--r-- | src/setuptools_scm/integration.py | 12 | ||||
-rw-r--r-- | src/setuptools_scm/version.py | 14 | ||||
-rw-r--r-- | testing/test_git.py | 24 | ||||
-rw-r--r-- | testing/test_regressions.py | 3 | ||||
-rw-r--r-- | testing/test_version.py | 7 | ||||
-rw-r--r-- | tox.ini | 17 |
10 files changed, 47 insertions, 64 deletions
diff --git a/MANIFEST.in b/MANIFEST.in index c758a17..54e9473 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -8,5 +8,6 @@ include *.rst include LICENSE include *.toml include mypy.ini -include testing/Dockerfile.busted-buster +include testing/Dockerfile.* +include src/setuptools_scm/.git_archival.txt recursive-include testing *.bash @@ -7,7 +7,7 @@ url = https://github.com/pypa/setuptools_scm/ author = Ronny Pfannschmidt author_email = opensource@ronnypfannschmidt.de license = MIT -license_file = LICENSE +license_files = LICENSE classifiers = Development Status :: 5 - Production/Stable Intended Audience :: Developers diff --git a/src/setuptools_scm/__init__.py b/src/setuptools_scm/__init__.py index 764b51e..91f88ed 100644 --- a/src/setuptools_scm/__init__.py +++ b/src/setuptools_scm/__init__.py @@ -50,7 +50,9 @@ def dump_version( target = os.path.normpath(os.path.join(root, write_to)) ext = os.path.splitext(target)[1] template = template or TEMPLATES.get(ext) + from .utils import trace + trace("dump", write_to, version) if template is None: raise ValueError( "bad file format: '{}' (of {}) \nonly *.txt and *.py are supported".format( diff --git a/src/setuptools_scm/git.py b/src/setuptools_scm/git.py index ccd8ce7..3a3a1b9 100644 --- a/src/setuptools_scm/git.py +++ b/src/setuptools_scm/git.py @@ -21,7 +21,7 @@ from .utils import require_command from .utils import trace from .version import meta from .version import ScmVersion -from .version import tags_to_versions +from .version import tag_to_version if TYPE_CHECKING: from . import hg_git @@ -150,33 +150,30 @@ def fail_on_shallow(wd: GitWorkdir) -> None: ) -def get_working_directory(config: Configuration) -> GitWorkdir | None: +def get_working_directory(config: Configuration, root: str) -> GitWorkdir | None: """ Return the working directory (``GitWorkdir``). """ - if config.parent: + if config.parent: # todo broken return GitWorkdir.from_potential_worktree(config.parent) if config.search_parent_directories: - return search_parent(config.absolute_root) + return search_parent(root) - return GitWorkdir.from_potential_worktree(config.absolute_root) + return GitWorkdir.from_potential_worktree(root) def parse( root: str, + config: Configuration, describe_command: str | list[str] | None = None, pre_parse: Callable[[GitWorkdir], None] = warn_on_shallow, - config: Configuration | None = None, ) -> ScmVersion | None: """ :param pre_parse: experimental pre_parse action, may change at any time """ - if not config: - config = Configuration(root=root) - - wd = get_working_directory(config) + wd = get_working_directory(config, root) if wd: return _git_parse_inner( config, wd, describe_command=describe_command, pre_parse=pre_parse @@ -301,11 +298,11 @@ def archival_to_version( distance=None if number == 0 else number, node=node, ) - versions = tags_to_versions( - REF_TAG_RE.findall(data.get("ref-names", "")), config=config - ) - if versions: - return meta(versions[0], config=config) + + for ref in REF_TAG_RE.findall(data.get("ref-names", "")): + version = tag_to_version(ref, config) + if version is not None: + return meta(version, config=config) else: node = data.get("node") if node is None: diff --git a/src/setuptools_scm/integration.py b/src/setuptools_scm/integration.py index a5d2c02..e9c6c12 100644 --- a/src/setuptools_scm/integration.py +++ b/src/setuptools_scm/integration.py @@ -63,6 +63,7 @@ def _assign_version(dist: setuptools.Distribution, config: Configuration) -> Non if maybe_version is None: _version_missing(config) else: + assert dist.metadata.version is None dist.metadata.version = maybe_version @@ -80,12 +81,16 @@ def version_keyword( assert ( "dist_name" not in value ), "dist_name may not be specified in the setup keyword " - + dist_name: str | None = dist.metadata.name + if dist.metadata.version is not None: + warnings.warn(f"version of {dist_name} already set") + return trace( "version keyword", vars(dist.metadata), ) - dist_name = dist.metadata.name # type: str | None + trace("dist", id(dist), id(dist.metadata)) + if dist_name is None: dist_name = _read_dist_name_from_setup_cfg() version_cls = value.pop("version_cls", None) @@ -116,6 +121,9 @@ def infer_version(dist: setuptools.Distribution) -> None: "finalize hook", vars(dist.metadata), ) + trace("dist", id(dist), id(dist.metadata)) + if dist.metadata.version is not None: + return # metadata already added by hook dist_name = dist.metadata.name if dist_name is None: dist_name = _read_dist_name_from_setup_cfg() diff --git a/src/setuptools_scm/version.py b/src/setuptools_scm/version.py index 11ed5aa..5da3f82 100644 --- a/src/setuptools_scm/version.py +++ b/src/setuptools_scm/version.py @@ -100,20 +100,6 @@ def tag_to_version( return version -def tags_to_versions(tags: list[str], config: _config.Configuration) -> list[_VersionT]: - """ - take tags that might be prefixed with a keyword and return only the version part - :param tags: an iterable of tags - :param config: optional configuration object - """ - result: list[_VersionT] = [] - for tag in tags: - parsed = tag_to_version(tag, config=config) - if parsed: - result.append(parsed) - return result - - def _source_epoch_or_utc_now() -> datetime: if "SOURCE_DATE_EPOCH" in os.environ: date_epoch = int(os.environ["SOURCE_DATE_EPOCH"]) diff --git a/testing/test_git.py b/testing/test_git.py index 2dc8b0d..ab2cfed 100644 --- a/testing/test_git.py +++ b/testing/test_git.py @@ -91,7 +91,7 @@ setup(use_scm_version={"search_parent_directories": True}) def test_git_gone(wd: WorkDir, monkeypatch: pytest.MonkeyPatch) -> None: monkeypatch.setenv("PATH", str(wd.cwd / "not-existing")) with pytest.raises(EnvironmentError, match="'git' was not found"): - git.parse(str(wd.cwd), git.DEFAULT_DESCRIBE) + git.parse(str(wd.cwd), Configuration(), git.DEFAULT_DESCRIBE) @pytest.mark.issue("https://github.com/pypa/setuptools_scm/issues/298") @@ -105,7 +105,7 @@ def test_file_finder_no_history(wd: WorkDir, caplog: pytest.LogCaptureFixture) - @pytest.mark.issue("https://github.com/pypa/setuptools_scm/issues/281") def test_parse_call_order(wd: WorkDir) -> None: - git.parse(str(wd.cwd), git.DEFAULT_DESCRIBE) + git.parse(str(wd.cwd), Configuration(), git.DEFAULT_DESCRIBE) @pytest.mark.issue("https://github.com/pypa/setuptools_scm/issues/707") @@ -130,7 +130,7 @@ def test_not_owner(wd: WorkDir) -> None: stdin=subprocess.DEVNULL, check=True, ) - assert git.parse(str(wd.cwd)) + assert git.parse(str(wd.cwd), Configuration()) finally: # Restore the ownership subprocess.run( @@ -148,7 +148,7 @@ def test_not_owner(wd: WorkDir) -> None: def test_version_from_git(wd: WorkDir) -> None: assert wd.version == "0.1.dev0" - parsed = git.parse(str(wd.cwd), git.DEFAULT_DESCRIBE) + parsed = git.parse(str(wd.cwd), Configuration(), git.DEFAULT_DESCRIBE) assert parsed is not None and parsed.branch in ("master", "main") wd.commit_testfile() @@ -226,8 +226,8 @@ def test_git_version_unnormalized_setuptools( the version is not normalized in write_to files, but still normalized by setuptools for the final dist metadata. """ - monkeypatch.delenv("SETUPTOOLS_SCM_DEBUG") - + # monkeypatch.delenv("SETUPTOOLS_SCM_DEBUG") + monkeypatch.chdir(wd.cwd) wd.write("setup.py", dedent(setup_py_txt)) # do git operations and tag @@ -303,23 +303,23 @@ def shallow_wd(wd: WorkDir, tmp_path: Path) -> Path: def test_git_parse_shallow_warns( shallow_wd: Path, recwarn: pytest.WarningsRecorder ) -> None: - git.parse(str(shallow_wd)) + git.parse(str(shallow_wd), Configuration()) msg = recwarn.pop() assert "is shallow and may cause errors" in str(msg.message) def test_git_parse_shallow_fail(shallow_wd: Path) -> None: with pytest.raises(ValueError, match="git fetch"): - git.parse(str(shallow_wd), pre_parse=git.fail_on_shallow) + git.parse(str(shallow_wd), Configuration(), pre_parse=git.fail_on_shallow) def test_git_shallow_autocorrect( shallow_wd: Path, recwarn: pytest.WarningsRecorder ) -> None: - git.parse(str(shallow_wd), pre_parse=git.fetch_on_shallow) + git.parse(str(shallow_wd), Configuration(), pre_parse=git.fetch_on_shallow) msg = recwarn.pop() assert "git fetch was used to rectify" in str(msg.message) - git.parse(str(shallow_wd), pre_parse=git.fail_on_shallow) + git.parse(str(shallow_wd), Configuration(), pre_parse=git.fail_on_shallow) def test_find_files_stop_at_root_git(wd: WorkDir) -> None: @@ -332,7 +332,7 @@ def test_find_files_stop_at_root_git(wd: WorkDir) -> None: @pytest.mark.issue(128) def test_parse_no_worktree(tmp_path: Path) -> None: - ret = git.parse(str(tmp_path)) + ret = git.parse(str(tmp_path), Configuration(root=str(tmp_path))) assert ret is None @@ -452,7 +452,7 @@ def test_git_getdate(wd: WorkDir) -> None: today = date.today() def parse_date() -> date: - parsed = git.parse(os.fspath(wd.cwd)) + parsed = git.parse(os.fspath(wd.cwd), Configuration()) assert parsed is not None assert parsed.node_date is not None return parsed.node_date diff --git a/testing/test_regressions.py b/testing/test_regressions.py index 6de7141..bc378f5 100644 --- a/testing/test_regressions.py +++ b/testing/test_regressions.py @@ -7,6 +7,7 @@ from pathlib import Path import pytest +from setuptools_scm import Configuration from setuptools_scm import get_version from setuptools_scm.git import parse from setuptools_scm.utils import do @@ -100,5 +101,5 @@ def test_case_mismatch_on_windows_git(tmp_path: Path) -> None: camel_case_path = tmp_path / "CapitalizedDir" camel_case_path.mkdir() do("git init", camel_case_path) - res = parse(str(camel_case_path).lower()) + res = parse(str(camel_case_path).lower(), Configuration()) assert res is not None diff --git a/testing/test_version.py b/testing/test_version.py index d7fefe4..29d58c9 100644 --- a/testing/test_version.py +++ b/testing/test_version.py @@ -15,7 +15,6 @@ from setuptools_scm.version import no_guess_dev_version from setuptools_scm.version import release_branch_semver_version from setuptools_scm.version import ScmVersion from setuptools_scm.version import simplified_semver_version -from setuptools_scm.version import tags_to_versions c = Configuration() @@ -187,12 +186,6 @@ def test_tag_regex1(tag: str, expected: str) -> None: assert result.tag.public == expected -@pytest.mark.issue("https://github.com/pypa/setuptools_scm/issues/286") -def test_tags_to_versions() -> None: - versions = tags_to_versions(["1.0", "2.0", "3.0"], config=c) - assert isinstance(versions, list) # enable subscription - - @pytest.mark.issue("https://github.com/pypa/setuptools_scm/issues/471") def test_version_bump_bad() -> None: class YikesVersion: @@ -1,5 +1,5 @@ [tox] -envlist=py{37,38,39,310,311}-{test,selfcheck},check_readme,check-dist,check-bootstrap +envlist=py{37,38,39,310,311}-{test,selfcheck},check_readme,check-dist [pytest] testpaths=testing @@ -37,16 +37,18 @@ commands= [testenv:check_readme] skip_install=True -setenv = SETUPTOOLS_SCM_PRETEND_VERSION=2.0 deps= check-manifest docutils pygments + setuptools>45 + typing_extensions commands= rst2html.py README.rst {envlogdir}/README.html --strict [] - check-manifest + check-manifest --no-build-isolation [testenv:check_dist] +skip_install = true deps= build twine @@ -54,14 +56,7 @@ commands= python -m build twine check dist/* -[testenv:check-bootstrap] -deps = - setuptools > 45 - packaging>20 -skip_install = true -recreate = true -commands = - python setup.py bdist_wheel + #XXX: envs for hg versions |