pyhyi 0.0.1__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.
- pyhyi-0.0.1/.gitattributes +1 -0
- pyhyi-0.0.1/.github/workflows/ci.yml +45 -0
- pyhyi-0.0.1/.github/workflows/release.yml +56 -0
- pyhyi-0.0.1/.gitignore +23 -0
- pyhyi-0.0.1/LICENSE +21 -0
- pyhyi-0.0.1/PKG-INFO +165 -0
- pyhyi-0.0.1/README.md +149 -0
- pyhyi-0.0.1/docs/releasing.md +45 -0
- pyhyi-0.0.1/pyproject.toml +54 -0
- pyhyi-0.0.1/scripts/build_aliases.py +102 -0
- pyhyi-0.0.1/src/pyhyi/__init__.py +3 -0
- pyhyi-0.0.1/src/pyhyi/__main__.py +5 -0
- pyhyi-0.0.1/src/pyhyi/baseline.py +87 -0
- pyhyi-0.0.1/src/pyhyi/cli.py +145 -0
- pyhyi-0.0.1/src/pyhyi/config.py +115 -0
- pyhyi-0.0.1/src/pyhyi/context.py +109 -0
- pyhyi-0.0.1/src/pyhyi/engine.py +144 -0
- pyhyi-0.0.1/src/pyhyi/errors.py +13 -0
- pyhyi-0.0.1/src/pyhyi/findings.py +47 -0
- pyhyi-0.0.1/src/pyhyi/git.py +108 -0
- pyhyi-0.0.1/src/pyhyi/paths.py +57 -0
- pyhyi-0.0.1/src/pyhyi/registry.py +36 -0
- pyhyi-0.0.1/src/pyhyi/report.py +52 -0
- pyhyi-0.0.1/src/pyhyi/rules/__init__.py +104 -0
- pyhyi-0.0.1/src/pyhyi/rules/suppression.py +40 -0
- pyhyi-0.0.1/src/pyhyi/suppressions.py +58 -0
- pyhyi-0.0.1/tests/conftest.py +56 -0
- pyhyi-0.0.1/tests/test_aliases.py +49 -0
- pyhyi-0.0.1/tests/test_baseline.py +68 -0
- pyhyi-0.0.1/tests/test_cli.py +111 -0
- pyhyi-0.0.1/tests/test_config.py +93 -0
- pyhyi-0.0.1/tests/test_engine.py +190 -0
- pyhyi-0.0.1/tests/test_git.py +98 -0
- pyhyi-0.0.1/tests/test_paths.py +48 -0
- pyhyi-0.0.1/tests/test_repo_privacy.py +38 -0
- pyhyi-0.0.1/tests/test_suppressions.py +45 -0
- pyhyi-0.0.1/uv.lock +220 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
* text=auto eol=lf
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
lint:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
- uses: astral-sh/setup-uv@v6
|
|
17
|
+
- run: uv sync --locked
|
|
18
|
+
- run: uv run ruff check .
|
|
19
|
+
- run: uv run ruff format --check .
|
|
20
|
+
- run: uv run pyhyi check
|
|
21
|
+
|
|
22
|
+
build:
|
|
23
|
+
# Same build as the release workflow, so packaging breaks before a tag does.
|
|
24
|
+
runs-on: ubuntu-latest
|
|
25
|
+
steps:
|
|
26
|
+
- uses: actions/checkout@v4
|
|
27
|
+
- uses: astral-sh/setup-uv@v6
|
|
28
|
+
- run: uv build --out-dir dist/pyhyi
|
|
29
|
+
- run: python3 scripts/build_aliases.py --out-dir dist
|
|
30
|
+
- run: ls -R dist
|
|
31
|
+
|
|
32
|
+
test:
|
|
33
|
+
strategy:
|
|
34
|
+
fail-fast: false
|
|
35
|
+
matrix:
|
|
36
|
+
os: [ubuntu-latest, windows-latest]
|
|
37
|
+
python: ["3.10", "3.14"]
|
|
38
|
+
runs-on: ${{ matrix.os }}
|
|
39
|
+
steps:
|
|
40
|
+
- uses: actions/checkout@v4
|
|
41
|
+
- uses: astral-sh/setup-uv@v6
|
|
42
|
+
with:
|
|
43
|
+
python-version: ${{ matrix.python }}
|
|
44
|
+
- run: uv sync --locked
|
|
45
|
+
- run: uv run pytest
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
# Pushing a tag vX.Y.Z publishes pyhyi and its alias packages to PyPI via
|
|
4
|
+
# trusted publishing (no API tokens). Every package is published by its own
|
|
5
|
+
# job in its own environment `pypi-<package>`, matching the trusted publisher
|
|
6
|
+
# configured for that project on PyPI. See docs/releasing.md.
|
|
7
|
+
|
|
8
|
+
on:
|
|
9
|
+
push:
|
|
10
|
+
tags: ["v*"]
|
|
11
|
+
|
|
12
|
+
permissions:
|
|
13
|
+
contents: read
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
build:
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
outputs:
|
|
19
|
+
packages: ${{ steps.list.outputs.packages }}
|
|
20
|
+
steps:
|
|
21
|
+
- uses: actions/checkout@v4
|
|
22
|
+
- uses: astral-sh/setup-uv@v6
|
|
23
|
+
- name: Check that the tag matches the package version
|
|
24
|
+
run: |
|
|
25
|
+
version=$(sed -n 's/^__version__ = "\(.*\)"$/\1/p' src/pyhyi/__init__.py)
|
|
26
|
+
echo "tag: ${GITHUB_REF_NAME}, package: ${version}"
|
|
27
|
+
test "${GITHUB_REF_NAME}" = "v${version}"
|
|
28
|
+
- run: uv build --out-dir dist/pyhyi
|
|
29
|
+
- run: python3 scripts/build_aliases.py --out-dir dist
|
|
30
|
+
- id: list
|
|
31
|
+
run: echo "packages=$(ls dist | jq -R -s -c 'split("\n") | map(select(length > 0))')" >> "$GITHUB_OUTPUT"
|
|
32
|
+
- uses: actions/upload-artifact@v4
|
|
33
|
+
with:
|
|
34
|
+
name: dist
|
|
35
|
+
path: dist/
|
|
36
|
+
|
|
37
|
+
publish:
|
|
38
|
+
needs: build
|
|
39
|
+
runs-on: ubuntu-latest
|
|
40
|
+
strategy:
|
|
41
|
+
fail-fast: false
|
|
42
|
+
matrix:
|
|
43
|
+
package: ${{ fromJSON(needs.build.outputs.packages) }}
|
|
44
|
+
environment:
|
|
45
|
+
name: pypi-${{ matrix.package }}
|
|
46
|
+
url: https://pypi.org/project/${{ matrix.package }}/
|
|
47
|
+
permissions:
|
|
48
|
+
id-token: write
|
|
49
|
+
steps:
|
|
50
|
+
- uses: actions/download-artifact@v4
|
|
51
|
+
with:
|
|
52
|
+
name: dist
|
|
53
|
+
path: dist/
|
|
54
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
55
|
+
with:
|
|
56
|
+
packages-dir: dist/${{ matrix.package }}/
|
pyhyi-0.0.1/.gitignore
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Private, never published: transcripts, notes, local experiments.
|
|
2
|
+
/private/
|
|
3
|
+
|
|
4
|
+
# Agent instructions and agent tooling stay local.
|
|
5
|
+
/AGENTS.md
|
|
6
|
+
/CLAUDE.md
|
|
7
|
+
.claude/
|
|
8
|
+
.codex/
|
|
9
|
+
.agents/
|
|
10
|
+
.skills/
|
|
11
|
+
.cursor/
|
|
12
|
+
|
|
13
|
+
# Python
|
|
14
|
+
__pycache__/
|
|
15
|
+
*.py[cod]
|
|
16
|
+
*.egg-info/
|
|
17
|
+
build/
|
|
18
|
+
dist/
|
|
19
|
+
.venv/
|
|
20
|
+
.pytest_cache/
|
|
21
|
+
.ruff_cache/
|
|
22
|
+
.coverage
|
|
23
|
+
htmlcov/
|
pyhyi-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 marsik641
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
pyhyi-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: pyhyi
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Repository hygiene checker: catches the mess autonomous coding agents leave behind.
|
|
5
|
+
Project-URL: Repository, https://github.com/marsik641/pyhyi
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
9
|
+
Classifier: Environment :: Console
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
13
|
+
Requires-Python: >=3.10
|
|
14
|
+
Requires-Dist: tomli>=1.1; python_version < '3.11'
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# pyhyi
|
|
18
|
+
|
|
19
|
+
Repository hygiene checker. It catches the mess that autonomous coding agents
|
|
20
|
+
(and hurried humans) leave behind: dump folders, stale docs, broken doc links,
|
|
21
|
+
forgotten TODOs, junk in the repo root, commits that ignore the convention.
|
|
22
|
+
|
|
23
|
+
> Status: pre-alpha. The engine is in place; real hygiene rules come next.
|
|
24
|
+
|
|
25
|
+
## Idea
|
|
26
|
+
|
|
27
|
+
Strong models know the conventions. They just don't follow the implicit ones
|
|
28
|
+
unless someone enforces them. pyhyi turns those implicit expectations into
|
|
29
|
+
explicit, checkable rules, so a tool slaps the agent's hands instead of a human.
|
|
30
|
+
|
|
31
|
+
- **Language-agnostic core** — git history, file layout, text references between
|
|
32
|
+
files. Works on any repository, not only Python ones.
|
|
33
|
+
- **Thin language adapters** (planned) — precise dependency graphs where needed,
|
|
34
|
+
built on existing tools rather than custom parsers.
|
|
35
|
+
- **Precision over recall** — every finding should be worth reading. Suppressions
|
|
36
|
+
require a reason; a baseline lets legacy repositories adopt it gradually.
|
|
37
|
+
- **Agent-friendly output** — JSON reports an agent can act on directly.
|
|
38
|
+
|
|
39
|
+
## Install
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
pip install pyhyi
|
|
43
|
+
# or run without installing
|
|
44
|
+
uvx pyhyi check
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Requires Python 3.10+ and `git` on `PATH`.
|
|
48
|
+
|
|
49
|
+
## Usage
|
|
50
|
+
|
|
51
|
+
```sh
|
|
52
|
+
pyhyi check # check the repository containing the current directory
|
|
53
|
+
pyhyi check path/to/repo --format json
|
|
54
|
+
pyhyi check --select rule-a,rule-b --ignore rule-c
|
|
55
|
+
pyhyi baseline # record current issues; only new ones fail afterwards
|
|
56
|
+
pyhyi rules # list available rules
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Exit codes: `0` no issues, `1` issues found, `2` usage, configuration or
|
|
60
|
+
internal error.
|
|
61
|
+
|
|
62
|
+
pyhyi scans tracked files plus untracked files that are not git-ignored, so
|
|
63
|
+
junk is caught before it is committed.
|
|
64
|
+
|
|
65
|
+
## Configuration
|
|
66
|
+
|
|
67
|
+
Settings live in the repository root, in the first file found of
|
|
68
|
+
`pyhyi.toml`, `.pyhyi.toml` (top-level keys) or `pyproject.toml`
|
|
69
|
+
(`[tool.pyhyi]` table). Non-Python projects do not need a `pyproject.toml`.
|
|
70
|
+
|
|
71
|
+
```toml
|
|
72
|
+
[tool.pyhyi]
|
|
73
|
+
select = ["rule-a", "rule-b"] # default: every rule enabled by default
|
|
74
|
+
ignore = ["rule-c"]
|
|
75
|
+
exclude = ["vendor", "*.min.js", "docs/generated/**"]
|
|
76
|
+
baseline = ".pyhyi-baseline.json"
|
|
77
|
+
|
|
78
|
+
[tool.pyhyi.per-path-ignores]
|
|
79
|
+
"tests/fixtures/**" = ["rule-a"]
|
|
80
|
+
|
|
81
|
+
[tool.pyhyi.rules.rule-a]
|
|
82
|
+
some-option = 10
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Unknown keys, unknown rule ids and options of the wrong type are errors, so
|
|
86
|
+
typos do not silently disable checks.
|
|
87
|
+
|
|
88
|
+
Path patterns use `/`. `*` matches within one path segment, `**` across
|
|
89
|
+
segments. A pattern without `/` matches a name at any depth (`node_modules`);
|
|
90
|
+
a pattern with `/` is anchored at the root (`docs/*.md`, `/build`). Matching a
|
|
91
|
+
directory covers everything inside it.
|
|
92
|
+
|
|
93
|
+
## Suppressing a finding
|
|
94
|
+
|
|
95
|
+
Put a marker in a comment on the reported line, naming the rule and the reason:
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
data = load() # pyhyi: ignore[rule-a] generated by the release script
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
```markdown
|
|
102
|
+
<!-- pyhyi: ignore[rule-a] link to an external mirror -->
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
The comment opener (`#`, `//`, `/*`, `<!--`, `--`, `;`, `%`, `{#`) must start
|
|
106
|
+
the line or follow whitespace. A suppression without a reason is not applied,
|
|
107
|
+
and the `bad-suppression` rule reports it together with markers that name
|
|
108
|
+
unknown rules. Findings without a line (commits, repository layout) are
|
|
109
|
+
silenced through `ignore` or `per-path-ignores` instead.
|
|
110
|
+
|
|
111
|
+
## Baseline
|
|
112
|
+
|
|
113
|
+
On an existing repository the first run may report hundreds of issues.
|
|
114
|
+
`pyhyi baseline` writes them to `.pyhyi-baseline.json`; `pyhyi check` then fails
|
|
115
|
+
only on new ones. Entries are matched by rule, file and a line-independent key,
|
|
116
|
+
so editing elsewhere in a file does not bring them back. When baselined issues
|
|
117
|
+
get fixed, `check` says so; run `pyhyi baseline` again to shrink the file.
|
|
118
|
+
Commit the baseline file.
|
|
119
|
+
|
|
120
|
+
## Writing rules
|
|
121
|
+
|
|
122
|
+
A rule is a class with a kebab-case `id`, a one-line `summary` and a `check`
|
|
123
|
+
method that yields findings:
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
from pyhyi.rules import Rule
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
class NoTmpFiles(Rule):
|
|
130
|
+
id = "no-tmp-files"
|
|
131
|
+
summary = "Temporary files must not be in the repository."
|
|
132
|
+
default_options = {"suffixes": [".tmp", ".bak"]}
|
|
133
|
+
|
|
134
|
+
def check(self, ctx):
|
|
135
|
+
for path in ctx.files:
|
|
136
|
+
if path.endswith(tuple(self.options["suffixes"])):
|
|
137
|
+
yield self.finding("Temporary file in the repository", path=path)
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
`ctx` gives read-only access to the repository: `files`, `exists()`,
|
|
141
|
+
`read_text()`, `lines()` and `commits`. Keep line numbers out of messages: the
|
|
142
|
+
message doubles as the baseline key unless `key=` is passed.
|
|
143
|
+
|
|
144
|
+
Third-party packages register rules through an entry point:
|
|
145
|
+
|
|
146
|
+
```toml
|
|
147
|
+
[project.entry-points."pyhyi.rules"]
|
|
148
|
+
no-tmp-files = "my_package.rules:NoTmpFiles"
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Development
|
|
152
|
+
|
|
153
|
+
```sh
|
|
154
|
+
uv sync
|
|
155
|
+
uv run pytest
|
|
156
|
+
uv run ruff check .
|
|
157
|
+
uv run ruff format --check .
|
|
158
|
+
uv run pyhyi check
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Releases are described in [docs/releasing.md](https://github.com/marsik641/pyhyi/blob/main/docs/releasing.md).
|
|
162
|
+
|
|
163
|
+
## License
|
|
164
|
+
|
|
165
|
+
MIT
|
pyhyi-0.0.1/README.md
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# pyhyi
|
|
2
|
+
|
|
3
|
+
Repository hygiene checker. It catches the mess that autonomous coding agents
|
|
4
|
+
(and hurried humans) leave behind: dump folders, stale docs, broken doc links,
|
|
5
|
+
forgotten TODOs, junk in the repo root, commits that ignore the convention.
|
|
6
|
+
|
|
7
|
+
> Status: pre-alpha. The engine is in place; real hygiene rules come next.
|
|
8
|
+
|
|
9
|
+
## Idea
|
|
10
|
+
|
|
11
|
+
Strong models know the conventions. They just don't follow the implicit ones
|
|
12
|
+
unless someone enforces them. pyhyi turns those implicit expectations into
|
|
13
|
+
explicit, checkable rules, so a tool slaps the agent's hands instead of a human.
|
|
14
|
+
|
|
15
|
+
- **Language-agnostic core** — git history, file layout, text references between
|
|
16
|
+
files. Works on any repository, not only Python ones.
|
|
17
|
+
- **Thin language adapters** (planned) — precise dependency graphs where needed,
|
|
18
|
+
built on existing tools rather than custom parsers.
|
|
19
|
+
- **Precision over recall** — every finding should be worth reading. Suppressions
|
|
20
|
+
require a reason; a baseline lets legacy repositories adopt it gradually.
|
|
21
|
+
- **Agent-friendly output** — JSON reports an agent can act on directly.
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
pip install pyhyi
|
|
27
|
+
# or run without installing
|
|
28
|
+
uvx pyhyi check
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Requires Python 3.10+ and `git` on `PATH`.
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
pyhyi check # check the repository containing the current directory
|
|
37
|
+
pyhyi check path/to/repo --format json
|
|
38
|
+
pyhyi check --select rule-a,rule-b --ignore rule-c
|
|
39
|
+
pyhyi baseline # record current issues; only new ones fail afterwards
|
|
40
|
+
pyhyi rules # list available rules
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Exit codes: `0` no issues, `1` issues found, `2` usage, configuration or
|
|
44
|
+
internal error.
|
|
45
|
+
|
|
46
|
+
pyhyi scans tracked files plus untracked files that are not git-ignored, so
|
|
47
|
+
junk is caught before it is committed.
|
|
48
|
+
|
|
49
|
+
## Configuration
|
|
50
|
+
|
|
51
|
+
Settings live in the repository root, in the first file found of
|
|
52
|
+
`pyhyi.toml`, `.pyhyi.toml` (top-level keys) or `pyproject.toml`
|
|
53
|
+
(`[tool.pyhyi]` table). Non-Python projects do not need a `pyproject.toml`.
|
|
54
|
+
|
|
55
|
+
```toml
|
|
56
|
+
[tool.pyhyi]
|
|
57
|
+
select = ["rule-a", "rule-b"] # default: every rule enabled by default
|
|
58
|
+
ignore = ["rule-c"]
|
|
59
|
+
exclude = ["vendor", "*.min.js", "docs/generated/**"]
|
|
60
|
+
baseline = ".pyhyi-baseline.json"
|
|
61
|
+
|
|
62
|
+
[tool.pyhyi.per-path-ignores]
|
|
63
|
+
"tests/fixtures/**" = ["rule-a"]
|
|
64
|
+
|
|
65
|
+
[tool.pyhyi.rules.rule-a]
|
|
66
|
+
some-option = 10
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Unknown keys, unknown rule ids and options of the wrong type are errors, so
|
|
70
|
+
typos do not silently disable checks.
|
|
71
|
+
|
|
72
|
+
Path patterns use `/`. `*` matches within one path segment, `**` across
|
|
73
|
+
segments. A pattern without `/` matches a name at any depth (`node_modules`);
|
|
74
|
+
a pattern with `/` is anchored at the root (`docs/*.md`, `/build`). Matching a
|
|
75
|
+
directory covers everything inside it.
|
|
76
|
+
|
|
77
|
+
## Suppressing a finding
|
|
78
|
+
|
|
79
|
+
Put a marker in a comment on the reported line, naming the rule and the reason:
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
data = load() # pyhyi: ignore[rule-a] generated by the release script
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
```markdown
|
|
86
|
+
<!-- pyhyi: ignore[rule-a] link to an external mirror -->
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The comment opener (`#`, `//`, `/*`, `<!--`, `--`, `;`, `%`, `{#`) must start
|
|
90
|
+
the line or follow whitespace. A suppression without a reason is not applied,
|
|
91
|
+
and the `bad-suppression` rule reports it together with markers that name
|
|
92
|
+
unknown rules. Findings without a line (commits, repository layout) are
|
|
93
|
+
silenced through `ignore` or `per-path-ignores` instead.
|
|
94
|
+
|
|
95
|
+
## Baseline
|
|
96
|
+
|
|
97
|
+
On an existing repository the first run may report hundreds of issues.
|
|
98
|
+
`pyhyi baseline` writes them to `.pyhyi-baseline.json`; `pyhyi check` then fails
|
|
99
|
+
only on new ones. Entries are matched by rule, file and a line-independent key,
|
|
100
|
+
so editing elsewhere in a file does not bring them back. When baselined issues
|
|
101
|
+
get fixed, `check` says so; run `pyhyi baseline` again to shrink the file.
|
|
102
|
+
Commit the baseline file.
|
|
103
|
+
|
|
104
|
+
## Writing rules
|
|
105
|
+
|
|
106
|
+
A rule is a class with a kebab-case `id`, a one-line `summary` and a `check`
|
|
107
|
+
method that yields findings:
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
from pyhyi.rules import Rule
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
class NoTmpFiles(Rule):
|
|
114
|
+
id = "no-tmp-files"
|
|
115
|
+
summary = "Temporary files must not be in the repository."
|
|
116
|
+
default_options = {"suffixes": [".tmp", ".bak"]}
|
|
117
|
+
|
|
118
|
+
def check(self, ctx):
|
|
119
|
+
for path in ctx.files:
|
|
120
|
+
if path.endswith(tuple(self.options["suffixes"])):
|
|
121
|
+
yield self.finding("Temporary file in the repository", path=path)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
`ctx` gives read-only access to the repository: `files`, `exists()`,
|
|
125
|
+
`read_text()`, `lines()` and `commits`. Keep line numbers out of messages: the
|
|
126
|
+
message doubles as the baseline key unless `key=` is passed.
|
|
127
|
+
|
|
128
|
+
Third-party packages register rules through an entry point:
|
|
129
|
+
|
|
130
|
+
```toml
|
|
131
|
+
[project.entry-points."pyhyi.rules"]
|
|
132
|
+
no-tmp-files = "my_package.rules:NoTmpFiles"
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Development
|
|
136
|
+
|
|
137
|
+
```sh
|
|
138
|
+
uv sync
|
|
139
|
+
uv run pytest
|
|
140
|
+
uv run ruff check .
|
|
141
|
+
uv run ruff format --check .
|
|
142
|
+
uv run pyhyi check
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Releases are described in [docs/releasing.md](https://github.com/marsik641/pyhyi/blob/main/docs/releasing.md).
|
|
146
|
+
|
|
147
|
+
## License
|
|
148
|
+
|
|
149
|
+
MIT
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Releasing
|
|
2
|
+
|
|
3
|
+
pyhyi is published to PyPI together with alias packages (`pyhui`, `pyhuy`,
|
|
4
|
+
`pihui`, `pihuy`, `pyhuj`, `pohuj`). An alias contains no code: it depends on
|
|
5
|
+
the exact same pyhyi version, so installing it installs pyhyi. Aliases are
|
|
6
|
+
generated by `scripts/build_aliases.py`; the list lives in `ALIASES` there.
|
|
7
|
+
|
|
8
|
+
Publishing uses PyPI trusted publishing from GitHub Actions, so no API tokens
|
|
9
|
+
are stored anywhere.
|
|
10
|
+
|
|
11
|
+
## Release a version
|
|
12
|
+
|
|
13
|
+
1. Bump `__version__` in `src/pyhyi/__init__.py` and commit.
|
|
14
|
+
2. Make sure CI is green on `main` (the `build` job builds every package).
|
|
15
|
+
3. Tag and push:
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
git tag vX.Y.Z
|
|
19
|
+
git push origin vX.Y.Z
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The `Release` workflow checks that the tag matches `__version__`, builds pyhyi
|
|
23
|
+
and the aliases, and publishes each package in its own job and environment
|
|
24
|
+
`pypi-<package>`. A failed publish job can be re-run from the Actions page.
|
|
25
|
+
|
|
26
|
+
## Trusted publisher settings
|
|
27
|
+
|
|
28
|
+
Each PyPI project needs one trusted publisher (for a project that does not exist
|
|
29
|
+
yet, add it as a *pending* publisher under *Account settings -> Publishing*):
|
|
30
|
+
|
|
31
|
+
| Field | Value |
|
|
32
|
+
| ----------------- | ------------------ |
|
|
33
|
+
| PyPI project name | package name |
|
|
34
|
+
| Owner | `marsik641` |
|
|
35
|
+
| Repository name | `pyhyi` |
|
|
36
|
+
| Workflow name | `release.yml` |
|
|
37
|
+
| Environment name | `pypi-<package>` |
|
|
38
|
+
|
|
39
|
+
A pending publisher does not reserve the name: the project is created by the
|
|
40
|
+
first successful upload.
|
|
41
|
+
|
|
42
|
+
## Adding an alias
|
|
43
|
+
|
|
44
|
+
Add the name to `ALIASES`, configure its trusted publisher as above, and
|
|
45
|
+
release a new version: an alias always carries the same version as pyhyi.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pyhyi"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Repository hygiene checker: catches the mess autonomous coding agents leave behind."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
dependencies = [
|
|
14
|
+
"tomli>=1.1; python_version < '3.11'",
|
|
15
|
+
]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 2 - Pre-Alpha",
|
|
18
|
+
"Environment :: Console",
|
|
19
|
+
"Intended Audience :: Developers",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Topic :: Software Development :: Quality Assurance",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
[project.urls]
|
|
25
|
+
Repository = "https://github.com/marsik641/pyhyi"
|
|
26
|
+
|
|
27
|
+
[project.scripts]
|
|
28
|
+
pyhyi = "pyhyi.cli:main"
|
|
29
|
+
|
|
30
|
+
[dependency-groups]
|
|
31
|
+
dev = [
|
|
32
|
+
"pytest>=8",
|
|
33
|
+
"pytest-github-actions-annotate-failures>=0.3",
|
|
34
|
+
"ruff>=0.8",
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
[tool.hatch.version]
|
|
38
|
+
path = "src/pyhyi/__init__.py"
|
|
39
|
+
|
|
40
|
+
[tool.pytest.ini_options]
|
|
41
|
+
testpaths = ["tests"]
|
|
42
|
+
addopts = "-ra"
|
|
43
|
+
|
|
44
|
+
[tool.pyhyi.per-path-ignores]
|
|
45
|
+
# Test fixtures and docs quote suppression markers on purpose.
|
|
46
|
+
"tests/**" = ["bad-suppression"]
|
|
47
|
+
"README.md" = ["bad-suppression"]
|
|
48
|
+
|
|
49
|
+
[tool.ruff]
|
|
50
|
+
line-length = 100
|
|
51
|
+
target-version = "py310"
|
|
52
|
+
|
|
53
|
+
[tool.ruff.lint]
|
|
54
|
+
select = ["E", "F", "W", "I", "UP", "B", "SIM", "RUF"]
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"""Build alias distributions that install pyhyi under other names.
|
|
2
|
+
|
|
3
|
+
Each alias is a metadata-only package that depends on the exact same pyhyi
|
|
4
|
+
version, so `pip install <alias>` installs pyhyi and nothing else.
|
|
5
|
+
|
|
6
|
+
Usage: python scripts/build_aliases.py [--out-dir dist]
|
|
7
|
+
Each alias lands in its own subdirectory: dist/<alias>/.
|
|
8
|
+
Requires `uv` on PATH.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import argparse
|
|
14
|
+
import re
|
|
15
|
+
import shutil
|
|
16
|
+
import subprocess
|
|
17
|
+
import tempfile
|
|
18
|
+
from collections.abc import Sequence
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
|
|
21
|
+
ROOT = Path(__file__).resolve().parent.parent
|
|
22
|
+
|
|
23
|
+
ALIASES = ("pyhui", "pyhuy", "pihui", "pihuy", "pyhuj", "pohuj")
|
|
24
|
+
|
|
25
|
+
PYPROJECT = """\
|
|
26
|
+
[build-system]
|
|
27
|
+
requires = ["hatchling>=1.27"]
|
|
28
|
+
build-backend = "hatchling.build"
|
|
29
|
+
|
|
30
|
+
[project]
|
|
31
|
+
name = "{name}"
|
|
32
|
+
version = "{version}"
|
|
33
|
+
description = "Alias of pyhyi, the repository hygiene checker. Installs pyhyi."
|
|
34
|
+
readme = "README.md"
|
|
35
|
+
license = "MIT"
|
|
36
|
+
license-files = ["LICENSE"]
|
|
37
|
+
requires-python = ">=3.10"
|
|
38
|
+
dependencies = ["pyhyi=={version}"]
|
|
39
|
+
|
|
40
|
+
[project.urls]
|
|
41
|
+
Repository = "https://github.com/marsik641/pyhyi"
|
|
42
|
+
Homepage = "https://pypi.org/project/pyhyi/"
|
|
43
|
+
|
|
44
|
+
[tool.hatch.build.targets.wheel]
|
|
45
|
+
bypass-selection = true
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
README = """\
|
|
49
|
+
# {name}
|
|
50
|
+
|
|
51
|
+
`{name}` is an alias of [pyhyi](https://pypi.org/project/pyhyi/), a repository
|
|
52
|
+
hygiene checker. Installing it installs `pyhyi` {version}; use the `pyhyi`
|
|
53
|
+
command:
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
pip install {name}
|
|
57
|
+
pyhyi check
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Prefer depending on `pyhyi` directly.
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def read_version() -> str:
|
|
65
|
+
text = (ROOT / "src" / "pyhyi" / "__init__.py").read_text(encoding="utf-8")
|
|
66
|
+
match = re.search(r'^__version__ = "([^"]+)"$', text, re.MULTILINE)
|
|
67
|
+
if match is None:
|
|
68
|
+
raise SystemExit("cannot find __version__ in src/pyhyi/__init__.py")
|
|
69
|
+
return match[1]
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def write_alias(name: str, version: str, parent: Path) -> Path:
|
|
73
|
+
"""Write the source tree of one alias package and return its directory."""
|
|
74
|
+
src = parent / name
|
|
75
|
+
src.mkdir(parents=True)
|
|
76
|
+
for filename, template in (("pyproject.toml", PYPROJECT), ("README.md", README)):
|
|
77
|
+
(src / filename).write_text(
|
|
78
|
+
template.format(name=name, version=version), encoding="utf-8", newline="\n"
|
|
79
|
+
)
|
|
80
|
+
shutil.copyfile(ROOT / "LICENSE", src / "LICENSE")
|
|
81
|
+
return src
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def main(argv: Sequence[str] | None = None) -> int:
|
|
85
|
+
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
|
86
|
+
parser.add_argument("--out-dir", default="dist", help="output directory (default: dist)")
|
|
87
|
+
args = parser.parse_args(argv)
|
|
88
|
+
out_dir = Path(args.out_dir).resolve()
|
|
89
|
+
version = read_version()
|
|
90
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
91
|
+
for name in ALIASES:
|
|
92
|
+
src = write_alias(name, version, Path(tmp))
|
|
93
|
+
subprocess.run(
|
|
94
|
+
["uv", "build", "--quiet", "--out-dir", str(out_dir / name), str(src)],
|
|
95
|
+
check=True,
|
|
96
|
+
)
|
|
97
|
+
print(f"built {name} {version} -> {out_dir / name}")
|
|
98
|
+
return 0
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
if __name__ == "__main__":
|
|
102
|
+
raise SystemExit(main())
|