matchify 0.0.1__tar.gz → 0.2.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.
- {matchify-0.0.1 → matchify-0.2.0}/.copier-answers.yml +7 -3
- matchify-0.2.0/.copier-enforce.json +5 -0
- {matchify-0.0.1 → matchify-0.2.0}/.github/actions/setup/action.yml +0 -1
- matchify-0.2.0/.github/workflows/ci.yml +211 -0
- matchify-0.2.0/.github/workflows/release-pr.yml +53 -0
- matchify-0.2.0/.github/workflows/weekly.yml +45 -0
- {matchify-0.0.1 → matchify-0.2.0}/.gitignore +0 -1
- {matchify-0.0.1 → matchify-0.2.0}/.pre-commit-config.yaml +10 -1
- matchify-0.2.0/.pre-commit-hooks.yaml +12 -0
- matchify-0.2.0/CHANGELOG.md +72 -0
- {matchify-0.0.1 → matchify-0.2.0}/CONTRIBUTING.md +5 -0
- matchify-0.2.0/COPIER_TEMPLATE_CHANGES.md +151 -0
- matchify-0.2.0/LICENSE +21 -0
- {matchify-0.0.1 → matchify-0.2.0}/PKG-INFO +271 -81
- matchify-0.2.0/README.md +414 -0
- matchify-0.2.0/changelog.d/.gitignore +1 -0
- {matchify-0.0.1 → matchify-0.2.0}/find_new_issue_2.py +3 -1
- {matchify-0.0.1 → matchify-0.2.0}/pyproject.toml +30 -11
- {matchify-0.0.1 → matchify-0.2.0}/src/matchify/__init__.py +2 -0
- {matchify-0.0.1 → matchify-0.2.0}/src/matchify/access_path.py +56 -20
- {matchify-0.0.1 → matchify-0.2.0}/src/matchify/assumptions.py +37 -2
- {matchify-0.0.1 → matchify-0.2.0}/src/matchify/cli.py +22 -6
- {matchify-0.0.1 → matchify-0.2.0}/src/matchify/compiler.py +9 -8
- {matchify-0.0.1 → matchify-0.2.0}/src/matchify/conditions.py +69 -28
- {matchify-0.0.1 → matchify-0.2.0}/src/matchify/facts.py +30 -29
- matchify-0.2.0/src/matchify/lookup_tables.py +263 -0
- {matchify-0.0.1 → matchify-0.2.0}/src/matchify/pattern_builder.py +70 -37
- {matchify-0.0.1 → matchify-0.2.0}/src/matchify/patterns.py +4 -10
- {matchify-0.0.1 → matchify-0.2.0}/src/matchify/safety.py +7 -1
- {matchify-0.0.1 → matchify-0.2.0}/src/matchify/transform.py +39 -2
- {matchify-0.0.1 → matchify-0.2.0}/tests/test_access_path.py +20 -1
- {matchify-0.0.1 → matchify-0.2.0}/tests/test_cli.py +192 -3
- {matchify-0.0.1 → matchify-0.2.0}/tests/test_edge_cases.py +21 -0
- {matchify-0.0.1 → matchify-0.2.0}/tests/test_find_new_issue_2.py +1 -3
- {matchify-0.0.1 → matchify-0.2.0}/tests/test_generated_roundtrip.py +26 -0
- matchify-0.2.0/tests/test_lookup_tables.py +284 -0
- matchify-0.2.0/tests/test_public_coverage.py +359 -0
- {matchify-0.0.1 → matchify-0.2.0}/tests/test_readme.py +22 -1
- matchify-0.2.0/tests/test_sequence_assumptions.py +101 -0
- {matchify-0.0.1 → matchify-0.2.0}/tests/test_transform.py +177 -12
- matchify-0.2.0/uv.lock +1097 -0
- matchify-0.0.1/.github/workflows/ci.yml +0 -156
- matchify-0.0.1/README.md +0 -225
- {matchify-0.0.1 → matchify-0.2.0}/.github/FUNDING.yml +0 -0
- {matchify-0.0.1 → matchify-0.2.0}/.github/pull_request_template.md +0 -0
- {matchify-0.0.1 → matchify-0.2.0}/AGENTS.md +0 -0
- {matchify-0.0.1 → matchify-0.2.0}/design.md +0 -0
- {matchify-0.0.1 → matchify-0.2.0}/find_new_issue.py +0 -0
- {matchify-0.0.1 → matchify-0.2.0}/limitations.md +0 -0
- {matchify-0.0.1 → matchify-0.2.0}/src/matchify/__main__.py +0 -0
- {matchify-0.0.1 → matchify-0.2.0}/src/matchify/capture_patterns.py +0 -0
- {matchify-0.0.1 → matchify-0.2.0}/test-repos.json +0 -0
- {matchify-0.0.1 → matchify-0.2.0}/test-repos.py +0 -0
- {matchify-0.0.1 → matchify-0.2.0}/tests/helpers.py +0 -0
- {matchify-0.0.1 → matchify-0.2.0}/tests/samples/.gitkeep +0 -0
- {matchify-0.0.1 → matchify-0.2.0}/tests/test_guard_rendering.py +0 -0
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
# Changes here will be overwritten by Copier
|
|
2
|
-
_commit: v0.
|
|
3
|
-
_src_path:
|
|
2
|
+
_commit: v0.3.2
|
|
3
|
+
_src_path: https://github.com/15r10nk/project-template.git
|
|
4
|
+
author_email: 15r10nk@polarbit.de
|
|
5
|
+
author_name: Frank Hoffmann
|
|
6
|
+
discord_id: ''
|
|
7
|
+
discord_invite_id: ''
|
|
4
8
|
full_coverage: false
|
|
5
9
|
github_user: 15r10nk
|
|
6
10
|
insider_only: false
|
|
@@ -9,7 +13,7 @@ project_description: converts if-else code to match statements
|
|
|
9
13
|
project_main: true
|
|
10
14
|
project_name: matchify
|
|
11
15
|
pypy_versions:
|
|
12
|
-
- pypy3.
|
|
16
|
+
- pypy3.11
|
|
13
17
|
python_versions:
|
|
14
18
|
- '3.10'
|
|
15
19
|
- '3.11'
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
push:
|
|
6
|
+
branches: [main]
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
|
|
10
|
+
detect_release:
|
|
11
|
+
|
|
12
|
+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
permissions:
|
|
15
|
+
contents: read
|
|
16
|
+
pull-requests: read
|
|
17
|
+
outputs:
|
|
18
|
+
is_release: ${{steps.release.outputs.is_release}}
|
|
19
|
+
tag: ${{steps.release.outputs.tag}}
|
|
20
|
+
|
|
21
|
+
steps:
|
|
22
|
+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
|
23
|
+
|
|
24
|
+
- name: Detect merged release pull request
|
|
25
|
+
id: release
|
|
26
|
+
env:
|
|
27
|
+
GH_TOKEN: ${{github.token}}
|
|
28
|
+
run: |
|
|
29
|
+
version="$(python -c 'import tomllib; print(tomllib.load(open("pyproject.toml", "rb"))["project"]["version"])')"
|
|
30
|
+
release_branch="$(
|
|
31
|
+
gh api "repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/pulls" \
|
|
32
|
+
--jq '[.[] | select(.merged_at != null and .base.ref == "main" and (.head.ref | startswith("release/v")))][0].head.ref // ""'
|
|
33
|
+
)"
|
|
34
|
+
if test "$release_branch" = "release/v$version"; then
|
|
35
|
+
echo "is_release=true" >> "$GITHUB_OUTPUT"
|
|
36
|
+
echo "tag=v$version" >> "$GITHUB_OUTPUT"
|
|
37
|
+
else
|
|
38
|
+
echo "is_release=false" >> "$GITHUB_OUTPUT"
|
|
39
|
+
fi
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
test:
|
|
43
|
+
|
|
44
|
+
runs-on: ${{matrix.os}}
|
|
45
|
+
|
|
46
|
+
strategy:
|
|
47
|
+
matrix:
|
|
48
|
+
python-version: ['3.10', '3.11', '3.12', '3.13', '3.14', pypy3.11]
|
|
49
|
+
|
|
50
|
+
os: [ubuntu-latest, windows-latest, macos-15]
|
|
51
|
+
lowest_resolution: [false]
|
|
52
|
+
is_insider:
|
|
53
|
+
- ${{contains(github.repository, '-insiders/')}}
|
|
54
|
+
|
|
55
|
+
exclude:
|
|
56
|
+
- is_insider: true
|
|
57
|
+
os: windows-latest
|
|
58
|
+
- is_insider: true
|
|
59
|
+
os: macos-15
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
- os: macos-15
|
|
63
|
+
python-version: '3.11'
|
|
64
|
+
- os: windows-latest
|
|
65
|
+
python-version: '3.11'
|
|
66
|
+
|
|
67
|
+
- os: macos-15
|
|
68
|
+
python-version: '3.12'
|
|
69
|
+
- os: windows-latest
|
|
70
|
+
python-version: '3.12'
|
|
71
|
+
|
|
72
|
+
- os: macos-15
|
|
73
|
+
python-version: '3.13'
|
|
74
|
+
- os: windows-latest
|
|
75
|
+
python-version: '3.13'
|
|
76
|
+
|
|
77
|
+
- os: macos-15
|
|
78
|
+
python-version: pypy3.11
|
|
79
|
+
- os: windows-latest
|
|
80
|
+
python-version: pypy3.11
|
|
81
|
+
|
|
82
|
+
include:
|
|
83
|
+
- os: ubuntu-latest
|
|
84
|
+
python-version: '3.10'
|
|
85
|
+
lowest_resolution: true
|
|
86
|
+
- os: ubuntu-latest
|
|
87
|
+
python-version: '3.14'
|
|
88
|
+
lowest_resolution: true
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
env:
|
|
92
|
+
TOP: ${{github.workspace}}
|
|
93
|
+
COVERAGE_PROCESS_START: ${{github.workspace}}/pyproject.toml
|
|
94
|
+
steps:
|
|
95
|
+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
|
96
|
+
- uses: ./.github/actions/setup
|
|
97
|
+
with:
|
|
98
|
+
python-version: ${{matrix.python-version}}
|
|
99
|
+
|
|
100
|
+
- name: Resolve lowest direct dependencies
|
|
101
|
+
if: matrix.lowest_resolution
|
|
102
|
+
run: |
|
|
103
|
+
uv lock --upgrade --resolution lowest-direct
|
|
104
|
+
uv sync --locked --resolution lowest-direct
|
|
105
|
+
uv pip install coverage coverage-enable-subprocess pytest pytest-xdist
|
|
106
|
+
|
|
107
|
+
- name: Test locked dependencies
|
|
108
|
+
if: ${{ !matrix.lowest_resolution }}
|
|
109
|
+
run: uv run --locked --with coverage --with coverage-enable-subprocess --with pytest --with pytest-xdist -m ${{ matrix.os == 'ubuntu-latest' && 'coverage run -m' || '' }} pytest -n=auto -vv
|
|
110
|
+
|
|
111
|
+
- name: Test lowest direct dependencies
|
|
112
|
+
if: matrix.lowest_resolution
|
|
113
|
+
run: uv run --no-sync -m coverage run -m pytest -n=auto -vv
|
|
114
|
+
|
|
115
|
+
- run: |
|
|
116
|
+
uv run ${{ matrix.lowest_resolution && '--no-sync' || '--with coverage' }} -m coverage combine
|
|
117
|
+
mv .coverage .coverage.${{ matrix.python-version }}-${{matrix.os}}-${{strategy.job-index}}
|
|
118
|
+
if: matrix.os == 'ubuntu-latest'
|
|
119
|
+
|
|
120
|
+
- name: Upload coverage data
|
|
121
|
+
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1
|
|
122
|
+
if: matrix.os == 'ubuntu-latest'
|
|
123
|
+
with:
|
|
124
|
+
name: coverage-data-${{github.run_id}}-${{ matrix.python-version }}-${{matrix.os}}-${{strategy.job-index}}
|
|
125
|
+
path: .coverage.*
|
|
126
|
+
include-hidden-files: true
|
|
127
|
+
if-no-files-found: ignore
|
|
128
|
+
|
|
129
|
+
coverage:
|
|
130
|
+
name: Combine & check coverage
|
|
131
|
+
env:
|
|
132
|
+
TOP: ${{github.workspace}}
|
|
133
|
+
if: always()
|
|
134
|
+
needs: test
|
|
135
|
+
runs-on: ubuntu-latest
|
|
136
|
+
|
|
137
|
+
steps:
|
|
138
|
+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
|
139
|
+
- uses: ./.github/actions/setup
|
|
140
|
+
|
|
141
|
+
- uses: actions/download-artifact@cc203385981b70ca67e1cc392babf9cc229d5806 # v4.1.9
|
|
142
|
+
with:
|
|
143
|
+
pattern: coverage-data-${{github.run_id}}-*
|
|
144
|
+
merge-multiple: true
|
|
145
|
+
|
|
146
|
+
- name: Combine coverage & fail if it's <100%
|
|
147
|
+
run: |
|
|
148
|
+
uv run --with coverage coverage combine
|
|
149
|
+
uv run --with coverage coverage html --skip-covered --skip-empty
|
|
150
|
+
|
|
151
|
+
# Report and write to summary.
|
|
152
|
+
uv run --with coverage coverage report --format=markdown >> "$GITHUB_STEP_SUMMARY"
|
|
153
|
+
|
|
154
|
+
# Report again and fail if under 100%.
|
|
155
|
+
uv run --with coverage coverage report
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
- name: Upload HTML report if check failed
|
|
159
|
+
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1
|
|
160
|
+
with:
|
|
161
|
+
name: html-report
|
|
162
|
+
path: htmlcov
|
|
163
|
+
if: ${{ failure() }}
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
publish:
|
|
167
|
+
name: Publish new release
|
|
168
|
+
needs: [detect_release, test, coverage]
|
|
169
|
+
if: needs.detect_release.outputs.is_release == 'true' && !contains(github.repository, '-insiders/')
|
|
170
|
+
runs-on: ubuntu-latest
|
|
171
|
+
environment: pypi
|
|
172
|
+
permissions:
|
|
173
|
+
contents: write
|
|
174
|
+
id-token: write
|
|
175
|
+
|
|
176
|
+
steps:
|
|
177
|
+
- name: Checkout tested commit
|
|
178
|
+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
|
179
|
+
with:
|
|
180
|
+
fetch-depth: 0
|
|
181
|
+
token: ${{secrets.PAT_WEEKLY_UPDATE}}
|
|
182
|
+
|
|
183
|
+
- uses: ./.github/actions/setup
|
|
184
|
+
with:
|
|
185
|
+
python-version: '3.12'
|
|
186
|
+
|
|
187
|
+
- name: Build distributions
|
|
188
|
+
run: uvx hatch build
|
|
189
|
+
|
|
190
|
+
- name: Tag tested commit
|
|
191
|
+
env:
|
|
192
|
+
TAG: ${{needs.detect_release.outputs.tag}}
|
|
193
|
+
run: |
|
|
194
|
+
git config user.name github-actions[bot]
|
|
195
|
+
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
|
|
196
|
+
if git rev-parse "$TAG" >/dev/null 2>&1; then
|
|
197
|
+
test "$(git rev-list -n 1 "$TAG")" = "$GITHUB_SHA"
|
|
198
|
+
else
|
|
199
|
+
git tag --annotate "$TAG" --message "Release $TAG"
|
|
200
|
+
git push origin "$TAG"
|
|
201
|
+
fi
|
|
202
|
+
|
|
203
|
+
- name: Publish package distributions to PyPI
|
|
204
|
+
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4
|
|
205
|
+
with:
|
|
206
|
+
skip-existing: true
|
|
207
|
+
|
|
208
|
+
- name: Create GitHub release
|
|
209
|
+
env:
|
|
210
|
+
GITHUB_TOKEN: ${{github.token}}
|
|
211
|
+
run: uv run --locked scriv github-release --repo "$GITHUB_REPOSITORY"
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
name: Create release pull request
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
|
|
6
|
+
concurrency:
|
|
7
|
+
group: release-pull-request
|
|
8
|
+
cancel-in-progress: false
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
release-pr:
|
|
12
|
+
if: "!contains(github.repository, '-insiders/')"
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
permissions:
|
|
15
|
+
contents: write
|
|
16
|
+
pull-requests: write
|
|
17
|
+
|
|
18
|
+
steps:
|
|
19
|
+
- name: Checkout main
|
|
20
|
+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
21
|
+
with:
|
|
22
|
+
fetch-depth: 0
|
|
23
|
+
|
|
24
|
+
- name: Set up uv
|
|
25
|
+
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
|
26
|
+
with:
|
|
27
|
+
python-version: '3.13'
|
|
28
|
+
|
|
29
|
+
- name: Prepare release
|
|
30
|
+
id: release
|
|
31
|
+
run: |
|
|
32
|
+
version="$(uv run --locked cz bump --get-next --yes)"
|
|
33
|
+
uv run --locked scriv collect --version "$version" --no-edit
|
|
34
|
+
uv run --locked cz bump "$version" --yes --version-files-only
|
|
35
|
+
uv lock
|
|
36
|
+
echo "version=$version" >> "$GITHUB_OUTPUT"
|
|
37
|
+
|
|
38
|
+
- name: Run pre-commit
|
|
39
|
+
run: uvx pre-commit run --all-files || uvx pre-commit run --all-files
|
|
40
|
+
|
|
41
|
+
- name: Create pull request
|
|
42
|
+
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
|
|
43
|
+
with:
|
|
44
|
+
token: ${{secrets.PAT_WEEKLY_UPDATE}}
|
|
45
|
+
branch: release/v${{steps.release.outputs.version}}
|
|
46
|
+
commit-message: 'chore: release v${{steps.release.outputs.version}}'
|
|
47
|
+
title: 'chore: release v${{steps.release.outputs.version}}'
|
|
48
|
+
body: |
|
|
49
|
+
Prepare release v${{steps.release.outputs.version}}.
|
|
50
|
+
|
|
51
|
+
This pull request was generated from the changelog fragments and
|
|
52
|
+
Conventional Commits on `main`.
|
|
53
|
+
delete-branch: true
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
name: Weekly Cog Update
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
schedule:
|
|
5
|
+
- cron: 0 8 * * 5 # Every Friday at 08:00 UTC
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
weekly-update:
|
|
10
|
+
permissions:
|
|
11
|
+
contents: write
|
|
12
|
+
pull-requests: write
|
|
13
|
+
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- name: Checkout repository
|
|
17
|
+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
18
|
+
with:
|
|
19
|
+
fetch-depth: 0
|
|
20
|
+
|
|
21
|
+
- name: Set up Python
|
|
22
|
+
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
|
|
23
|
+
with:
|
|
24
|
+
python-version: '3.12'
|
|
25
|
+
|
|
26
|
+
- name: Set up uv
|
|
27
|
+
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
|
28
|
+
|
|
29
|
+
- name: Run cog update
|
|
30
|
+
run: |
|
|
31
|
+
git ls-files -z -- '*.py' '*.md' | xargs -0 -r uv run --group cog cog -r
|
|
32
|
+
uvx gha-update
|
|
33
|
+
uvx pre-commit run --all-files || uvx pre-commit run --all-files
|
|
34
|
+
|
|
35
|
+
- name: Create Pull Request
|
|
36
|
+
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
|
|
37
|
+
with:
|
|
38
|
+
token: ${{github.token}}
|
|
39
|
+
branch-token: ${{secrets.PAT_WEEKLY_UPDATE}}
|
|
40
|
+
commit-message: 'chore: weekly cog update'
|
|
41
|
+
title: 'chore: weekly update'
|
|
42
|
+
body: Automated weekly update via scheduled workflow.
|
|
43
|
+
branch: chore/weekly-update
|
|
44
|
+
delete-branch: true
|
|
45
|
+
reviewers: 15r10nk
|
|
@@ -5,6 +5,13 @@ ci:
|
|
|
5
5
|
autoupdate_schedule: monthly
|
|
6
6
|
|
|
7
7
|
repos:
|
|
8
|
+
|
|
9
|
+
- repo: https://github.com/15r10nk/project-template
|
|
10
|
+
rev: v0.3.2
|
|
11
|
+
hooks:
|
|
12
|
+
- id: copier-enforce
|
|
13
|
+
|
|
14
|
+
|
|
8
15
|
- hooks:
|
|
9
16
|
- id: check-ast
|
|
10
17
|
- id: check-merge-conflict
|
|
@@ -41,6 +48,7 @@ repos:
|
|
|
41
48
|
- args:
|
|
42
49
|
- --py310-plus
|
|
43
50
|
id: pyupgrade
|
|
51
|
+
language_version: python3.13
|
|
44
52
|
repo: https://github.com/asottile/pyupgrade
|
|
45
53
|
rev: v3.20.0
|
|
46
54
|
- hooks:
|
|
@@ -84,6 +92,7 @@ repos:
|
|
|
84
92
|
- id: actionlint
|
|
85
93
|
|
|
86
94
|
- repo: https://github.com/crate-ci/typos
|
|
87
|
-
rev: v1
|
|
95
|
+
rev: v1.47.0
|
|
88
96
|
hooks:
|
|
89
97
|
- id: typos
|
|
98
|
+
exclude: ^COPIER_TEMPLATE_CHANGES\.md$
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
- id: matchify
|
|
2
|
+
name: matchify
|
|
3
|
+
description: Convert eligible if/elif chains to match statements.
|
|
4
|
+
entry: matchify
|
|
5
|
+
language: python
|
|
6
|
+
types: [python]
|
|
7
|
+
- id: matchify-check
|
|
8
|
+
name: matchify check
|
|
9
|
+
description: Check whether Python files can be converted with matchify.
|
|
10
|
+
entry: matchify --check
|
|
11
|
+
language: python
|
|
12
|
+
types: [python]
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
<!-- scriv-insert-here -->
|
|
4
|
+
|
|
5
|
+
<a id='changelog-0.2.0'></a>
|
|
6
|
+
# 0.2.0 — 2026-08-08
|
|
7
|
+
|
|
8
|
+
## Added
|
|
9
|
+
|
|
10
|
+
- Convert membership tests against eligible literal sets into OR patterns when
|
|
11
|
+
the `hashable-subjects` assumption is enabled.
|
|
12
|
+
|
|
13
|
+
## Fixed
|
|
14
|
+
|
|
15
|
+
- Apply `--no-types` patterns to qualified `isinstance` targets such as
|
|
16
|
+
`typing.Mapping`, including targets contained in type tuples.
|
|
17
|
+
|
|
18
|
+
<a id='changelog-0.1.0'></a>
|
|
19
|
+
# 0.1.0 — 2026-08-04
|
|
20
|
+
|
|
21
|
+
## Added
|
|
22
|
+
|
|
23
|
+
- Added `--check` mode. It reports files that would be converted without
|
|
24
|
+
modifying them and exits with status 1 when changes are needed or processing
|
|
25
|
+
errors occur.
|
|
26
|
+
- Added `matchify` and `matchify-check` pre-commit hooks for automatic rewriting
|
|
27
|
+
and check-only CI workflows.
|
|
28
|
+
- Added conversion of eligible inline dictionary lookups and single-use local
|
|
29
|
+
lookup-table variables into `match` statements. Literal and nested tuple keys,
|
|
30
|
+
arbitrary value expressions, comments, single evaluation of the lookup key,
|
|
31
|
+
and the original `KeyError` behavior are preserved where supported. This
|
|
32
|
+
conversion requires the new `lookup-equality` assumption.
|
|
33
|
+
- Added the `identity-equality` assumption, allowing qualified identity checks
|
|
34
|
+
such as `value is Enum.MEMBER` to become value patterns when identity and
|
|
35
|
+
equality are known to be equivalent.
|
|
36
|
+
- Added separate `list-sequence-pattern` and `tuple-sequence-pattern`
|
|
37
|
+
assumptions for converting explicit sequence type checks into Python sequence
|
|
38
|
+
patterns. Checks against both types require both assumptions.
|
|
39
|
+
- Exported `Assumptions` from the top-level `matchify` package.
|
|
40
|
+
- Added an MIT license.
|
|
41
|
+
|
|
42
|
+
## Changed
|
|
43
|
+
|
|
44
|
+
- Composite match subjects selected under `pure-subjects` now use paths shared
|
|
45
|
+
by a majority of branches. This enables more eligible mixed-subject chains to
|
|
46
|
+
be converted while keeping less common checks in guards.
|
|
47
|
+
- Sequence transformations are more conservative: an `isinstance` check for
|
|
48
|
+
`list` or `tuple` is no longer treated as implied by a sequence pattern unless
|
|
49
|
+
the corresponding assumption is enabled. Qualified class names remain
|
|
50
|
+
guarded and are not covered by these assumptions.
|
|
51
|
+
- CLI summaries distinguish check results with `would convert`, and normal as
|
|
52
|
+
well as check mode now return a failure status for processing errors.
|
|
53
|
+
- Release automation now uses dedicated release pull requests, tags the tested
|
|
54
|
+
merge commit, publishes it to PyPI, and creates GitHub release notes from
|
|
55
|
+
Scriv fragments.
|
|
56
|
+
|
|
57
|
+
## Fixed
|
|
58
|
+
|
|
59
|
+
- Preserved comments attached to dictionary lookup statements during
|
|
60
|
+
conversion.
|
|
61
|
+
- Restricted dictionary lookup conversion to safe, unambiguous candidates.
|
|
62
|
+
Chained subscriptions, reused local tables, multiple or unsupported uses,
|
|
63
|
+
duplicate or unhashable keys, dictionary unpacking, and other unsafe forms
|
|
64
|
+
remain unchanged.
|
|
65
|
+
- Avoided capture-name collisions in generated missing-key cases.
|
|
66
|
+
|
|
67
|
+
## Development
|
|
68
|
+
|
|
69
|
+
- Expanded behavior and public-API tests, including generated runtime
|
|
70
|
+
round-trips, and enforced 100% branch coverage.
|
|
71
|
+
- Added locked dependencies, lowest-direct-dependency CI coverage, PyPy 3.11
|
|
72
|
+
testing, and updated repository template and maintenance automation.
|
|
@@ -42,3 +42,8 @@ environment values.
|
|
|
42
42
|
|
|
43
43
|
# Commits
|
|
44
44
|
Please use [pre-commit](https://pre-commit.com/) for your commits.
|
|
45
|
+
|
|
46
|
+
# Changelog
|
|
47
|
+
Add a changelog fragment for user-visible changes with
|
|
48
|
+
`uv run scriv create --add --edit`. The fragments are collected automatically
|
|
49
|
+
when the release pull request is created.
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# Änderungen am Copier-Template
|
|
2
|
+
|
|
3
|
+
Diese Datei beschreibt die Änderungen, die im Template
|
|
4
|
+
[`15r10nk/project-template`](https://github.com/15r10nk/project-template)
|
|
5
|
+
vorgenommen werden sollten. Sie basieren auf den Problemen, die beim Update
|
|
6
|
+
von Matchify auf Template-Version `v0.1.0` in GitHub Actions aufgetreten sind.
|
|
7
|
+
|
|
8
|
+
## 1. Coverage-Verzeichnis in allen relevanten Jobs setzen
|
|
9
|
+
|
|
10
|
+
Die Coverage-Konfiguration verwendet aktuell:
|
|
11
|
+
|
|
12
|
+
```toml
|
|
13
|
+
[tool.coverage.run]
|
|
14
|
+
data_file = "$TOP/.coverage"
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Der `test`-Job muss deshalb `TOP` definieren. Andernfalls versucht
|
|
18
|
+
`coverage.py`, Dateien wie `/.coverage.*` im Wurzelverzeichnis anzulegen, und
|
|
19
|
+
scheitert wegen fehlender Schreibrechte.
|
|
20
|
+
|
|
21
|
+
```yaml
|
|
22
|
+
jobs:
|
|
23
|
+
test:
|
|
24
|
+
env:
|
|
25
|
+
TOP: ${{github.workspace}}
|
|
26
|
+
|
|
27
|
+
coverage:
|
|
28
|
+
env:
|
|
29
|
+
TOP: ${{github.workspace}}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Alternativ sollte das Template ganz auf die Umgebungsvariable verzichten und
|
|
33
|
+
den Standardpfad `.coverage` relativ zum Arbeitsverzeichnis verwenden. Wichtig
|
|
34
|
+
ist, dass Template-Konfiguration und Workflow dieselbe Strategie benutzen.
|
|
35
|
+
|
|
36
|
+
## 2. Coverage nicht ohne zusätzliche Konfiguration mit pytest-xdist ausführen
|
|
37
|
+
|
|
38
|
+
Der bisherige Aufruf
|
|
39
|
+
|
|
40
|
+
```yaml
|
|
41
|
+
coverage run -m pytest -n=auto
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
misst nur den xdist-Steuerprozess. Die eigentlichen Tests laufen in
|
|
45
|
+
Unterprozessen, sodass leere Coverage-Daten entstehen und der spätere
|
|
46
|
+
`coverage html`- beziehungsweise `coverage report`-Schritt mit `No data to
|
|
47
|
+
report` scheitert.
|
|
48
|
+
|
|
49
|
+
Die einfache und robuste Template-Vorgabe sollte deshalb ohne xdist laufen:
|
|
50
|
+
|
|
51
|
+
```yaml
|
|
52
|
+
- name: Test locked dependencies
|
|
53
|
+
run: uv run --locked --with coverage --with pytest -m ${{ matrix.os == 'ubuntu-latest' && 'coverage run -m' || '' }} pytest -vv
|
|
54
|
+
|
|
55
|
+
- name: Test lowest direct dependencies
|
|
56
|
+
run: uv run --no-sync -m coverage run -m pytest -vv
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Auch bei der Installation für die `lowest-direct`-Jobs wird dann
|
|
60
|
+
`pytest-xdist` nicht benötigt:
|
|
61
|
+
|
|
62
|
+
```yaml
|
|
63
|
+
uv pip install coverage pytest
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Falls parallele Tests im Template zwingend gewünscht sind, muss stattdessen
|
|
67
|
+
die Coverage-Unterprozessmessung vollständig eingerichtet werden, inklusive
|
|
68
|
+
separater Datendateien pro Worker und anschließendem `coverage combine`.
|
|
69
|
+
|
|
70
|
+
## 3. Unterstützte PyPy-Version als Vorgabe verwenden
|
|
71
|
+
|
|
72
|
+
`pypy3.10` kann die aktuelle Version von LibCST nicht mehr bauen. Deren
|
|
73
|
+
Rust/PyO3-Abhängigkeiten setzen mindestens PyPy 3.11 voraus. Die
|
|
74
|
+
Copier-Vorgabe und die generierte CI-Matrix sollten daher `pypy3.11` verwenden:
|
|
75
|
+
|
|
76
|
+
```yaml
|
|
77
|
+
pypy_versions:
|
|
78
|
+
- pypy3.11
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Das betrifft sowohl die Frage beziehungsweise den Default in `copier.yml` als
|
|
82
|
+
auch alle Stellen im Workflow-Template, die aus dieser Antwort erzeugt werden.
|
|
83
|
+
Die unterstützten PyPy-Versionen sollten nicht unabhängig voneinander an
|
|
84
|
+
mehreren Stellen fest eingetragen sein.
|
|
85
|
+
|
|
86
|
+
## 4. Python-Architektur an den GitHub-Runner anpassen
|
|
87
|
+
|
|
88
|
+
Die Composite Action erzwingt derzeit für `actions/setup-python` die
|
|
89
|
+
Architektur `x64`. `macos-latest` läuft jedoch auf ARM64. Dadurch lädt die
|
|
90
|
+
Action eine inkompatible Intel-Python-Version, die unter anderem wegen
|
|
91
|
+
fehlender x64-Homebrew-Bibliotheken nicht startet.
|
|
92
|
+
|
|
93
|
+
Die Architektur sollte vom Runner übernommen werden:
|
|
94
|
+
|
|
95
|
+
```yaml
|
|
96
|
+
- name: Set up Python
|
|
97
|
+
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b
|
|
98
|
+
with:
|
|
99
|
+
python-version: ${{inputs.python-version}}
|
|
100
|
+
architecture: ${{runner.arch == 'ARM64' && 'arm64' || 'x64'}}
|
|
101
|
+
allow-prereleases: true
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Noch besser ist es, `architecture` wegzulassen, sofern `setup-python` dann auf
|
|
105
|
+
allen vorgesehenen Runnern zuverlässig die native Architektur auswählt.
|
|
106
|
+
|
|
107
|
+
## 5. macOS-Runner nicht auf eine veraltete Plattform festlegen
|
|
108
|
+
|
|
109
|
+
Die Matrix sollte `macos-latest` statt `macos-14` verwenden, sofern das
|
|
110
|
+
Template nicht gezielt eine bestimmte macOS-Version testen muss:
|
|
111
|
+
|
|
112
|
+
```yaml
|
|
113
|
+
os: [ubuntu-latest, windows-latest, macos-latest]
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Alle zugehörigen `exclude`-Einträge müssen denselben Labelwert verwenden.
|
|
117
|
+
Diese Änderung allein reicht jedoch nicht aus; die Composite Action muss auch
|
|
118
|
+
die native Runner-Architektur gemäß Abschnitt 4 berücksichtigen.
|
|
119
|
+
|
|
120
|
+
## 6. Generierte Kombinationen als Template-Test prüfen
|
|
121
|
+
|
|
122
|
+
Das Template sollte mindestens ein generiertes Beispielprojekt in CI erzeugen
|
|
123
|
+
und dessen Workflow-Konfiguration statisch prüfen. Sinnvolle Prüfungen sind:
|
|
124
|
+
|
|
125
|
+
- `actionlint` für alle generierten Workflows,
|
|
126
|
+
- Konsistenz zwischen `data_file = "$TOP/.coverage"` und den Job-Umgebungen,
|
|
127
|
+
- keine Kombination aus `coverage run` und `pytest -n` ohne
|
|
128
|
+
Unterprozesskonfiguration,
|
|
129
|
+
- native Architektur für ARM64-macOS,
|
|
130
|
+
- eine tatsächlich installierbare PyPy-Version,
|
|
131
|
+
- `uv lock --check` beziehungsweise `uv run --locked`,
|
|
132
|
+
- ein Testlauf mit der niedrigsten direkten Auflösung.
|
|
133
|
+
|
|
134
|
+
Zusätzlich sollte ein durch Copier erzeugtes Smoke-Projekt regelmäßig auf
|
|
135
|
+
Ubuntu, Windows, macOS und PyPy ausgeführt werden. Eine reine YAML-Prüfung kann
|
|
136
|
+
Architektur- und Wheel-Kompatibilitätsprobleme nicht erkennen.
|
|
137
|
+
|
|
138
|
+
## Akzeptanzkriterien
|
|
139
|
+
|
|
140
|
+
Nach den Template-Änderungen sollte ein frisch erzeugtes Projekt ohne manuelle
|
|
141
|
+
Nacharbeit folgende GitHub-Actions-Jobs erfolgreich ausführen:
|
|
142
|
+
|
|
143
|
+
- alle konfigurierten CPython-Versionen auf Ubuntu,
|
|
144
|
+
- die älteste und neueste CPython-Version auf Windows und macOS,
|
|
145
|
+
- PyPy 3.11 auf Ubuntu,
|
|
146
|
+
- `lowest-direct` für die älteste und neueste CPython-Version,
|
|
147
|
+
- Zusammenführen und Prüfen der Coverage-Daten,
|
|
148
|
+
- alle Pre-Commit- und `actionlint`-Prüfungen.
|
|
149
|
+
|
|
150
|
+
Die entsprechenden, in Matchify bereits bewährten Änderungen befinden sich in
|
|
151
|
+
den Commits `96538b5`, `d2e8d59` und `52ae891` des Copier-Update-Branches.
|
matchify-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) Frank Hoffmann
|
|
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
|
|
13
|
+
all 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
|
|
21
|
+
THE SOFTWARE.
|