Skip to content

Commit 6a7ad1c

Browse files
Merge pull request #936 from RonnyPfannschmidt/try-ruff
introduce ruff as a linter
2 parents 056584b + 57bd901 commit 6a7ad1c

22 files changed

+119
-73
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ repos:
2727
hooks:
2828
- id: pyupgrade
2929
args: [--py38-plus]
30+
- repo: https://github.com/astral-sh/ruff-pre-commit
31+
rev: v0.0.291
32+
hooks:
33+
- id: ruff
34+
args: [--fix, --exit-non-zero-on-fix]
3035
- repo: https://github.com/tox-dev/pyproject-fmt
3136
rev: "1.1.0"
3237
hooks:

MANIFEST.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
exclude *.nix
22
exclude .pre-commit-config.yaml
3+
exclude changelog.d/*
34
exclude .git_archival.txt
5+
exclude .readthedocs.yaml
46
include *.py
57
include testing/*.py
68
include tox.ini
@@ -10,5 +12,14 @@ include *.toml
1012
include mypy.ini
1113
include testing/Dockerfile.*
1214
include src/setuptools_scm/.git_archival.txt
15+
include README.md
16+
include CHANGELOG.md
17+
18+
1319
recursive-include testing *.bash
1420
prune nextgen
21+
22+
recursive-include docs *.md
23+
include docs/examples/version_scheme_code/*.py
24+
include docs/examples/version_scheme_code/*.toml
25+
include mkdocs.yml
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
### Changed
3+
4+
- introduce ruff as a linter

hatch.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
[envs.test]
2+
extras = ["test", "dev"]
3+
4+
[envs.test.scripts]
5+
all = "pytest {args}"
6+
7+
[[env.test.matrix]]
8+
python = ["3.8", "3.9", "3.10", "3.11"]
9+
10+
111
[envs.docs]
212
python = "3.11"
313
extras = ["docs"]

pyproject.toml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ dependencies = [
4242
"packaging>=20",
4343
"setuptools",
4444
'tomli>=1; python_version < "3.11"',
45-
'typing-extensions; python_version < "3.11"',
45+
"typing-extensions",
4646
]
4747
[project.optional-dependencies]
4848
docs = [
@@ -108,5 +108,25 @@ version = { attr = "_own_version_helper.version"}
108108

109109
[tool.setuptools_scm]
110110

111+
[tool.ruff]
112+
select = ["E", "F", "B", "U", "YTT", "C", "DTZ", "PYI", "PT"]
113+
ignore = ["B028"]
114+
115+
[tool.pytest.ini_options]
116+
testpaths = ["testing"]
117+
filterwarnings = [
118+
"error",
119+
"ignore:.*tool\\.setuptools_scm.*",
120+
"ignore:.*git archive did not support describe output.*:UserWarning",
121+
]
122+
log_level = "debug"
123+
log_cli_level = "info"
124+
# disable unraisable until investigated
125+
addopts = ["-p", "no:unraisableexception"]
126+
markers = [
127+
"issue(id): reference to github issue",
128+
"skip_commit: allows to skip committing in the helpers",
129+
]
130+
111131
[tool.scriv]
112132
format = "md"

src/setuptools_scm/_config.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ def _check_absolute_root(root: _t.PathT, relative_to: _t.PathT | None) -> str:
6565
and not os.path.commonpath([root, relative_to]) == root
6666
):
6767
warnings.warn(
68-
"absolute root path '%s' overrides relative_to '%s'"
69-
% (root, relative_to)
68+
f"absolute root path '{root}' overrides relative_to '{relative_to}'"
7069
)
7170
if os.path.isdir(relative_to):
7271
warnings.warn(

src/setuptools_scm/_file_finders/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def scm_find_files(
4444
# dirpath with symlinks resolved
4545
realdirpath = os.path.normcase(os.path.realpath(dirpath))
4646

47-
def _link_not_in_scm(n: str) -> bool:
47+
def _link_not_in_scm(n: str, realdirpath: str = realdirpath) -> bool:
4848
fn = os.path.join(realdirpath, os.path.normcase(n))
4949
return os.path.islink(fn) and fn not in scm_files
5050

src/setuptools_scm/_file_finders/hg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def _hg_ls_files_and_dirs(toplevel: str) -> tuple[set[str], set[str]]:
3434
hg_dirs = {toplevel}
3535
res = _run(["hg", "files"], cwd=toplevel)
3636
if res.returncode:
37-
(), ()
37+
return set(), set()
3838
for name in res.stdout.splitlines():
3939
name = os.path.normcase(name).replace("/", os.path.sep)
4040
fullname = os.path.join(toplevel, name)

src/setuptools_scm/_version_cls.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ def _validate_version_cls(
8484
try:
8585
return cast(Type[_VersionT], import_name(version_cls))
8686
except: # noqa
87-
raise ValueError(f"Unable to import version_cls='{version_cls}'")
87+
raise ValueError(
88+
f"Unable to import version_cls='{version_cls}'"
89+
) from None
8890
else:
8991
return version_cls

src/setuptools_scm/git.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import warnings
99
from datetime import date
1010
from datetime import datetime
11+
from datetime import timezone
1112
from os.path import samefile
1213
from pathlib import Path
1314
from typing import Callable
@@ -268,7 +269,7 @@ def _git_parse_inner(
268269
tag=tag, distance=distance, dirty=dirty, node=node, config=config
269270
)
270271
branch = wd.get_branch()
271-
node_date = wd.get_head_date() or date.today()
272+
node_date = wd.get_head_date() or datetime.now(timezone.utc).date()
272273
return dataclasses.replace(version, branch=branch, node_date=node_date)
273274

274275

0 commit comments

Comments
 (0)