Skip to content

cleanups + bugfixes #996

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

Merged
merged 18 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
2 changes: 2 additions & 0 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ jobs:
name: ${{ matrix.os }} - Python ${{ matrix.python_version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup python
uses: actions/setup-python@v5
if: matrix.python_version != 'msys2'
Expand Down
28 changes: 4 additions & 24 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,39 +1,19 @@
default_language_version:
python: python3.9
repos:
- repo: https://github.com/psf/black
rev: 23.12.1
hooks:
- id: black
args: [--safe, --quiet]
exclude: docs/examples/
- repo: https://github.com/asottile/reorder-python-imports
rev: v3.12.0
hooks:
- id: reorder-python-imports
args: [ "--application-directories=.:src" , --py38-plus, --add-import, 'from __future__ import annotations']
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: check-yaml
- id: debug-statements
- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
- id: flake8
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade
args: [--py38-plus]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.11
rev: v0.2.1
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format

- repo: https://github.com/tox-dev/pyproject-fmt
rev: "1.5.3"
rev: "1.7.0"
hooks:
- id: pyproject-fmt
exclude: docs/examples/
Expand Down
9 changes: 5 additions & 4 deletions _own_version_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@
it works only if the backend-path of the build-system section
from pyproject.toml is respected
"""

from __future__ import annotations

import logging
from typing import Callable

from setuptools import build_meta as build_meta # noqa
from typing import Callable

from setuptools_scm import _types as _t
from setuptools import build_meta as build_meta
from setuptools_scm import Configuration
from setuptools_scm import _types as _t
from setuptools_scm import get_version
from setuptools_scm import git
from setuptools_scm import hg
from setuptools_scm.fallbacks import parse_pkginfo
from setuptools_scm.version import ScmVersion
from setuptools_scm.version import get_local_node_and_date
from setuptools_scm.version import guess_next_dev_version
from setuptools_scm.version import ScmVersion

log = logging.getLogger("setuptools_scm")
# todo: take fake entrypoints from pyproject.toml
Expand Down
4 changes: 4 additions & 0 deletions changelog.d/20240105_133254_subprocess_timeout_var.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

### Changed

- fix #957 - add subprocess timeout control env var
30 changes: 30 additions & 0 deletions changelog.d/20240108_134756_cli_version_file_force.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

### Added

- fix #960: add a ``--force-write-version-files`` flag for the cli

-->
<!--
### Changed

- A bullet item for the Changed category.

-->
<!--
### Deprecated

- A bullet item for the Deprecated category.

-->
<!--
### Fixed

- A bullet item for the Fixed category.

-->
<!--
### Security

- A bullet item for the Security category.

-->
7 changes: 5 additions & 2 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ Callables or other Python objects have to be passed in `setup.py` (via the `use_
for other file types it is necessary to provide `version_file_template`.

`version_file_template: str | None = None`
: A new-style format string that is given the current version as
the `version` keyword argument for formatting.
: A new-style format string taking `version`, `scm_version` and `version_tuple` as parameters.
`version` is the generated next_version as string,
`version_tuple` is a tuple of split numbers/strings and
`scm_version` is the `ScmVersion` instance the current `version` was rendered from


`write_to: Pathlike[str] | Path | None = None`
: (deprecated) legacy option to create a version file relative to the scm root
Expand Down
1 change: 0 additions & 1 deletion docs/examples/version_scheme_code/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from __future__ import annotations

from setuptools import setup

from setuptools_scm import ScmVersion


Expand Down
7 changes: 7 additions & 0 deletions docs/overrides.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@ where the dist name normalization follows adapted PEP 503 semantics.

setuptools_scm parses the environment variable `SETUPTOOLS_SCM_OVERRIDES_FOR_${NORMALIZED_DIST_NAME}`
as a toml inline map to override the configuration data from `pyproject.toml`.

## subprocess timeouts

The environment variable `SETUPTOOLS_SCM_SUBPROCESS_TIMEOUT` allows to override the subprocess timeout.
The default is 40 seconds and should work for most needs. However, users with git lfs + windows reported
situations where this was not enough.

13 changes: 11 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,17 @@ version = { attr = "_own_version_helper.version"}
[tool.setuptools_scm]

[tool.ruff]
select = ["E", "F", "B", "U", "YTT", "C", "DTZ", "PYI", "PT"]
ignore = ["B028"]
required-version = "0.2.1"
fix = true
lint.select = ["E", "F", "B", "U", "YTT", "C", "DTZ", "PYI", "PT", "I", "FURB", "RUF"]
lint.ignore = ["B028"]
lint.preview = true

[tool.ruff.lint.isort]
force-single-line = true
from-first = false
lines-between-types = 1
order-by-type = true

[tool.pytest.ini_options]
testpaths = ["testing"]
Expand Down
24 changes: 12 additions & 12 deletions src/setuptools_scm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@
:copyright: 2010-2023 by Ronny Pfannschmidt
:license: MIT
"""

from __future__ import annotations

from ._config import DEFAULT_LOCAL_SCHEME
from ._config import DEFAULT_VERSION_SCHEME
from ._config import Configuration
from ._config import DEFAULT_LOCAL_SCHEME # soft deprecated
from ._config import DEFAULT_VERSION_SCHEME # soft deprecated
from ._get_version_impl import _get_version # soft deprecated
from ._get_version_impl import get_version # soft deprecated
from ._get_version_impl import _get_version
from ._get_version_impl import get_version
from ._integration.dump_version import dump_version # soft deprecated
from ._version_cls import NonNormalizedVersion
from ._version_cls import Version
from .version import ScmVersion


# Public API
__all__ = [
# soft deprecated imports, left for backward compatibility
"get_version",
"_get_version",
"dump_version",
"DEFAULT_VERSION_SCHEME",
"DEFAULT_LOCAL_SCHEME",
"DEFAULT_VERSION_SCHEME",
"Configuration",
"Version",
"ScmVersion",
"NonNormalizedVersion",
"ScmVersion",
"Version",
"_get_version",
"dump_version",
# soft deprecated imports, left for backward compatibility
"get_version",
]
12 changes: 10 additions & 2 deletions src/setuptools_scm/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ def main(args: list[str] | None = None) -> None:
f" Reason: {ex}.",
file=sys.stderr,
)
config = Configuration(inferred_root)
config = Configuration(root=inferred_root)

version = _get_version(config, force_write_version_files=False)
version = _get_version(
config, force_write_version_files=opts.force_write_version_files
)
if version is None:
raise SystemExit("ERROR: no version found for", opts)
if opts.strip_dev:
Expand Down Expand Up @@ -67,6 +69,12 @@ def _get_cli_opts(args: list[str] | None) -> argparse.Namespace:
action="store_true",
help="remove the dev/local parts of the version before printing the version",
)
parser.add_argument(
"--force-write-version-files",
action="store_true",
help="trigger to write the content of the version files\n"
"its recommended to use normal/editable installation instead)",
)
sub = parser.add_subparsers(title="extra commands", dest="command", metavar="")
# We avoid `metavar` to prevent printing repetitive information
desc = "List files managed by the SCM"
Expand Down
6 changes: 4 additions & 2 deletions src/setuptools_scm/_config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
""" configuration """

from __future__ import annotations

import dataclasses
import os
import re
import warnings

from pathlib import Path
from typing import Any
from typing import Pattern
Expand All @@ -17,9 +19,9 @@
)
from ._integration.pyproject_reading import read_pyproject as _read_pyproject
from ._overrides import read_toml_overrides
from ._version_cls import Version as _Version
from ._version_cls import _validate_version_cls
from ._version_cls import _VersionT
from ._version_cls import Version as _Version

log = _log.log.getChild("config")

Expand Down Expand Up @@ -144,7 +146,7 @@ def from_data(
data.pop("version_cls", None), data.pop("normalize", True)
)
return cls(
relative_to,
relative_to=relative_to,
version_cls=version_cls,
tag_regex=tag_regex,
**data,
Expand Down
12 changes: 7 additions & 5 deletions src/setuptools_scm/_entrypoints.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
from __future__ import annotations

import sys

from typing import TYPE_CHECKING
from typing import Any
from typing import Callable
from typing import cast
from typing import Iterator
from typing import cast
from typing import overload
from typing import TYPE_CHECKING

from . import _log
from . import version

if TYPE_CHECKING:
from . import _types as _t
from ._config import Configuration, ParseFunction
from ._config import Configuration
from ._config import ParseFunction


from importlib.metadata import EntryPoint as EntryPoint


if sys.version_info[:2] < (3, 10):
from importlib.metadata import entry_points as legacy_entry_points

Expand All @@ -38,7 +39,8 @@ def entry_points(group: str) -> EntryPoints:
return EntryPoints(legacy_entry_points()[group])

else:
from importlib.metadata import entry_points, EntryPoints
from importlib.metadata import EntryPoints
from importlib.metadata import entry_points


log = _log.log.getChild("entrypoints")
Expand Down
10 changes: 6 additions & 4 deletions src/setuptools_scm/_file_finders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import itertools
import os
from typing import Callable

from typing import TYPE_CHECKING
from typing import Callable

from .. import _log
from .. import _types as _t
from .._entrypoints import iter_entry_points
from .pathtools import norm_real

if TYPE_CHECKING:
from typing_extensions import TypeGuard
Expand Down Expand Up @@ -37,12 +39,12 @@ def scm_find_files(
Spec here: https://setuptools.pypa.io/en/latest/userguide/extension.html#\
adding-support-for-revision-control-systems
"""
realpath = os.path.normcase(os.path.realpath(path))
realpath = norm_real(path)
seen: set[str] = set()
res: list[str] = []
for dirpath, dirnames, filenames in os.walk(realpath, followlinks=True):
# dirpath with symlinks resolved
realdirpath = os.path.normcase(os.path.realpath(dirpath))
realdirpath = norm_real(dirpath)

def _link_not_in_scm(n: str, realdirpath: str = realdirpath) -> bool:
fn = os.path.join(realdirpath, os.path.normcase(n))
Expand Down Expand Up @@ -72,7 +74,7 @@ def _link_not_in_scm(n: str, realdirpath: str = realdirpath) -> bool:
continue
# dirpath + filename with symlinks preserved
fullfilename = os.path.join(dirpath, filename)
is_tracked = os.path.normcase(os.path.realpath(fullfilename)) in scm_files
is_tracked = norm_real(fullfilename) in scm_files
if force_all_files or is_tracked:
res.append(os.path.join(path, os.path.relpath(fullfilename, realpath)))
seen.add(realdirpath)
Expand Down
10 changes: 6 additions & 4 deletions src/setuptools_scm/_file_finders/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import os
import subprocess
import tarfile

from typing import IO

from . import is_toplevel_acceptable
from . import scm_find_files
from .. import _types as _t
from .._run_cmd import run as _run
from ..integration import data_from_mime
from . import is_toplevel_acceptable
from . import scm_find_files
from .pathtools import norm_real

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -43,7 +45,7 @@ def _git_toplevel(path: str) -> str | None:
# ``\\`` is just and escape for `\`
out = cwd[: -len(out)]
log.debug("find files toplevel %s", out)
return os.path.normcase(os.path.realpath(out.strip()))
return norm_real(out)
except subprocess.CalledProcessError:
# git returned error, we are not in a git repo
return None
Expand Down Expand Up @@ -91,7 +93,7 @@ def git_find_files(path: _t.PathT = "") -> list[str]:
toplevel = _git_toplevel(os.fspath(path))
if not is_toplevel_acceptable(toplevel):
return []
fullpath = os.path.abspath(os.path.normpath(path))
fullpath = norm_real(path)
if not fullpath.startswith(toplevel):
log.warning("toplevel mismatch computed %s vs resolved %s ", toplevel, fullpath)
git_files, git_dirs = _git_ls_files_and_dirs(toplevel)
Expand Down
Loading