Skip to content

Commit 3a23635

Browse files
committed
Updated project
1 parent 994014e commit 3a23635

5 files changed

Lines changed: 91 additions & 74 deletions

File tree

‎.coveragerc‎

Lines changed: 0 additions & 24 deletions
This file was deleted.

‎.github/workflows/python-package.yml‎

Lines changed: 60 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ on:
1010
branches: [ "main" ]
1111

1212
permissions:
13-
id-token: write
1413
contents: read
1514

1615
jobs:
@@ -33,96 +32,110 @@ jobs:
3332
fail-fast: false
3433
matrix:
3534
os: [ubuntu-latest]
36-
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
35+
python-version: ["3.10", "3.11", "3.12", "3.13"]
3736
env:
3837
package: ${{ needs.prepare.outputs.package }}
38+
cov_python_version: "3.13"
3939
steps:
40-
- uses: actions/checkout@v5
40+
- uses: actions/checkout@v7
4141
- name: Set up Python ${{ matrix.python-version }}
42-
uses: actions/setup-python@v6
42+
uses: actions/setup-python@v7
4343
with:
4444
python-version: ${{ matrix.python-version }}
4545
- name: Install ${{ env.package }}
4646
run: |
4747
python -m pip install --upgrade pip
48-
python -m pip install pytest pytest-cov coverage
48+
python -m pip install pytest pytest-cov
4949
pip install -r requirements.txt
50-
pip install tinyscript>=1.31
50+
pip install "tinyscript>=1.31"
5151
pip install .
5252
- name: Test ${{ env.package }} with pytest
5353
run: |
54-
pytest --cov=$package
54+
pytest --cov=$package --cov-report=xml
55+
- name: Upload coverage report
56+
if: matrix.python-version == env.cov_python_version
57+
uses: actions/upload-artifact@v7
58+
with:
59+
name: coverage-report
60+
path: coverage.xml
5561
coverage:
56-
needs: [prepare, build]
62+
# only publish the badge for commits on main (not for pull requests)
63+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
64+
needs: build
5765
permissions:
5866
contents: write
5967
runs-on: ubuntu-latest
6068
env:
6169
cov_badge_path: docs/coverage.svg
62-
package: ${{ needs.prepare.outputs.package }}
63-
python_version: "3.13"
6470
steps:
65-
- uses: actions/checkout@v5
71+
- uses: actions/checkout@v7
72+
- name: Set up Python
73+
uses: actions/setup-python@v7
6674
with:
67-
fetch-depth: 0
68-
ref: ${{ (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && github.event.pull_request.head.sha || github.sha }}
69-
- name: Set up Python ${{ env.python_version }}
70-
uses: actions/setup-python@v6
75+
python-version: "3.13"
76+
- name: Download coverage report
77+
uses: actions/download-artifact@v8
7178
with:
72-
python-version: ${{ env.python_version }}
73-
- name: Install ${{ env.package }}
74-
run: |
75-
python -m pip install --upgrade pip
76-
python -m pip install pytest pytest-cov
77-
pip install -r requirements.txt
78-
pip install .
79-
- name: Make coverage badge for ${{ env.package }}
79+
name: coverage-report
80+
- name: Make coverage badge
8081
run: |
8182
pip install genbadge[coverage]
82-
pytest --cov=$package --cov-report=xml
8383
genbadge coverage -i coverage.xml -o $cov_badge_path
84-
- name: Verify Changed files
85-
uses: tj-actions/verify-changed-files@v20
86-
id: changed_files
87-
with:
88-
files: ${{ env.cov_badge_path }}
8984
- name: Push coverage badge
90-
if: steps.changed_files.outputs.files_changed == 'true'
9185
run: |
86+
# keep the badge alone on an orphan branch so that main is never modified by the workflow
9287
git config --local user.email "github-actions[bot]@users.noreply.github.com"
9388
git config --local user.name "github-actions[bot]"
94-
git fetch origin
95-
git checkout coverage-badge || git checkout -b coverage-badge
89+
if git fetch --depth=1 origin coverage-badge 2>/dev/null && \
90+
git show FETCH_HEAD:$cov_badge_path | cmp -s - $cov_badge_path; then
91+
echo "Coverage badge unchanged"
92+
exit 0
93+
fi
94+
git checkout --orphan coverage-badge
95+
git rm -rqf --cached .
9696
git add $cov_badge_path
97-
git diff --cached --quiet && exit 0
9897
git commit -m "Update coverage badge"
9998
git push origin coverage-badge --force
10099
deploy:
100+
# only release from main, never from pull requests
101+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
101102
environment:
102103
name: pypi
103104
url: ${{ needs.prepare.outputs.pypi_url }}
105+
permissions:
106+
contents: read
107+
id-token: write # for PyPI trusted publishing (OIDC)
104108
runs-on: ubuntu-latest
105-
needs: [prepare, coverage]
109+
needs: [prepare, build]
110+
env:
111+
package: ${{ needs.prepare.outputs.package }}
106112
steps:
107-
- uses: actions/checkout@v5
108-
with:
109-
fetch-depth: 0
110-
- name: Check for version change
111-
uses: dorny/paths-filter@v4
112-
id: filter
113+
- uses: actions/checkout@v7
114+
- name: Check whether the version is already on PyPI
115+
# comparing with PyPI (not with the previous commit) also releases a version whose push did not trigger a deploy
116+
id: version
117+
run: |
118+
version=$(tr -d '[:space:]' < src/$package/VERSION.txt)
119+
status=$(curl -s -o /dev/null -w '%{http_code}' --retry 3 "https://pypi.org/pypi/$package/$version/json")
120+
case "$status" in
121+
200) echo "Version $version is already on PyPI" ; echo "new=false" >> "$GITHUB_OUTPUT" ;;
122+
404) echo "Version $version is not on PyPI yet" ; echo "new=true" >> "$GITHUB_OUTPUT" ;;
123+
*) echo "::error::Unexpected HTTP status $status from PyPI" ; exit 1 ;;
124+
esac
125+
- if: steps.version.outputs.new == 'true'
126+
name: Set up Python
127+
uses: actions/setup-python@v7
113128
with:
114-
filters: |
115-
version:
116-
- '**/VERSION.txt'
117-
- if: steps.filter.outputs.version == 'true'
129+
python-version: "3.13"
130+
- if: steps.version.outputs.new == 'true'
118131
name: Cleanup README
119132
run: |
120133
sed -ri 's/^(##*)\s*:.*:\s*/\1 /g' README.md
121134
awk '{if (match($0,"## Supporters")) exit; print}' README.md > README
122135
mv -f README README.md
123-
- if: steps.filter.outputs.version == 'true'
136+
- if: steps.version.outputs.new == 'true'
124137
name: Build ${{ needs.prepare.outputs.package }} package
125-
run: python3 -m pip install --upgrade build && python3 -m build
126-
- if: steps.filter.outputs.version == 'true'
138+
run: python -m pip install --upgrade build && python -m build
139+
- if: steps.version.outputs.new == 'true'
127140
name: Publish to PyPI
128141
uses: pypa/gh-action-pypi-publish@release/v1
File renamed without changes.

‎pyproject.toml‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,36 @@ version = {attr = "codext.__info__.__version__"}
88
[tool.setuptools.packages.find]
99
where = ["src"]
1010

11+
[tool.pytest.ini_options]
12+
pythonpath = ["src"]
13+
14+
[tool.coverage.run]
15+
source = ["codext"]
16+
omit = [
17+
"src/codext/__info__.py",
18+
"src/codext/**/__init__.py",
19+
]
20+
21+
[tool.coverage.report]
22+
exclude_lines = [
23+
'pragma: no cover',
24+
'if.*?__name__.*?==.*?.__main__.:',
25+
'def main\(\)\:',
26+
'def __stdin_pipe\(\)\:',
27+
'for line in __stdin_pipe\(\)\:',
28+
'def __format_list\(items, include\=True\)\:',
29+
'def __print_tabular\(lst, space\=4\)\:',
30+
'except ImportError:',
31+
'except NameError:',
32+
'raise NotImplementedError',
33+
'def _detect\(text\)\:',
34+
'def _lang\(lang\)\:',
35+
'if stopfunc\.LANG_BACKEND\:',
36+
'def _validate\(stop_function, lang_backend\=\"none\"\)\:',
37+
'except KeyboardInterrupt\:',
38+
'if alt and len\(t\) \% 2 \=\= 1\:',
39+
]
40+
1141
[project]
1242
name = "codext"
1343
authors = [
@@ -16,7 +46,7 @@ authors = [
1646
description = "Native codecs extension"
1747
license = {file = "LICENSE"}
1848
keywords = ["python", "development", "programming", "codecs", "encodings"]
19-
requires-python = ">=3.8,<4"
49+
requires-python = ">=3.10,<4"
2050
classifiers = [
2151
"Development Status :: 5 - Production/Stable",
2252
"Environment :: Console",

‎pytest.ini‎

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)