Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor/breaking: move file finders to private module #815

Merged
merged 2 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ breaking
* remove legacy version parser api - config arg always required
* turn Configuration into a dataclass
* require configuration to always pass into helpers
* hide file-finders implementation in private module
* define own build backend to have setuptools work

features
--------

* created a directory for the vcs-versioning package and added it to pypi
* git: expect main as possible default branch
* drop version_from_scm helper
* trim down exposed public api
* no longer self-call twice in setuptools
* add support for version schemes by import
* chores

* migrate own metadata to pyproject.toml
Expand Down
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@ repository = "https://github.com/pypa/setuptools_scm/"
use_scm_version = "setuptools_scm.integration:version_keyword"

[project.entry-points."setuptools.file_finders"]
setuptools_scm = "setuptools_scm.integration:find_files"
setuptools_scm = "setuptools_scm._file_finders:find_files"

[project.entry-points."setuptools.finalize_distribution_options"]
setuptools_scm = "setuptools_scm.integration:infer_version"

[project.entry-points."setuptools_scm.files_command"]
".git" = "setuptools_scm.file_finder_git:git_find_files"
".hg" = "setuptools_scm.file_finder_hg:hg_find_files"
".git" = "setuptools_scm._file_finders.git:git_find_files"
".hg" = "setuptools_scm._file_finders.hg:hg_find_files"

[project.entry-points."setuptools_scm.files_command_fallback"]
".git_archival.txt" = "setuptools_scm.file_finder_git:git_archive_find_files"
".hg_archival.txt" = "setuptools_scm.file_finder_hg:hg_archive_find_files"
".git_archival.txt" = "setuptools_scm._file_finders.git:git_archive_find_files"
".hg_archival.txt" = "setuptools_scm._file_finders.hg:hg_archive_find_files"

[project.entry-points."setuptools_scm.local_scheme"]
dirty-tag = "setuptools_scm.version:get_local_dirty_tag"
Expand Down
2 changes: 1 addition & 1 deletion src/setuptools_scm/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

from setuptools_scm import _get_version
from setuptools_scm import Configuration
from setuptools_scm._file_finders import find_files
from setuptools_scm.discover import walk_potential_roots
from setuptools_scm.integration import find_files


def main(args: list[str] | None = None) -> None:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from __future__ import annotations

import itertools
import os
from typing import Callable

from typing_extensions import TypeGuard

from . import _types as _t
from ._trace import trace
from setuptools_scm import _types as _t
from setuptools_scm._entrypoints import iter_entry_points
from setuptools_scm._trace import trace


def scm_find_files(
Expand Down Expand Up @@ -84,3 +87,15 @@ def is_toplevel_acceptable(toplevel: str | None) -> TypeGuard[str]:
trace(toplevel, ignored)

return toplevel not in ignored


def find_files(path: _t.PathT = "") -> list[str]:
for ep in itertools.chain(
iter_entry_points("setuptools_scm.files_command"),
iter_entry_points("setuptools_scm.files_command_fallback"),
):
command: Callable[[_t.PathT], list[str]] = ep.load()
res: list[str] = command(path)
if res:
return res
return []
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import tarfile
from typing import IO

from . import _types as _t
from ._run_cmd import run as _run
from ._trace import trace
from .file_finder import is_toplevel_acceptable
from .file_finder import scm_find_files
from .utils import data_from_mime
from . import is_toplevel_acceptable
from . import scm_find_files
from .. import _types as _t
from .._run_cmd import run as _run
from .._trace import trace
from ..utils import data_from_mime

log = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
import os
import subprocess

from . import _types as _t
from ._run_cmd import run as _run
from ._trace import trace
from .file_finder import is_toplevel_acceptable
from .file_finder import scm_find_files
from .utils import data_from_mime
from .utils import do_ex
from .. import _types as _t
from .._file_finders import is_toplevel_acceptable
from .._file_finders import scm_find_files
from .._run_cmd import run as _run
from .._trace import trace
from ..utils import data_from_mime


def _hg_toplevel(path: str) -> str | None:
Expand All @@ -31,10 +30,10 @@ def _hg_toplevel(path: str) -> str | None:
def _hg_ls_files_and_dirs(toplevel: str) -> tuple[set[str], set[str]]:
hg_files: set[str] = set()
hg_dirs = {toplevel}
out, err, ret = do_ex(["hg", "files"], cwd=toplevel)
if ret:
res = _run(["hg", "files"], cwd=toplevel)
if res.returncode:
(), ()
for name in out.splitlines():
for name in res.stdout.splitlines():
name = os.path.normcase(name).replace("/", os.path.sep)
fullname = os.path.join(toplevel, name)
hg_files.add(fullname)
Expand Down
16 changes: 1 addition & 15 deletions src/setuptools_scm/integration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import itertools
import os
import warnings
from typing import Any
Expand All @@ -12,15 +11,14 @@
from . import _get_version
from . import _version_missing
from . import Configuration
from ._entrypoints import iter_entry_points
from ._integration.setuptools import (
read_dist_name_from_setup_cfg as _read_dist_name_from_setup_cfg,
)
from ._trace import trace
from ._version_cls import _validate_version_cls

if TYPE_CHECKING:
from . import _types as _t
pass


def _warn_on_old_setuptools(_version: str = setuptools.__version__) -> None:
Expand Down Expand Up @@ -99,18 +97,6 @@ def version_keyword(
_assign_version(dist, config)


def find_files(path: _t.PathT = "") -> list[str]:
for ep in itertools.chain(
iter_entry_points("setuptools_scm.files_command"),
iter_entry_points("setuptools_scm.files_command_fallback"),
):
command = ep.load()
res: list[str] = command(path)
if res:
return res
return []


def infer_version(dist: setuptools.Distribution) -> None:
trace(
"finalize hook",
Expand Down
2 changes: 1 addition & 1 deletion testing/test_file_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pytest

from .wd_wrapper import WorkDir
from setuptools_scm.integration import find_files
from setuptools_scm._file_finders import find_files


@pytest.fixture(params=["git", "hg"])
Expand Down
14 changes: 8 additions & 6 deletions testing/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@

import pytest

import setuptools_scm._file_finders
from .conftest import DebugMode
from .wd_wrapper import WorkDir
from setuptools_scm import Configuration
from setuptools_scm import git
from setuptools_scm import integration
from setuptools_scm import NonNormalizedVersion
from setuptools_scm._file_finders.git import git_find_files
from setuptools_scm._run_cmd import run
from setuptools_scm.file_finder_git import git_find_files
from setuptools_scm.git import archival_to_version
from setuptools_scm.utils import has_command
from setuptools_scm.version import format_version
Expand Down Expand Up @@ -327,7 +327,7 @@ def test_find_files_stop_at_root_git(wd: WorkDir) -> None:
project = wd.cwd / "project"
project.mkdir()
project.joinpath("setup.cfg").touch()
assert integration.find_files(str(project)) == []
assert setuptools_scm._file_finders.find_files(str(project)) == []


@pytest.mark.issue(128)
Expand Down Expand Up @@ -356,7 +356,7 @@ def test_git_archive_export_ignore(
wd("git add test1.txt test2.txt")
wd.commit()
monkeypatch.chdir(wd.cwd)
assert integration.find_files(".") == [opj(".", "test1.txt")]
assert setuptools_scm._file_finders.find_files(".") == [opj(".", "test1.txt")]


@pytest.mark.issue(228)
Expand All @@ -366,7 +366,9 @@ def test_git_archive_subdirectory(wd: WorkDir, monkeypatch: pytest.MonkeyPatch)
wd("git add foobar")
wd.commit()
monkeypatch.chdir(wd.cwd)
assert integration.find_files(".") == [opj(".", "foobar", "test1.txt")]
assert setuptools_scm._file_finders.find_files(".") == [
opj(".", "foobar", "test1.txt")
]


@pytest.mark.issue(251)
Expand All @@ -378,7 +380,7 @@ def test_git_archive_run_from_subdirectory(
wd("git add foobar")
wd.commit()
monkeypatch.chdir(wd.cwd / "foobar")
assert integration.find_files(".") == [opj(".", "test1.txt")]
assert setuptools_scm._file_finders.find_files(".") == [opj(".", "test1.txt")]


@pytest.mark.issue("https://github.com/pypa/setuptools_scm/issues/728")
Expand Down
6 changes: 3 additions & 3 deletions testing/test_mercurial.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import pytest

import setuptools_scm._file_finders
from setuptools_scm import Configuration
from setuptools_scm import integration
from setuptools_scm.hg import archival_to_version
from setuptools_scm.hg import parse
from setuptools_scm.utils import has_command
Expand Down Expand Up @@ -67,11 +67,11 @@ def test_find_files_stop_at_root_hg(
project.mkdir()
project.joinpath("setup.cfg").touch()
# setup.cfg has not been committed
assert integration.find_files(str(project)) == []
assert setuptools_scm._file_finders.find_files(str(project)) == []
# issue 251
wd.add_and_commit()
monkeypatch.chdir(project)
assert integration.find_files() == ["setup.cfg"]
assert setuptools_scm._file_finders.find_files() == ["setup.cfg"]


# XXX: better tests for tag prefixes
Expand Down