pkgdx 0.6.0__tar.gz → 0.7.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pkgdx-0.6.0 → pkgdx-0.7.0}/CHANGELOG.md +23 -1
- {pkgdx-0.6.0 → pkgdx-0.7.0}/PKG-INFO +28 -4
- {pkgdx-0.6.0 → pkgdx-0.7.0}/README.md +27 -3
- {pkgdx-0.6.0 → pkgdx-0.7.0}/src/pkgdx/_core.py +1 -1
- {pkgdx-0.6.0 → pkgdx-0.7.0}/src/pkgdx/exceptions.py +4 -0
- {pkgdx-0.6.0 → pkgdx-0.7.0}/src/pkgdx/standards/__init__.py +99 -1
- {pkgdx-0.6.0 → pkgdx-0.7.0}/src/pkgdx/standards/_cli.py +23 -6
- {pkgdx-0.6.0 → pkgdx-0.7.0}/src/pkgdx/standards/_hooks.py +98 -4
- {pkgdx-0.6.0 → pkgdx-0.7.0}/src/pkgdx/standards/hooks.toml +2 -2
- {pkgdx-0.6.0 → pkgdx-0.7.0}/src/pkgdx/standards/ruff.toml +0 -1
- {pkgdx-0.6.0 → pkgdx-0.7.0}/.gitignore +0 -0
- {pkgdx-0.6.0 → pkgdx-0.7.0}/COPYRIGHT +0 -0
- {pkgdx-0.6.0 → pkgdx-0.7.0}/LICENSE +0 -0
- {pkgdx-0.6.0 → pkgdx-0.7.0}/pyproject.toml +0 -0
- {pkgdx-0.6.0 → pkgdx-0.7.0}/src/pkgdx/__init__.py +0 -0
- {pkgdx-0.6.0 → pkgdx-0.7.0}/src/pkgdx/__main__.py +0 -0
- {pkgdx-0.6.0 → pkgdx-0.7.0}/src/pkgdx/_types.py +0 -0
- {pkgdx-0.6.0 → pkgdx-0.7.0}/src/pkgdx/py.typed +0 -0
- {pkgdx-0.6.0 → pkgdx-0.7.0}/src/pkgdx/standards/mypy.ini +0 -0
- {pkgdx-0.6.0 → pkgdx-0.7.0}/src/pkgdx/standards/pymarkdown.toml +0 -0
|
@@ -16,7 +16,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
16
16
|
> - `Fixed` for any bug fixes.
|
|
17
17
|
> - `Security` in case of vulnerabilities.
|
|
18
18
|
|
|
19
|
-
## [
|
|
19
|
+
## [0.7.0] - 2026-11-02
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
|
|
23
|
+
- `[tool.pkgdx] exclude` in `pyproject.toml` lists paths the lint, format, typing & markdown hooks
|
|
24
|
+
skip.
|
|
25
|
+
- `pkgdx config` lists each excluded path, marking one that does not exist `(not found)`.
|
|
26
|
+
|
|
27
|
+
### Changed
|
|
28
|
+
|
|
29
|
+
- `docs/guidance/toolchain-pkgdx.md` (1.1.0) & `toolchain-mypy.md` (1.0.1) describe the exclude
|
|
30
|
+
list.
|
|
31
|
+
|
|
32
|
+
### Fixed
|
|
33
|
+
|
|
34
|
+
- The lint, format & typing hooks can skip submodules & vendored code (#5). This needs no reset, but
|
|
35
|
+
both a `pkgdx` lock upgrade & `prek update`.
|
|
36
|
+
- The bundled `ruff.toml` no longer clears Ruff's default exclusions. A directory Ruff skips by
|
|
37
|
+
default, e.g. `dist`, `_build`, `venv` or `node_modules`, is no longer linted or formatted at any
|
|
38
|
+
depth, even when not gitignored. Exported user copies keep the old `exclude = []` until that line
|
|
39
|
+
is deleted.
|
|
40
|
+
- The `prek.toml` template's `#:schema` URL points at prek's `main` branch (it returned a 404).
|
|
41
|
+
- `pkgdx init` creates `.secrets.baseline` with the same exclude pattern as the `pkgdx-secrets` hook.
|
|
20
42
|
|
|
21
43
|
## [0.6.0] - 2026-10-31
|
|
22
44
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: pkgdx
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.0
|
|
4
4
|
Summary: A package to centralise standards across Python projects.
|
|
5
5
|
Project-URL: Documentation, https://gitlab.com/andyrids/pkgdx/blob/main/README.md
|
|
6
6
|
Project-URL: Repository, https://gitlab.com/andyrids/pkgdx
|
|
@@ -170,7 +170,7 @@ uv add --dev git+https://gitlab.com/andyrids/pkgdx.git
|
|
|
170
170
|
```
|
|
171
171
|
|
|
172
172
|
```bash
|
|
173
|
-
uv add --dev git+https://gitlab.com/andyrids/pkgdx.git@v0.
|
|
173
|
+
uv add --dev git+https://gitlab.com/andyrids/pkgdx.git@v0.7.0
|
|
174
174
|
```
|
|
175
175
|
|
|
176
176
|
## CI/CD integration
|
|
@@ -182,6 +182,30 @@ heavy boilerplate across each CI/CD YAML config.
|
|
|
182
182
|
> See `ruff-lint-job` in the project
|
|
183
183
|
> [.gitlab-ci.yml](https://gitlab.com/andyrids/pkgdx/-/blob/main/.gitlab-ci.yml) for an example.
|
|
184
184
|
|
|
185
|
+
## Excluding files and folders
|
|
186
|
+
|
|
187
|
+
The lint, format and typing hooks walk your project themselves, so they check and auto-fix
|
|
188
|
+
everything they find. To leave submodules, vendored code or generated files alone, list them in your
|
|
189
|
+
project's `pyproject.toml`:
|
|
190
|
+
|
|
191
|
+
```toml
|
|
192
|
+
[tool.pkgdx]
|
|
193
|
+
exclude = ["submodules", "vendor", "src/app/_gen.py"]
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Entries are literal paths relative to that file, `/` separated and case-sensitive. A folder covers
|
|
197
|
+
everything below it, and `vendor` never matches `src/vendor`. Globs are rejected, and an invalid
|
|
198
|
+
list fails the hook before any tool runs.
|
|
199
|
+
|
|
200
|
+
The list is committed, so it applies in CI and survives `pkgdx init --reset` and hook updates. It
|
|
201
|
+
also applies to the markdown hook, but `pkgdx-secrets` keeps scanning listed paths, because a secret
|
|
202
|
+
in vendored code is still a leaked secret. Run `uv run pkgdx config` to see the list in effect.
|
|
203
|
+
|
|
204
|
+
> [!NOTE]
|
|
205
|
+
> See [the guidance](https://gitlab.com/andyrids/pkgdx/-/blob/main/docs/guidance/toolchain-pkgdx.md)
|
|
206
|
+
> for the full rules. When upgrading, move both the `pkgdx` lock and the hook `rev` before relying
|
|
207
|
+
> on the list.
|
|
208
|
+
|
|
185
209
|
## Adopting your own standards (external users)
|
|
186
210
|
|
|
187
211
|
`pkgdx` ships bundled canonical standards. To change them without forking, place your own files in a
|
|
@@ -230,8 +254,8 @@ uv run pkgdx config
|
|
|
230
254
|
```
|
|
231
255
|
|
|
232
256
|
This prints one row per file on standard output: its name, its source (`user` or `bundled`) and
|
|
233
|
-
its resolved path
|
|
234
|
-
`PKGDX_CONFIG_DIR` set it.
|
|
257
|
+
its resolved path, then one row per [excluded path](#excluding-files-and-folders). A summary line on
|
|
258
|
+
standard error names the user config directory and whether `PKGDX_CONFIG_DIR` set it.
|
|
235
259
|
|
|
236
260
|
To start from the bundled files, export them into the user config directory:
|
|
237
261
|
|
|
@@ -134,7 +134,7 @@ uv add --dev git+https://gitlab.com/andyrids/pkgdx.git
|
|
|
134
134
|
```
|
|
135
135
|
|
|
136
136
|
```bash
|
|
137
|
-
uv add --dev git+https://gitlab.com/andyrids/pkgdx.git@v0.
|
|
137
|
+
uv add --dev git+https://gitlab.com/andyrids/pkgdx.git@v0.7.0
|
|
138
138
|
```
|
|
139
139
|
|
|
140
140
|
## CI/CD integration
|
|
@@ -146,6 +146,30 @@ heavy boilerplate across each CI/CD YAML config.
|
|
|
146
146
|
> See `ruff-lint-job` in the project
|
|
147
147
|
> [.gitlab-ci.yml](https://gitlab.com/andyrids/pkgdx/-/blob/main/.gitlab-ci.yml) for an example.
|
|
148
148
|
|
|
149
|
+
## Excluding files and folders
|
|
150
|
+
|
|
151
|
+
The lint, format and typing hooks walk your project themselves, so they check and auto-fix
|
|
152
|
+
everything they find. To leave submodules, vendored code or generated files alone, list them in your
|
|
153
|
+
project's `pyproject.toml`:
|
|
154
|
+
|
|
155
|
+
```toml
|
|
156
|
+
[tool.pkgdx]
|
|
157
|
+
exclude = ["submodules", "vendor", "src/app/_gen.py"]
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Entries are literal paths relative to that file, `/` separated and case-sensitive. A folder covers
|
|
161
|
+
everything below it, and `vendor` never matches `src/vendor`. Globs are rejected, and an invalid
|
|
162
|
+
list fails the hook before any tool runs.
|
|
163
|
+
|
|
164
|
+
The list is committed, so it applies in CI and survives `pkgdx init --reset` and hook updates. It
|
|
165
|
+
also applies to the markdown hook, but `pkgdx-secrets` keeps scanning listed paths, because a secret
|
|
166
|
+
in vendored code is still a leaked secret. Run `uv run pkgdx config` to see the list in effect.
|
|
167
|
+
|
|
168
|
+
> [!NOTE]
|
|
169
|
+
> See [the guidance](https://gitlab.com/andyrids/pkgdx/-/blob/main/docs/guidance/toolchain-pkgdx.md)
|
|
170
|
+
> for the full rules. When upgrading, move both the `pkgdx` lock and the hook `rev` before relying
|
|
171
|
+
> on the list.
|
|
172
|
+
|
|
149
173
|
## Adopting your own standards (external users)
|
|
150
174
|
|
|
151
175
|
`pkgdx` ships bundled canonical standards. To change them without forking, place your own files in a
|
|
@@ -194,8 +218,8 @@ uv run pkgdx config
|
|
|
194
218
|
```
|
|
195
219
|
|
|
196
220
|
This prints one row per file on standard output: its name, its source (`user` or `bundled`) and
|
|
197
|
-
its resolved path
|
|
198
|
-
`PKGDX_CONFIG_DIR` set it.
|
|
221
|
+
its resolved path, then one row per [excluded path](#excluding-files-and-folders). A summary line on
|
|
222
|
+
standard error names the user config directory and whether `PKGDX_CONFIG_DIR` set it.
|
|
199
223
|
|
|
200
224
|
To start from the bundled files, export them into the user config directory:
|
|
201
225
|
|
|
@@ -41,5 +41,9 @@ class ConfigDirError(Error):
|
|
|
41
41
|
"""Raised on an invalid `PKGDX_CONFIG_DIR`."""
|
|
42
42
|
|
|
43
43
|
|
|
44
|
+
class ProjectConfigError(Error):
|
|
45
|
+
"""Raised on an invalid `[tool.pkgdx]` table in `pyproject.toml`."""
|
|
46
|
+
|
|
47
|
+
|
|
44
48
|
class ToolNotFoundError(Error):
|
|
45
49
|
"""Raised when a hook tool executable is not found on `PATH`."""
|
|
@@ -8,7 +8,7 @@ import logging
|
|
|
8
8
|
import os
|
|
9
9
|
import sys
|
|
10
10
|
from functools import lru_cache
|
|
11
|
-
from pathlib import Path
|
|
11
|
+
from pathlib import Path, PurePath, PurePosixPath, PureWindowsPath
|
|
12
12
|
from typing import Any
|
|
13
13
|
|
|
14
14
|
logger = logging.getLogger(__package__)
|
|
@@ -26,6 +26,7 @@ BUNDLED_CONFIGS: tuple[Path, ...] = (
|
|
|
26
26
|
PYMARKDOWN_CONFIG,
|
|
27
27
|
RUFF_CONFIG,
|
|
28
28
|
)
|
|
29
|
+
_EXCLUDE_CHARS = frozenset("\\*?[]{}\x7f") | set(map(chr, range(32)))
|
|
29
30
|
|
|
30
31
|
|
|
31
32
|
def user_config_dir() -> Path:
|
|
@@ -80,6 +81,102 @@ def resolve_config(bundled: Path) -> Path:
|
|
|
80
81
|
return bundled
|
|
81
82
|
|
|
82
83
|
|
|
84
|
+
def _relative_exclude(entry: str, below: Path) -> str:
|
|
85
|
+
"""Make an `exclude` entry relative to the working directory.
|
|
86
|
+
|
|
87
|
+
NOTE: Built from path parts, as Windows path functions rewrite names such
|
|
88
|
+
as `NUL`. From at or inside the entry it stays whole, as a bare `..` would
|
|
89
|
+
match everything above the working directory.
|
|
90
|
+
|
|
91
|
+
Args:
|
|
92
|
+
entry: The validated entry, relative to the project root.
|
|
93
|
+
below: The working directory, relative to the project root.
|
|
94
|
+
|
|
95
|
+
Returns:
|
|
96
|
+
The `/` separated path, relative to the working directory.
|
|
97
|
+
"""
|
|
98
|
+
parts = PurePosixPath(entry).parts
|
|
99
|
+
shared = len(PurePath(os.path.commonpath([below, entry])).parts)
|
|
100
|
+
if shared == len(parts):
|
|
101
|
+
shared = 0
|
|
102
|
+
return "/".join([".."] * (len(below.parts) - shared) + [*parts[shared:]])
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def project_excludes() -> list[str]:
|
|
106
|
+
"""Get the paths the project excludes from the hooks.
|
|
107
|
+
|
|
108
|
+
NOTE: Reads `[tool.pkgdx] exclude` from the nearest `pyproject.toml`,
|
|
109
|
+
from the working directory up. Entries are literal paths, as those
|
|
110
|
+
translate exactly into each tool's syntax, & rejecting glob characters
|
|
111
|
+
keeps glob support addable without breaking a config. A path that does
|
|
112
|
+
not exist is allowed, as an uninitialised submodule or an ungenerated
|
|
113
|
+
folder is normal.
|
|
114
|
+
|
|
115
|
+
Raises:
|
|
116
|
+
ProjectConfigError: If the `pyproject.toml` or its table is invalid.
|
|
117
|
+
|
|
118
|
+
Returns:
|
|
119
|
+
The paths, `/` separated & relative to the working directory, or an
|
|
120
|
+
empty list if the project sets none.
|
|
121
|
+
"""
|
|
122
|
+
import tomllib
|
|
123
|
+
|
|
124
|
+
from pkgdx.exceptions import ProjectConfigError
|
|
125
|
+
|
|
126
|
+
cwd = Path.cwd()
|
|
127
|
+
for directory in (cwd, *cwd.parents):
|
|
128
|
+
pyproject = directory / "pyproject.toml"
|
|
129
|
+
# `lexists`: anything unreadable here fails closed below, unskipped
|
|
130
|
+
if os.path.lexists(pyproject):
|
|
131
|
+
break
|
|
132
|
+
else:
|
|
133
|
+
return []
|
|
134
|
+
|
|
135
|
+
try:
|
|
136
|
+
with pyproject.open("rb") as f:
|
|
137
|
+
document = tomllib.load(f)
|
|
138
|
+
except (OSError, ValueError) as e:
|
|
139
|
+
msg = f"Could not read {pyproject}: {e}"
|
|
140
|
+
raise ProjectConfigError(msg) from e
|
|
141
|
+
|
|
142
|
+
tool = document.get("tool", {})
|
|
143
|
+
table = tool.get("pkgdx", {}) if isinstance(tool, dict) else tool
|
|
144
|
+
if not isinstance(table, dict):
|
|
145
|
+
msg = f"`tool.pkgdx` must be a table, not {table!r}, in {pyproject}"
|
|
146
|
+
raise ProjectConfigError(msg)
|
|
147
|
+
|
|
148
|
+
if unknown := table.keys() - {"exclude"}:
|
|
149
|
+
msg = f"Unknown `[tool.pkgdx]` keys in {pyproject}: {sorted(unknown)}"
|
|
150
|
+
raise ProjectConfigError(msg)
|
|
151
|
+
|
|
152
|
+
entries = table.get("exclude", [])
|
|
153
|
+
if not isinstance(entries, list):
|
|
154
|
+
msg = (
|
|
155
|
+
f"`[tool.pkgdx] exclude` must be a list, not {entries!r},"
|
|
156
|
+
f" in {pyproject}"
|
|
157
|
+
)
|
|
158
|
+
raise ProjectConfigError(msg)
|
|
159
|
+
|
|
160
|
+
for entry in entries:
|
|
161
|
+
parts = PurePosixPath(entry).parts if isinstance(entry, str) else ()
|
|
162
|
+
# `rstrip` covers `..` & a name Windows would rewrite, e.g. `vendor.`
|
|
163
|
+
if (
|
|
164
|
+
not parts
|
|
165
|
+
or not _EXCLUDE_CHARS.isdisjoint(entry)
|
|
166
|
+
or PureWindowsPath(entry).anchor
|
|
167
|
+
or any(part != part.rstrip(". ") for part in parts)
|
|
168
|
+
):
|
|
169
|
+
msg = (
|
|
170
|
+
f"`[tool.pkgdx] exclude` entry {entry!r} in {pyproject} must"
|
|
171
|
+
" be a literal relative path, `/` separated, with no globs,"
|
|
172
|
+
" control characters or names ending in a dot or space"
|
|
173
|
+
)
|
|
174
|
+
raise ProjectConfigError(msg)
|
|
175
|
+
|
|
176
|
+
below = cwd.relative_to(directory)
|
|
177
|
+
return [_relative_exclude(entry, below) for entry in entries]
|
|
178
|
+
|
|
179
|
+
|
|
83
180
|
@lru_cache(maxsize=1)
|
|
84
181
|
def _load_prek_config() -> dict[str, Any]:
|
|
85
182
|
"""Load Prek config.
|
|
@@ -177,6 +274,7 @@ __all__: list[str] = [
|
|
|
177
274
|
"PREK_CONFIG",
|
|
178
275
|
"PYMARKDOWN_CONFIG",
|
|
179
276
|
"RUFF_CONFIG",
|
|
277
|
+
"project_excludes",
|
|
180
278
|
"resolve_config",
|
|
181
279
|
"user_config_dir",
|
|
182
280
|
]
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
NOTE: `pkgdx.__main__` adds these commands (`command_init`,
|
|
4
4
|
`command_config`) to the `pkgdx` group. The ledger, notes & closing lines go
|
|
5
|
-
to the run's STDERR console (`ctx.err`); `config` source
|
|
5
|
+
to the run's STDERR console (`ctx.err`); `config` source & exclude rows
|
|
6
|
+
to STDOUT.
|
|
6
7
|
"""
|
|
7
8
|
|
|
8
9
|
import dataclasses
|
|
@@ -303,11 +304,11 @@ def command_init(ctx: pyclig.Context, reset: bool) -> int:
|
|
|
303
304
|
)
|
|
304
305
|
@pyclig.pass_context
|
|
305
306
|
def command_config(ctx: pyclig.Context, export: bool) -> int:
|
|
306
|
-
"""Show config sources or export bundled configs.
|
|
307
|
+
"""Show config sources & excludes or export bundled configs.
|
|
307
308
|
|
|
308
309
|
\f
|
|
309
|
-
NOTE: Source rows go to STDOUT (`ctx.out`). The closing
|
|
310
|
-
`--export` ledger and errors go to STDERR (`ctx.err`).
|
|
310
|
+
NOTE: Source & project exclude rows go to STDOUT (`ctx.out`). The closing
|
|
311
|
+
line, the `--export` ledger and errors go to STDERR (`ctx.err`).
|
|
311
312
|
|
|
312
313
|
Args:
|
|
313
314
|
ctx: The CLI context.
|
|
@@ -315,8 +316,12 @@ def command_config(ctx: pyclig.Context, export: bool) -> int:
|
|
|
315
316
|
|
|
316
317
|
Returns:
|
|
317
318
|
The integer process exit code. 0 on success, 1 on an invalid
|
|
318
|
-
`PKGDX_CONFIG_DIR` or a failed copy
|
|
319
|
-
`--export`.
|
|
319
|
+
`PKGDX_CONFIG_DIR`, an invalid `[tool.pkgdx]` table or a failed copy
|
|
320
|
+
and 130 on Ctrl-C during `--export`.
|
|
321
|
+
|
|
322
|
+
Raises:
|
|
323
|
+
exceptions.ProjectConfigError: If the `[tool.pkgdx]` table is invalid,
|
|
324
|
+
before any row prints.
|
|
320
325
|
"""
|
|
321
326
|
env = standards.CONFIG_DIR_ENV
|
|
322
327
|
try:
|
|
@@ -336,6 +341,7 @@ def command_config(ctx: pyclig.Context, export: bool) -> int:
|
|
|
336
341
|
],
|
|
337
342
|
)
|
|
338
343
|
|
|
344
|
+
excludes = standards.project_excludes()
|
|
339
345
|
width = max(len(bundled.name) for bundled in standards.BUNDLED_CONFIGS)
|
|
340
346
|
users = 0
|
|
341
347
|
for bundled in standards.BUNDLED_CONFIGS:
|
|
@@ -352,6 +358,17 @@ def command_config(ctx: pyclig.Context, export: bool) -> int:
|
|
|
352
358
|
)
|
|
353
359
|
ctx.out.print(row, soft_wrap=True)
|
|
354
360
|
|
|
361
|
+
for path in excludes:
|
|
362
|
+
row = Text.assemble(
|
|
363
|
+
" ",
|
|
364
|
+
"exclude".ljust(width),
|
|
365
|
+
" ",
|
|
366
|
+
(f"{'project':<{_KIND}}", "bold"),
|
|
367
|
+
path,
|
|
368
|
+
"" if Path(path).exists() else " (not found)",
|
|
369
|
+
)
|
|
370
|
+
ctx.out.print(row, soft_wrap=True)
|
|
371
|
+
|
|
355
372
|
via = f"from {env}" if os.environ.get(env) else f"{env} not set"
|
|
356
373
|
sources = f"{users} user, {len(standards.BUNDLED_CONFIGS) - users} bundled"
|
|
357
374
|
ctx.err.print(
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"""Core pre-commit hook logic for the `pkgdx` canonical standards."""
|
|
2
2
|
|
|
3
|
+
import json
|
|
3
4
|
import os
|
|
5
|
+
import re
|
|
4
6
|
import subprocess
|
|
5
7
|
from itertools import islice
|
|
6
8
|
from typing import Any
|
|
@@ -55,27 +57,103 @@ def _run_tool(cmd: list[str], **kwargs: Any) -> int:
|
|
|
55
57
|
return proc.returncode
|
|
56
58
|
|
|
57
59
|
|
|
60
|
+
# PROJECT EXCLUDES
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _ruff_exclude_args() -> list[str]:
|
|
64
|
+
"""Translate the project excludes into Ruff arguments.
|
|
65
|
+
|
|
66
|
+
NOTE: Inline `--config`, as `ruff format --extend-exclude` needs ruff
|
|
67
|
+
0.15.21 & Ruff glob-expands flag values on Windows. `./` anchors a path
|
|
68
|
+
to the working directory; a bare name would match at any depth. Never
|
|
69
|
+
`--exclude`, which would replace Ruff's default exclusions.
|
|
70
|
+
|
|
71
|
+
Returns:
|
|
72
|
+
The arguments, empty if the project excludes nothing.
|
|
73
|
+
|
|
74
|
+
Raises:
|
|
75
|
+
exceptions.ProjectConfigError: If the project list is invalid.
|
|
76
|
+
"""
|
|
77
|
+
excludes = standards.project_excludes()
|
|
78
|
+
if not excludes:
|
|
79
|
+
return []
|
|
80
|
+
paths = [f"./{path}" for path in excludes]
|
|
81
|
+
value = json.dumps(paths, ensure_ascii=False)
|
|
82
|
+
return ["--config", f"extend-exclude={value}"]
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _mypy_exclude_args(args: list[str]) -> list[str]:
|
|
86
|
+
"""Translate the project excludes into Mypy arguments.
|
|
87
|
+
|
|
88
|
+
NOTE: `--exclude` adds to the config's `exclude` & only filters discovery.
|
|
89
|
+
With no args the whole project is checked, so `--follow-imports=silent`
|
|
90
|
+
only hides errors in excluded code the project imports, which a consumer
|
|
91
|
+
cannot do as the shim pins the config file. Args may narrow the target,
|
|
92
|
+
where the flag would hide errors in first-party code too, so it stays off.
|
|
93
|
+
|
|
94
|
+
Args:
|
|
95
|
+
args: The hook arguments.
|
|
96
|
+
|
|
97
|
+
Returns:
|
|
98
|
+
The arguments, empty if the project excludes nothing.
|
|
99
|
+
|
|
100
|
+
Raises:
|
|
101
|
+
exceptions.ProjectConfigError: If the project list is invalid.
|
|
102
|
+
"""
|
|
103
|
+
excludes = standards.project_excludes()
|
|
104
|
+
patterns = [
|
|
105
|
+
arg
|
|
106
|
+
for path in excludes
|
|
107
|
+
for arg in ("--exclude", f"^{re.escape(path)}(/|$)")
|
|
108
|
+
]
|
|
109
|
+
silent = excludes and not args
|
|
110
|
+
return [*patterns, "--follow-imports=silent"] if silent else patterns
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def _is_excluded(arg: str, excludes: list[str]) -> bool:
|
|
114
|
+
"""Check whether a hook argument is a path under an excluded path.
|
|
115
|
+
|
|
116
|
+
NOTE: Compares strings, as Mypy does, so that a match is case-sensitive
|
|
117
|
+
on every platform.
|
|
118
|
+
|
|
119
|
+
Args:
|
|
120
|
+
arg: The hook argument.
|
|
121
|
+
excludes: The project excludes, relative to the working directory.
|
|
122
|
+
|
|
123
|
+
Returns:
|
|
124
|
+
True if the argument is an excluded path or is below one.
|
|
125
|
+
"""
|
|
126
|
+
try:
|
|
127
|
+
path = os.path.relpath(arg).replace(os.sep, "/")
|
|
128
|
+
except ValueError: # on another Windows drive, so outside the project
|
|
129
|
+
return False
|
|
130
|
+
return any(
|
|
131
|
+
path == exclude or path.startswith(f"{exclude}/")
|
|
132
|
+
for exclude in excludes
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
|
|
58
136
|
# CORE HOOK LOGIC
|
|
59
137
|
|
|
60
138
|
|
|
61
139
|
def core_ruff_format(args: list[str]) -> int:
|
|
62
140
|
"""Core logic for ruff formatting."""
|
|
63
141
|
config = standards.resolve_config(standards.RUFF_CONFIG).as_posix()
|
|
64
|
-
cmd = ["ruff", "format", "--config", config
|
|
142
|
+
cmd = ["ruff", "format", "--config", config, *_ruff_exclude_args(), *args]
|
|
65
143
|
return _run_tool(cmd)
|
|
66
144
|
|
|
67
145
|
|
|
68
146
|
def core_ruff_lint(args: list[str]) -> int:
|
|
69
147
|
"""Core logic for ruff linting."""
|
|
70
148
|
config = standards.resolve_config(standards.RUFF_CONFIG).as_posix()
|
|
71
|
-
cmd = ["ruff", "check", "--config", config
|
|
149
|
+
cmd = ["ruff", "check", "--config", config, *_ruff_exclude_args(), *args]
|
|
72
150
|
return _run_tool(cmd)
|
|
73
151
|
|
|
74
152
|
|
|
75
153
|
def core_mypy_typing(args: list[str]) -> int:
|
|
76
154
|
"""Core logic for mypy type checking."""
|
|
77
155
|
config = standards.resolve_config(standards.MYPY_CONFIG).as_posix()
|
|
78
|
-
cmd = ["mypy", "--config-file", config
|
|
156
|
+
cmd = ["mypy", "--config-file", config, *_mypy_exclude_args(args), *args]
|
|
79
157
|
return _run_tool(cmd)
|
|
80
158
|
|
|
81
159
|
|
|
@@ -100,13 +178,19 @@ def core_pymarkdown_lint(args: list[str]) -> int:
|
|
|
100
178
|
The rest - paths & `scan`'s own options, e.g. `-r` or `-e` (`--exclude`)
|
|
101
179
|
- follow `scan` in order, as before.
|
|
102
180
|
|
|
181
|
+
Project excludes are dropped from a plain list of paths, which is what
|
|
182
|
+
prek passes, not passed as `-e`: PyMarkdown exits 1 silently when `-e`
|
|
183
|
+
leaves it nothing to scan, so the hook returns 0. A command with `scan`
|
|
184
|
+
options is hand-written & runs as given, as an option's value is no path.
|
|
185
|
+
|
|
103
186
|
Args:
|
|
104
187
|
args: The hook arguments: paths, `scan` & global options.
|
|
105
188
|
|
|
106
189
|
Returns:
|
|
107
|
-
The PyMarkdown return code.
|
|
190
|
+
The PyMarkdown return code, or 0 if every path was dropped.
|
|
108
191
|
|
|
109
192
|
Raises:
|
|
193
|
+
exceptions.ProjectConfigError: If the project list is invalid.
|
|
110
194
|
exceptions.ToolNotFoundError: If `pymarkdown` is not on `PATH`.
|
|
111
195
|
"""
|
|
112
196
|
config = standards.resolve_config(standards.PYMARKDOWN_CONFIG).as_posix()
|
|
@@ -123,6 +207,16 @@ def core_pymarkdown_lint(args: list[str]) -> int:
|
|
|
123
207
|
options.append(arg)
|
|
124
208
|
else:
|
|
125
209
|
scan_args.append(arg)
|
|
210
|
+
|
|
211
|
+
excludes = standards.project_excludes()
|
|
212
|
+
has_options = any(
|
|
213
|
+
arg.startswith("-") and not os.path.lexists(arg) for arg in scan_args
|
|
214
|
+
)
|
|
215
|
+
if scan_args and not has_options:
|
|
216
|
+
scan_args = [a for a in scan_args if not _is_excluded(a, excludes)]
|
|
217
|
+
if not scan_args:
|
|
218
|
+
return 0
|
|
219
|
+
|
|
126
220
|
cmd = [
|
|
127
221
|
"pymarkdown",
|
|
128
222
|
"--config",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
#:schema https://raw.githubusercontent.com/j178/prek/refs/heads/
|
|
1
|
+
#:schema https://raw.githubusercontent.com/j178/prek/refs/heads/main/prek.schema.json
|
|
2
2
|
|
|
3
3
|
[[repos]]
|
|
4
4
|
repo = "https://gitlab.com/andyrids/pkgdx"
|
|
5
|
-
rev = "v0.
|
|
5
|
+
rev = "v0.7.0"
|
|
6
6
|
|
|
7
7
|
[[repos.hooks]]
|
|
8
8
|
id = "pkgdx-lint"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|