rulepack 0.8.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.
@@ -0,0 +1,16 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ .venv/
6
+ .pytest_cache/
7
+ .ruff_cache/
8
+ .mypy_cache/
9
+ build/
10
+ dist/
11
+
12
+ # Tooling
13
+ .import_linter_cache/
14
+
15
+ # Local agent settings
16
+ .claude/settings.local.json
rulepack-0.8.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Matías Giménez
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.
@@ -0,0 +1,188 @@
1
+ Metadata-Version: 2.5
2
+ Name: rulepack
3
+ Version: 0.8.0
4
+ Summary: Run ast-grep and import-linter checks from shared, versioned rule packs in any repo.
5
+ Project-URL: repository, https://github.com/justmatias/rulepack
6
+ Author-email: Matias Gimenez <matiasgimenez.dev@gmail.com>
7
+ License: MIT
8
+ License-File: LICENSE
9
+ Requires-Python: >=3.12
10
+ Requires-Dist: ast-grep-cli>=0.51
11
+ Requires-Dist: import-linter>=2.17
12
+ Requires-Dist: pydantic>=2
13
+ Requires-Dist: pyyaml>=6
14
+ Description-Content-Type: text/markdown
15
+
16
+ # rulepack
17
+
18
+ Run ast-grep and import-linter checks from shared, versioned rule packs in any repo.
19
+
20
+ **Status: no shared packs yet.** `rulepack` runs a repo's own checks: ast-grep rule tests and scans, and import-linter contracts, from the CLI, pre-commit, GitHub Actions and agent hooks. Loading packs from other repos is planned in [pack-sources](docs/specs/pack-sources.md). Repos that select mstack's bundled packs (`packs = [...]` in `.mstack.toml`) stay on mstack `v6.x` until then.
21
+
22
+ ## Why
23
+
24
+ Agents write more of the code now, and reviewing it means correcting the same preferences again and again: a naming habit, a test layout, an import boundary. If an agent writes the code and you review it, it should write the code the way you would.
25
+
26
+ Prose rules in Markdown help, but an agent follows them only some of the time. rulepack turns those preferences into static, deterministic checks wherever a check can express them, so a broken rule fails the same way every time and the agent fixes it before you see the diff. Packs make the rules portable: write them once, version them, and select them from any repo.
27
+
28
+ ## Install
29
+
30
+ You need [`uv`](https://docs.astral.sh/uv/). Once the first release is available on [PyPI](https://pypi.org/project/rulepack/), install the CLI with:
31
+
32
+ ```bash
33
+ uv tool install rulepack
34
+ ```
35
+
36
+ To run it without installing:
37
+
38
+ ```bash
39
+ uvx rulepack --version
40
+ ```
41
+
42
+ Until the first PyPI release is available, install from the GitHub release tag:
43
+
44
+ ```bash
45
+ uv tool install git+https://github.com/justmatias/rulepack@v0.8.0
46
+ ```
47
+
48
+ Or run it without installing:
49
+
50
+ ```bash
51
+ uvx --from git+https://github.com/justmatias/rulepack@v0.8.0 rulepack --version
52
+ ```
53
+
54
+ ## Usage
55
+
56
+ Scaffold the layout in a repo, then lint it:
57
+
58
+ ```bash
59
+ rulepack init --pre-commit --ci github --poe # shows the plan and asks first
60
+ rulepack lint
61
+ ```
62
+
63
+ | Command | What it does |
64
+ | --- | --- |
65
+ | `rulepack init` | Writes `.rulepack.toml`, and with `--checks-dir DIR` an ast-grep sgconfig with empty `rules/` and `rule-tests/` for the repo's own checks. `--pre-commit`, `--ci github` and `--poe` add the hooks, the workflow and the poe tasks (in `pyproject.toml`, or `poe_tasks.toml` when there is none). It shows the plan, asks first (`--yes` skips, `--dry-run` writes nothing) and never overwrites a file, so a second run changes nothing. |
66
+ | `rulepack lint` | Runs the checks below. |
67
+ | `rulepack config` | Prints the resolved config and where each value comes from (`--json` for JSON). |
68
+ | `rulepack hook post-edit`, `rulepack hook stop` | Agent hooks (below). |
69
+
70
+ ### `rulepack lint`
71
+
72
+ ```text
73
+ rulepack lint [--changed [--base-ref REF] [--staged] | --files FILE ...]
74
+ [--only STEP ...] [--skip STEP ...] [--json]
75
+ ```
76
+
77
+ | Step | Runs | Skipped when |
78
+ | --- | --- | --- |
79
+ | `test` | `ast-grep test -c <sgconfig> --skip-snapshot-tests` | there is no sgconfig at the default path, or its `testConfigs` hold no test files |
80
+ | `scan` | `ast-grep scan -c <sgconfig>`, skipping the `[scan].exclude` globs | there is no sgconfig at the default path, or `--changed` or `--files` selected no file |
81
+ | `imports` | `lint-imports` | there is no `.importlinter` (the configured `importlinter`) |
82
+
83
+ - **Modes.** By default the scan covers the whole repo and warnings don't fail. `--changed` scans only the files changed against `[changed].base_ref` (`--base-ref` overrides it, `--staged` uses the staged files) and passes `--error`, so warnings fail on new or touched code. `--files` scans exactly the given files with `--error` (for pre-commit).
84
+ - **All steps run**, even after a failure. The exit code is 1 if any failed, 2 for a usage, config or git error. `--json` prints `{step: {ok, skipped, findings}}`.
85
+ - **Tools.** ast-grep and lint-imports come from the environment rulepack runs in. A repo whose `uv.lock` lists import-linter runs its own (`uv run --frozen lint-imports`), because the contracts need the project importable.
86
+
87
+ ### Configuration
88
+
89
+ Every command reads an optional `.rulepack.toml`, found by walking up from the current directory to the git root. A flag wins over the file, and the file over the defaults. Paths are relative to the file. Unknown keys are an error. rulepack ignores `.mstack.toml`.
90
+
91
+ ```toml
92
+ sgconfig = "lint/sgconfig.yml" # ast-grep config; a missing default means no local checks
93
+ importlinter = ".importlinter" # optional; skipped when missing
94
+
95
+ [scan]
96
+ exclude = [] # globs every scan skips
97
+ extensions = [".py"] # what --changed, --files and the hooks scan
98
+
99
+ [hooks]
100
+ enabled = true
101
+ timeout = 10.0 # seconds per agent hook run
102
+
103
+ [changed]
104
+ base_ref = "origin/main"
105
+ ```
106
+
107
+ ### pre-commit
108
+
109
+ ```yaml
110
+ repos:
111
+ - repo: https://github.com/justmatias/rulepack
112
+ rev: vX.Y.Z # a release tag
113
+ hooks:
114
+ - id: rulepack-lint # ast-grep scan of the staged files; warnings fail too
115
+ - id: rulepack-rules # rule tests, when a rule or its test changes
116
+ - id: rulepack-imports # .importlinter contracts
117
+ ```
118
+
119
+ `rulepack-imports` needs the project importable: list its third-party packages under the hook's `additional_dependencies`, or run `rulepack lint --only imports` from the project's environment instead.
120
+
121
+ ### GitHub Actions
122
+
123
+ The action runs the full scan, and on pull requests also the changed-files scan, where warnings fail. Check out with the full history so the base branch exists:
124
+
125
+ ```yaml
126
+ steps:
127
+ - uses: actions/checkout@v7
128
+ with:
129
+ fetch-depth: 0
130
+ - uses: justmatias/rulepack@v0.8.0
131
+ ```
132
+
133
+ Inputs: `mode` (`full`, `changed` or `both`), `base-ref`, `rulepack-version`, `python-version` and `working-directory`. Every release moves the `v<major>` tag. On other CI providers, run `uvx --from git+https://github.com/justmatias/rulepack@<tag> rulepack lint`, and on merge requests the same with `--changed --base-ref origin/<base branch>`.
134
+
135
+ ### Agent hooks
136
+
137
+ `rulepack hook post-edit` and `rulepack hook stop` read a Claude Code, Codex or Cursor hook payload on stdin. They run only in repos with `.rulepack.toml`. Post-edit scans the edited files; stop scans the changed files, and reports the same findings only once per session. A run that times out or fails logs a warning and lets the agent continue. Set `[hooks] enabled = false` to turn them off for a repo.
138
+
139
+ ## Development
140
+
141
+ ```bash
142
+ uv sync # dev dependencies
143
+ uv run pre-commit install # installs the pre-commit and the commit-msg hooks
144
+ uv run poe lint # every pre-commit hook on every file
145
+ uv run poe test # pytest
146
+ ```
147
+
148
+ Planned work lives in [`docs/specs/`](docs/specs/README.md).
149
+
150
+ ## Releasing
151
+
152
+ Pull requests are squash-merged, so the PR title becomes the commit on `main` and decides the bump: `feat` is a minor bump, `fix` and `perf` a patch, and `!` a major bump once past `1.0` (during `0.x` it bumps the minor version). Other types release nothing.
153
+
154
+ `release-prepare.yml` commits the bump, `CHANGELOG.md`, `uv.lock` and the tags in this README to the PR branch, so the release is reviewed with the change. After the merge, the `versioning` job in `ci.yml` tags the version, creates the GitHub release and moves the `v<major>` tag.
155
+
156
+ ## Maintaining
157
+
158
+ GitHub settings, applied with `gh`:
159
+
160
+ - **Public**, so branch rulesets work on the free plan and consumers can install the CLI and its hooks without a token.
161
+ - **Squash merge only.** The squash commit title is the PR title (`COMMIT_OR_PR_TITLE`), and head branches are deleted on merge:
162
+
163
+ ```bash
164
+ gh api -X PATCH repos/justmatias/rulepack \
165
+ -F allow_squash_merge=true -F allow_merge_commit=false -F allow_rebase_merge=false \
166
+ -f squash_merge_commit_title=COMMIT_OR_PR_TITLE -f squash_merge_commit_message=COMMIT_MESSAGES \
167
+ -F delete_branch_on_merge=true
168
+ ```
169
+
170
+ - **A `main` ruleset**: no deletion, no force push, and changes only through a pull request merged with squash:
171
+
172
+ ```bash
173
+ gh api -X POST repos/justmatias/rulepack/rulesets --input - <<'EOF'
174
+ {"name": "main", "target": "branch", "enforcement": "active",
175
+ "conditions": {"ref_name": {"include": ["refs/heads/main"], "exclude": []}},
176
+ "rules": [{"type": "deletion"}, {"type": "non_fast_forward"},
177
+ {"type": "pull_request", "parameters": {"allowed_merge_methods": ["squash"],
178
+ "required_approving_review_count": 0, "dismiss_stale_reviews_on_push": false,
179
+ "require_code_owner_review": false, "require_last_push_approval": false,
180
+ "required_review_thread_resolution": false}}]}
181
+ EOF
182
+ ```
183
+
184
+ - **A `GH_TOKEN` secret**: a fine-grained token with contents write access on this repo only. `release-prepare.yml` and `pre-commit-autoupdate.yml` push with it, because a push made with `GITHUB_TOKEN` does not start CI on the pushed commit.
185
+
186
+ ## License
187
+
188
+ MIT. See [LICENSE](LICENSE).
@@ -0,0 +1,173 @@
1
+ # rulepack
2
+
3
+ Run ast-grep and import-linter checks from shared, versioned rule packs in any repo.
4
+
5
+ **Status: no shared packs yet.** `rulepack` runs a repo's own checks: ast-grep rule tests and scans, and import-linter contracts, from the CLI, pre-commit, GitHub Actions and agent hooks. Loading packs from other repos is planned in [pack-sources](docs/specs/pack-sources.md). Repos that select mstack's bundled packs (`packs = [...]` in `.mstack.toml`) stay on mstack `v6.x` until then.
6
+
7
+ ## Why
8
+
9
+ Agents write more of the code now, and reviewing it means correcting the same preferences again and again: a naming habit, a test layout, an import boundary. If an agent writes the code and you review it, it should write the code the way you would.
10
+
11
+ Prose rules in Markdown help, but an agent follows them only some of the time. rulepack turns those preferences into static, deterministic checks wherever a check can express them, so a broken rule fails the same way every time and the agent fixes it before you see the diff. Packs make the rules portable: write them once, version them, and select them from any repo.
12
+
13
+ ## Install
14
+
15
+ You need [`uv`](https://docs.astral.sh/uv/). Once the first release is available on [PyPI](https://pypi.org/project/rulepack/), install the CLI with:
16
+
17
+ ```bash
18
+ uv tool install rulepack
19
+ ```
20
+
21
+ To run it without installing:
22
+
23
+ ```bash
24
+ uvx rulepack --version
25
+ ```
26
+
27
+ Until the first PyPI release is available, install from the GitHub release tag:
28
+
29
+ ```bash
30
+ uv tool install git+https://github.com/justmatias/rulepack@v0.8.0
31
+ ```
32
+
33
+ Or run it without installing:
34
+
35
+ ```bash
36
+ uvx --from git+https://github.com/justmatias/rulepack@v0.8.0 rulepack --version
37
+ ```
38
+
39
+ ## Usage
40
+
41
+ Scaffold the layout in a repo, then lint it:
42
+
43
+ ```bash
44
+ rulepack init --pre-commit --ci github --poe # shows the plan and asks first
45
+ rulepack lint
46
+ ```
47
+
48
+ | Command | What it does |
49
+ | --- | --- |
50
+ | `rulepack init` | Writes `.rulepack.toml`, and with `--checks-dir DIR` an ast-grep sgconfig with empty `rules/` and `rule-tests/` for the repo's own checks. `--pre-commit`, `--ci github` and `--poe` add the hooks, the workflow and the poe tasks (in `pyproject.toml`, or `poe_tasks.toml` when there is none). It shows the plan, asks first (`--yes` skips, `--dry-run` writes nothing) and never overwrites a file, so a second run changes nothing. |
51
+ | `rulepack lint` | Runs the checks below. |
52
+ | `rulepack config` | Prints the resolved config and where each value comes from (`--json` for JSON). |
53
+ | `rulepack hook post-edit`, `rulepack hook stop` | Agent hooks (below). |
54
+
55
+ ### `rulepack lint`
56
+
57
+ ```text
58
+ rulepack lint [--changed [--base-ref REF] [--staged] | --files FILE ...]
59
+ [--only STEP ...] [--skip STEP ...] [--json]
60
+ ```
61
+
62
+ | Step | Runs | Skipped when |
63
+ | --- | --- | --- |
64
+ | `test` | `ast-grep test -c <sgconfig> --skip-snapshot-tests` | there is no sgconfig at the default path, or its `testConfigs` hold no test files |
65
+ | `scan` | `ast-grep scan -c <sgconfig>`, skipping the `[scan].exclude` globs | there is no sgconfig at the default path, or `--changed` or `--files` selected no file |
66
+ | `imports` | `lint-imports` | there is no `.importlinter` (the configured `importlinter`) |
67
+
68
+ - **Modes.** By default the scan covers the whole repo and warnings don't fail. `--changed` scans only the files changed against `[changed].base_ref` (`--base-ref` overrides it, `--staged` uses the staged files) and passes `--error`, so warnings fail on new or touched code. `--files` scans exactly the given files with `--error` (for pre-commit).
69
+ - **All steps run**, even after a failure. The exit code is 1 if any failed, 2 for a usage, config or git error. `--json` prints `{step: {ok, skipped, findings}}`.
70
+ - **Tools.** ast-grep and lint-imports come from the environment rulepack runs in. A repo whose `uv.lock` lists import-linter runs its own (`uv run --frozen lint-imports`), because the contracts need the project importable.
71
+
72
+ ### Configuration
73
+
74
+ Every command reads an optional `.rulepack.toml`, found by walking up from the current directory to the git root. A flag wins over the file, and the file over the defaults. Paths are relative to the file. Unknown keys are an error. rulepack ignores `.mstack.toml`.
75
+
76
+ ```toml
77
+ sgconfig = "lint/sgconfig.yml" # ast-grep config; a missing default means no local checks
78
+ importlinter = ".importlinter" # optional; skipped when missing
79
+
80
+ [scan]
81
+ exclude = [] # globs every scan skips
82
+ extensions = [".py"] # what --changed, --files and the hooks scan
83
+
84
+ [hooks]
85
+ enabled = true
86
+ timeout = 10.0 # seconds per agent hook run
87
+
88
+ [changed]
89
+ base_ref = "origin/main"
90
+ ```
91
+
92
+ ### pre-commit
93
+
94
+ ```yaml
95
+ repos:
96
+ - repo: https://github.com/justmatias/rulepack
97
+ rev: vX.Y.Z # a release tag
98
+ hooks:
99
+ - id: rulepack-lint # ast-grep scan of the staged files; warnings fail too
100
+ - id: rulepack-rules # rule tests, when a rule or its test changes
101
+ - id: rulepack-imports # .importlinter contracts
102
+ ```
103
+
104
+ `rulepack-imports` needs the project importable: list its third-party packages under the hook's `additional_dependencies`, or run `rulepack lint --only imports` from the project's environment instead.
105
+
106
+ ### GitHub Actions
107
+
108
+ The action runs the full scan, and on pull requests also the changed-files scan, where warnings fail. Check out with the full history so the base branch exists:
109
+
110
+ ```yaml
111
+ steps:
112
+ - uses: actions/checkout@v7
113
+ with:
114
+ fetch-depth: 0
115
+ - uses: justmatias/rulepack@v0.8.0
116
+ ```
117
+
118
+ Inputs: `mode` (`full`, `changed` or `both`), `base-ref`, `rulepack-version`, `python-version` and `working-directory`. Every release moves the `v<major>` tag. On other CI providers, run `uvx --from git+https://github.com/justmatias/rulepack@<tag> rulepack lint`, and on merge requests the same with `--changed --base-ref origin/<base branch>`.
119
+
120
+ ### Agent hooks
121
+
122
+ `rulepack hook post-edit` and `rulepack hook stop` read a Claude Code, Codex or Cursor hook payload on stdin. They run only in repos with `.rulepack.toml`. Post-edit scans the edited files; stop scans the changed files, and reports the same findings only once per session. A run that times out or fails logs a warning and lets the agent continue. Set `[hooks] enabled = false` to turn them off for a repo.
123
+
124
+ ## Development
125
+
126
+ ```bash
127
+ uv sync # dev dependencies
128
+ uv run pre-commit install # installs the pre-commit and the commit-msg hooks
129
+ uv run poe lint # every pre-commit hook on every file
130
+ uv run poe test # pytest
131
+ ```
132
+
133
+ Planned work lives in [`docs/specs/`](docs/specs/README.md).
134
+
135
+ ## Releasing
136
+
137
+ Pull requests are squash-merged, so the PR title becomes the commit on `main` and decides the bump: `feat` is a minor bump, `fix` and `perf` a patch, and `!` a major bump once past `1.0` (during `0.x` it bumps the minor version). Other types release nothing.
138
+
139
+ `release-prepare.yml` commits the bump, `CHANGELOG.md`, `uv.lock` and the tags in this README to the PR branch, so the release is reviewed with the change. After the merge, the `versioning` job in `ci.yml` tags the version, creates the GitHub release and moves the `v<major>` tag.
140
+
141
+ ## Maintaining
142
+
143
+ GitHub settings, applied with `gh`:
144
+
145
+ - **Public**, so branch rulesets work on the free plan and consumers can install the CLI and its hooks without a token.
146
+ - **Squash merge only.** The squash commit title is the PR title (`COMMIT_OR_PR_TITLE`), and head branches are deleted on merge:
147
+
148
+ ```bash
149
+ gh api -X PATCH repos/justmatias/rulepack \
150
+ -F allow_squash_merge=true -F allow_merge_commit=false -F allow_rebase_merge=false \
151
+ -f squash_merge_commit_title=COMMIT_OR_PR_TITLE -f squash_merge_commit_message=COMMIT_MESSAGES \
152
+ -F delete_branch_on_merge=true
153
+ ```
154
+
155
+ - **A `main` ruleset**: no deletion, no force push, and changes only through a pull request merged with squash:
156
+
157
+ ```bash
158
+ gh api -X POST repos/justmatias/rulepack/rulesets --input - <<'EOF'
159
+ {"name": "main", "target": "branch", "enforcement": "active",
160
+ "conditions": {"ref_name": {"include": ["refs/heads/main"], "exclude": []}},
161
+ "rules": [{"type": "deletion"}, {"type": "non_fast_forward"},
162
+ {"type": "pull_request", "parameters": {"allowed_merge_methods": ["squash"],
163
+ "required_approving_review_count": 0, "dismiss_stale_reviews_on_push": false,
164
+ "require_code_owner_review": false, "require_last_push_approval": false,
165
+ "required_review_thread_resolution": false}}]}
166
+ EOF
167
+ ```
168
+
169
+ - **A `GH_TOKEN` secret**: a fine-grained token with contents write access on this repo only. `release-prepare.yml` and `pre-commit-autoupdate.yml` push with it, because a push made with `GITHUB_TOKEN` does not start CI on the pushed commit.
170
+
171
+ ## License
172
+
173
+ MIT. See [LICENSE](LICENSE).
@@ -0,0 +1,166 @@
1
+ [project]
2
+ name = "rulepack"
3
+ version = "0.8.0"
4
+ description = "Run ast-grep and import-linter checks from shared, versioned rule packs in any repo."
5
+ readme = "README.md"
6
+ license = { text = "MIT" }
7
+ authors = [
8
+ { name = "Matias Gimenez", email = "matiasgimenez.dev@gmail.com" },
9
+ ]
10
+ requires-python = ">=3.12"
11
+ # ast-grep and import-linter ship with the CLI, so `rulepack lint` works in any repo.
12
+ dependencies = [
13
+ "ast-grep-cli>=0.51",
14
+ "import-linter>=2.17",
15
+ "pydantic>=2",
16
+ "pyyaml>=6",
17
+ ]
18
+
19
+ [project.scripts]
20
+ rulepack = "rulepack.cli:main"
21
+
22
+ [project.urls]
23
+ repository = "https://github.com/justmatias/rulepack"
24
+
25
+ [dependency-groups]
26
+ dev = [
27
+ "poethepoet>=0.49.0",
28
+ "pre-commit>=4",
29
+ "pytest",
30
+ "types-pyyaml",
31
+ ]
32
+
33
+ [build-system]
34
+ requires = ["hatchling>=1.27,<2"]
35
+ build-backend = "hatchling.build"
36
+
37
+ [tool.hatch.build.targets.wheel]
38
+ packages = ["rulepack"]
39
+
40
+ [tool.hatch.build.targets.sdist]
41
+ include = [
42
+ "/rulepack",
43
+ "/LICENSE",
44
+ "/README.md",
45
+ "/pyproject.toml",
46
+ ]
47
+
48
+ [tool.poe.tasks]
49
+ lint = { cmd = "pre-commit run --all-files", help = "Every pre-commit hook on every file" }
50
+ test = { cmd = "pytest -q", help = "pytest, skipping the slow tests" }
51
+
52
+ [tool.pytest.ini_options]
53
+ testpaths = ["tests"]
54
+ # Slow tests install rulepack from scratch (pre-commit try-repo); CI runs them with -m slow.
55
+ markers = ["slow: installs packages; run with -m slow"]
56
+ addopts = "-m 'not slow'"
57
+ # tests/fixtures/ holds a sample repo for the checks (some files break them on purpose).
58
+ norecursedirs = ["tests/fixtures"]
59
+
60
+ ##################################
61
+ # ruff configuration #
62
+ ##################################
63
+
64
+ [tool.ruff]
65
+ line-length = 88
66
+ # tests/fixtures/ holds a sample repo with deliberate violations for the checks to catch.
67
+ extend-exclude = ["tests/fixtures"]
68
+ preview = true
69
+ fix = true
70
+ # T20: no print() left in code; use logging.
71
+ lint.extend-select = ["T20"]
72
+ format.indent-style = "space"
73
+ format.quote-style = "double"
74
+ format.line-ending = "auto"
75
+ format.skip-magic-trailing-comma = false
76
+
77
+ ##################################
78
+ # pylint configuration #
79
+ ##################################
80
+
81
+ [tool.pylint]
82
+ ignore-paths = ["^tests/fixtures/.*$"]
83
+ disable = [
84
+ "missing-docstring",
85
+ "missing-module-docstring",
86
+ "missing-function-docstring",
87
+ "too-few-public-methods",
88
+ "astroid-error",
89
+ "consider-using-assignment-expr",
90
+ "redefined-outer-name",
91
+ "broad-exception-caught",
92
+ "import-error",
93
+ ]
94
+
95
+ load-plugins = [
96
+ "pylint.extensions.bad_builtin",
97
+ "pylint.extensions.code_style",
98
+ "pylint.extensions.comparison_placement",
99
+ "pylint.extensions.consider_refactoring_into_while_condition",
100
+ "pylint.extensions.dunder",
101
+ "pylint.extensions.eq_without_hash",
102
+ "pylint.extensions.for_any_all",
103
+ "pylint.extensions.mccabe",
104
+ "pylint.extensions.no_self_use",
105
+ "pylint.extensions.overlapping_exceptions",
106
+ "pylint.extensions.private_import",
107
+ "pylint.extensions.redefined_loop_name",
108
+ "pylint.extensions.set_membership",
109
+ ]
110
+
111
+ ##################################
112
+ # mypy configuration #
113
+ ##################################
114
+
115
+ [tool.mypy]
116
+ python_version = "3.12"
117
+ exclude = ["^tests/fixtures/"]
118
+ disallow_untyped_defs = true
119
+ show_error_codes = true
120
+ no_implicit_optional = true
121
+ warn_return_any = true
122
+ warn_unused_ignores = true
123
+ disable_error_code = ["var-annotated"]
124
+
125
+ # Tests take pytest fixtures as parameters; annotating each one adds noise.
126
+ [[tool.mypy.overrides]]
127
+ module = ["tests.*"]
128
+ disallow_untyped_defs = false
129
+ warn_return_any = false
130
+
131
+ ##################################
132
+ # semantic release configuration #
133
+ ##################################
134
+
135
+ [tool.semantic_release]
136
+ branch = "main"
137
+ commit_message = "chore(release): release version {version}"
138
+ major_on_zero = false
139
+ version_toml = ["pyproject.toml:project.version"]
140
+ # The install commands in README.md pin `rulepack@v<version>`.
141
+ version_variables = ["README.md:rulepack:tf"]
142
+ build_command = "uv lock --upgrade-package rulepack && git add uv.lock"
143
+
144
+ [tool.semantic_release.branches.main]
145
+ match = "(main|master)"
146
+ prerelease_token = "rc"
147
+ prerelease = false
148
+
149
+ [tool.semantic_release.changelog.default_templates]
150
+ changelog_file = "CHANGELOG.md"
151
+
152
+ [tool.semantic_release.commit_author]
153
+ env = "GIT_COMMIT_AUTHOR"
154
+ default = "semantic-release <semantic-release>"
155
+
156
+ [tool.semantic_release.commit_parser_options]
157
+ allowed_tags = ["build", "chore", "ci", "docs", "feat", "fix", "perf", "refactor", "style", "test"]
158
+ minor_tags = ["feat"]
159
+ patch_tags = ["fix", "perf"]
160
+ default_bump_level = 0
161
+
162
+ [tool.semantic_release.remote]
163
+ name = "origin"
164
+ type = "github"
165
+ ignore_token_for_push = false
166
+ insecure = false
File without changes
@@ -0,0 +1,5 @@
1
+ import sys
2
+
3
+ from rulepack.cli import main
4
+
5
+ sys.exit(main())
@@ -0,0 +1,40 @@
1
+ import argparse
2
+ import importlib
3
+ import importlib.metadata
4
+ import logging
5
+ import sys
6
+
7
+ logger = logging.getLogger(__name__)
8
+
9
+ COMMANDS = {
10
+ "config": "rulepack.config.command",
11
+ "hook": "rulepack.hook.command",
12
+ "init": "rulepack.init.command",
13
+ "lint": "rulepack.lint.command",
14
+ }
15
+
16
+
17
+ def main(argv: list[str] | None = None) -> int:
18
+ arguments = sys.argv[1:] if argv is None else argv
19
+ logging.basicConfig(level=logging.INFO, format="%(message)s")
20
+ parser = argparse.ArgumentParser(
21
+ prog="rulepack",
22
+ description=(
23
+ "Run ast-grep and import-linter checks from shared, versioned rule packs."
24
+ ),
25
+ epilog="Run 'rulepack <command> --help' for what each command does.",
26
+ )
27
+ parser.add_argument(
28
+ "--version",
29
+ action="version",
30
+ version=f"rulepack {importlib.metadata.version('rulepack')}",
31
+ )
32
+ parser.add_argument("command", choices=COMMANDS)
33
+ parsed = parser.parse_args(arguments[:1])
34
+ command = importlib.import_module(COMMANDS[parsed.command])
35
+ config = importlib.import_module("rulepack.config")
36
+ try:
37
+ return int(command.main(arguments[1:]))
38
+ except config.ConfigError as error:
39
+ logger.error("rulepack: %s", error)
40
+ return 2
@@ -0,0 +1,12 @@
1
+ from rulepack.config.project_paths import CONFIG_FILE_NAME
2
+ from rulepack.config.resolve import ConfigError, resolve_config
3
+ from rulepack.config.settings import ProjectConfig, ResolvedConfig, StrictModel
4
+
5
+ __all__ = [
6
+ "CONFIG_FILE_NAME",
7
+ "ConfigError",
8
+ "ProjectConfig",
9
+ "ResolvedConfig",
10
+ "StrictModel",
11
+ "resolve_config",
12
+ ]