Skip to content

Commit

Permalink
Merge pull request #724 from RonnyPfannschmidt/fix-722-self-bootstrap
Browse files Browse the repository at this point in the history
minimize bootstrap - fixes #722 and #722
  • Loading branch information
RonnyPfannschmidt authored Jun 22, 2022
2 parents f807bfe + 64058ad commit f1f35bd
Show file tree
Hide file tree
Showing 18 changed files with 89 additions and 35 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
v7.0.2
======

* fix #723 and #722: remove bootstrap dependencies
* bugfix: ensure we read the distribution name from setup.cfg
if needed even for pyproject
*

v7.0.1
=======

Expand Down
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[build-system]
requires = [
"setuptools>=45",
"tomli>=1.0",
"packaging>=20.0",
"typing_extensions",
"importlib_metadata",
]
build-backend = "setuptools.build_meta"
2 changes: 1 addition & 1 deletion src/setuptools_scm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from typing import Callable
from typing import TYPE_CHECKING

from . import _types as _t
from ._entrypoints import _call_entrypoint_fn
from ._entrypoints import _version_from_entrypoints
from ._overrides import _read_pretended_version_for
Expand All @@ -33,6 +32,7 @@
if TYPE_CHECKING:
from typing import NoReturn

from . import _types as _t

TEMPLATES = {
".py": """\
Expand Down
20 changes: 16 additions & 4 deletions src/setuptools_scm/_entrypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@
from typing import overload
from typing import TYPE_CHECKING

from typing_extensions import Protocol

from . import _types as _t
from .utils import function_has_arg
from .utils import trace
from .version import ScmVersion

if TYPE_CHECKING:
from .config import Configuration
from typing_extensions import Protocol
from . import _types as _t
else:
Configuration = Any

class Protocol:
pass


class MaybeConfigFunction(Protocol):
__name__: str
Expand Down Expand Up @@ -71,7 +73,17 @@ def _version_from_entrypoints(
try:
from importlib.metadata import entry_points # type: ignore
except ImportError:
from importlib_metadata import entry_points
try:
from importlib_metadata import entry_points
except ImportError:
from collections import defaultdict

def entry_points() -> dict[str, list[_t.EntrypointProtocol]]:
warnings.warn(
"importlib metadata missing, "
"this may happen at build time for python3.7"
)
return defaultdict(list)


def iter_entry_points(
Expand Down
7 changes: 0 additions & 7 deletions src/setuptools_scm/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from typing import Any
from typing import Callable
from typing import List
from typing import NamedTuple
from typing import TYPE_CHECKING
from typing import TypeVar
from typing import Union
Expand All @@ -22,12 +21,6 @@
VERSION_SCHEME = Union[str, Callable[["version.ScmVersion"], str]]


class CmdResult(NamedTuple):
out: str
err: str
returncode: int


class EntrypointProtocol(Protocol):
name: str

Expand Down
2 changes: 1 addition & 1 deletion src/setuptools_scm/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
from typing import TYPE_CHECKING
from typing import Union

from . import _types as _t
from ._version_cls import NonNormalizedVersion
from ._version_cls import Version
from .utils import trace


if TYPE_CHECKING:
from . import _types as _t
from setuptools_scm.version import ScmVersion

DEFAULT_TAG_REGEX = r"^(?:[\w-]+-)?(?P<version>[vV]?\d+(?:\.\d+){0,2}[^\+]*)(?:\+.*)?$"
Expand Down
4 changes: 3 additions & 1 deletion src/setuptools_scm/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import os
from typing import Iterable
from typing import Iterator
from typing import TYPE_CHECKING

from . import _types as _t
if TYPE_CHECKING:
from . import _types as _t
from .config import Configuration
from .utils import trace

Expand Down
2 changes: 1 addition & 1 deletion src/setuptools_scm/file_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

if TYPE_CHECKING:
from typing_extensions import TypeGuard
from . import _types as _t

from . import _types as _t
from .utils import trace


Expand Down
6 changes: 5 additions & 1 deletion src/setuptools_scm/file_finder_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
import subprocess
import tarfile
from typing import IO
from typing import TYPE_CHECKING

from . import _types as _t
from .file_finder import is_toplevel_acceptable
from .file_finder import scm_find_files
from .utils import do_ex
from .utils import trace

if TYPE_CHECKING:
from . import _types as _t


log = logging.getLogger(__name__)


Expand Down
8 changes: 5 additions & 3 deletions src/setuptools_scm/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
from typing import Callable
from typing import TYPE_CHECKING

from . import _types as _t
from .config import Configuration
from .scm_workdir import Workdir
from .utils import _CmdResult
from .utils import data_from_mime
from .utils import do_ex
from .utils import require_command
Expand All @@ -23,6 +23,8 @@
from .version import tags_to_versions

if TYPE_CHECKING:
from . import _types as _t

from setuptools_scm.hg_git import GitWorkdirHgClient

REF_TAG_RE = re.compile(r"(?<=\btag: )([^,]+)\b")
Expand Down Expand Up @@ -72,7 +74,7 @@ def from_potential_worktree(cls, wd: _t.PathT) -> GitWorkdir | None:

return cls(real_wd)

def do_ex_git(self, cmd: list[str]) -> _t.CmdResult:
def do_ex_git(self, cmd: list[str]) -> _CmdResult:
return self.do_ex(["git", "--git-dir", join(self.path, ".git")] + cmd)

def is_dirty(self) -> bool:
Expand Down Expand Up @@ -120,7 +122,7 @@ def count_all_nodes(self) -> int:
revs, _, _ = self.do_ex_git(["rev-list", "HEAD"])
return revs.count("\n") + 1

def default_describe(self) -> _t.CmdResult:
def default_describe(self) -> _CmdResult:
git_dir = join(self.path, ".git")
return self.do_ex(
DEFAULT_DESCRIBE[:1] + ["--git-dir", git_dir] + DEFAULT_DESCRIBE[1:]
Expand Down
4 changes: 3 additions & 1 deletion src/setuptools_scm/hacks.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from __future__ import annotations

import os
from typing import TYPE_CHECKING

from . import _types as _t
if TYPE_CHECKING:
from . import _types as _t
from .config import Configuration
from .utils import data_from_mime
from .utils import trace
Expand Down
5 changes: 4 additions & 1 deletion src/setuptools_scm/hg.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import datetime
import os
from pathlib import Path
from typing import TYPE_CHECKING

from . import _types as _t
from ._version_cls import Version
from .config import Configuration
from .scm_workdir import Workdir
Expand All @@ -16,6 +16,9 @@
from .version import ScmVersion
from .version import tag_to_version

if TYPE_CHECKING:
from . import _types as _t


class HgWorkdir(Workdir):

Expand Down
7 changes: 4 additions & 3 deletions src/setuptools_scm/hg_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
from . import _types as _t
from .git import GitWorkdir
from .hg import HgWorkdir
from .utils import _CmdResult
from .utils import do_ex
from .utils import require_command
from .utils import trace


_FAKE_GIT_DESCRIBE_ERROR = _t.CmdResult("<>hg git failed", "", 1)
_FAKE_GIT_DESCRIBE_ERROR = _CmdResult("<>hg git failed", "", 1)


class GitWorkdirHgClient(GitWorkdir, HgWorkdir):
Expand Down Expand Up @@ -94,7 +95,7 @@ def count_all_nodes(self) -> int:
revs, _, _ = self.do_ex(["hg", "log", "-r", "ancestors(.)", "-T", "."])
return len(revs)

def default_describe(self) -> _t.CmdResult:
def default_describe(self) -> _CmdResult:
"""
Tentative to reproduce the output of
Expand Down Expand Up @@ -142,4 +143,4 @@ def default_describe(self) -> _t.CmdResult:
if self.is_dirty():
desc += "-dirty"
trace("desc", desc)
return _t.CmdResult(desc, "", 0)
return _CmdResult(desc, "", 0)
9 changes: 8 additions & 1 deletion src/setuptools_scm/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@
import warnings
from typing import Any
from typing import Callable
from typing import TYPE_CHECKING

import setuptools

from . import _get_version
from . import _types as _t
from . import _version_missing
from ._entrypoints import iter_entry_points
from .config import _read_dist_name_from_setup_cfg
from .config import Configuration
from .utils import do
from .utils import trace

if TYPE_CHECKING:
from . import _types as _t


def _warn_on_old_setuptools(_version: str = setuptools.__version__) -> None:
if int(_version.split(".")[0]) < 45:
Expand Down Expand Up @@ -104,8 +107,12 @@ def infer_version(dist: setuptools.Distribution) -> None:
vars(dist.metadata),
)
dist_name = dist.metadata.name
if dist_name is None:
dist_name = _read_dist_name_from_setup_cfg()
if not os.path.isfile("pyproject.toml"):
return
if dist_name == "setuptools_scm":
return
try:
config = Configuration.from_file(dist_name=dist_name)
except LookupError as e:
Expand Down
8 changes: 6 additions & 2 deletions src/setuptools_scm/scm_workdir.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
from __future__ import annotations

from typing import ClassVar
from typing import TYPE_CHECKING

from . import _types as _t
from .utils import _CmdResult
from .utils import do
from .utils import do_ex
from .utils import require_command

if TYPE_CHECKING:
from . import _types as _t


class Workdir:
COMMAND: ClassVar[str]
Expand All @@ -15,7 +19,7 @@ def __init__(self, path: _t.PathT):
require_command(self.COMMAND)
self.path = path

def do_ex(self, cmd: _t.CMD_TYPE) -> _t.CmdResult:
def do_ex(self, cmd: _t.CMD_TYPE) -> _CmdResult:
return do_ex(cmd, cwd=self.path)

def do(self, cmd: _t.CMD_TYPE) -> str:
Expand Down
16 changes: 13 additions & 3 deletions src/setuptools_scm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,23 @@
from types import FunctionType
from typing import Iterator
from typing import Mapping
from typing import NamedTuple
from typing import TYPE_CHECKING

from . import _types as _t
if TYPE_CHECKING:

from . import _types as _t

DEBUG = bool(os.environ.get("SETUPTOOLS_SCM_DEBUG"))
IS_WINDOWS = platform.system() == "Windows"


class _CmdResult(NamedTuple):
out: str
err: str
returncode: int


def no_git_env(env: Mapping[str, str]) -> dict[str, str]:
# adapted from pre-commit
# Too many bugs dealing with environment variables and GIT:
Expand Down Expand Up @@ -69,7 +79,7 @@ def _run(cmd: _t.CMD_TYPE, cwd: _t.PathT) -> subprocess.CompletedProcess[bytes]:
)


def do_ex(cmd: _t.CMD_TYPE, cwd: _t.PathT = ".") -> _t.CmdResult:
def do_ex(cmd: _t.CMD_TYPE, cwd: _t.PathT = ".") -> _CmdResult:
trace("cmd", repr(cmd))
trace(" in", cwd)
if os.name == "posix" and not isinstance(cmd, (list, tuple)):
Expand All @@ -82,7 +92,7 @@ def do_ex(cmd: _t.CMD_TYPE, cwd: _t.PathT = ".") -> _t.CmdResult:
trace("err", repr(res.stderr))
if res.returncode:
trace("ret", res.returncode)
return _t.CmdResult(
return _CmdResult(
ensure_stripped_str(res.stdout), ensure_stripped_str(res.stderr), res.returncode
)

Expand Down
3 changes: 2 additions & 1 deletion src/setuptools_scm/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
if TYPE_CHECKING:
from typing_extensions import Concatenate

from . import _types as _t
from . import _types as _t

from ._version_cls import Version as PkgVersion
from .config import Configuration
from .config import _VersionT
Expand Down
10 changes: 9 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist=py{37,38,39,310}-{test,selfcheck},check_readme,check-dist
envlist=py{37,38,39,310}-{test,selfcheck},check_readme,check-dist,check-bootstrap

[pytest]
testpaths=testing
Expand Down Expand Up @@ -55,6 +55,14 @@ 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

0 comments on commit f1f35bd

Please sign in to comment.