Skip to content

Commit c89e04e

Browse files
authored
Merge pull request #1 from devjerry0/dev
fix: move imports to top-level in test file
2 parents fe330f3 + 4cdfcb9 commit c89e04e

File tree

11 files changed

+160
-239
lines changed

11 files changed

+160
-239
lines changed

.github/workflows/auto-tag.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Auto Tag on Version Change
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'contractions/_version.py'
9+
10+
jobs:
11+
tag:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: write
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Extract version from _version.py
23+
id: get_version
24+
run: |
25+
VERSION=$(grep -oP '__version__\s*=\s*"\K[^"]+' contractions/_version.py)
26+
echo "version=${VERSION}" >> $GITHUB_OUTPUT
27+
echo "Detected version: ${VERSION}"
28+
29+
- name: Check if tag exists
30+
id: check_tag
31+
run: |
32+
if git rev-parse "v${{ steps.get_version.outputs.version }}" >/dev/null 2>&1; then
33+
echo "exists=true" >> $GITHUB_OUTPUT
34+
echo "Tag v${{ steps.get_version.outputs.version }} already exists"
35+
else
36+
echo "exists=false" >> $GITHUB_OUTPUT
37+
echo "Tag v${{ steps.get_version.outputs.version }} does not exist"
38+
fi
39+
40+
- name: Create and push tag
41+
if: steps.check_tag.outputs.exists == 'false'
42+
run: |
43+
git config user.name "github-actions[bot]"
44+
git config user.email "github-actions[bot]@users.noreply.github.com"
45+
git tag -a "v${{ steps.get_version.outputs.version }}" -m "Release v${{ steps.get_version.outputs.version }}"
46+
git push origin "v${{ steps.get_version.outputs.version }}"
47+
echo "✅ Created and pushed tag v${{ steps.get_version.outputs.version }}"
48+
49+
- name: Tag already exists
50+
if: steps.check_tag.outputs.exists == 'true'
51+
run: |
52+
echo "⚠️ Tag v${{ steps.get_version.outputs.version }} already exists. Skipping tag creation."
53+

.github/workflows/commit.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,20 @@ name: commit
33

44
on:
55
push:
6+
branches: [dev, main]
7+
pull_request:
8+
branches: [main]
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
permissions:
15+
contents: read
616

717
jobs:
818
lint:
9-
name: Python Lint
19+
name: Lint
1020
runs-on: ubuntu-latest
1121
steps:
1222
- name: checkout
@@ -47,8 +57,9 @@ jobs:
4757
run: pytest tests/ --cov=contractions --cov-report=xml --cov-report=term
4858
- name: Upload coverage to Codecov
4959
if: matrix.py-version == '3.12'
50-
uses: codecov/codecov-action@v4
60+
uses: codecov/codecov-action@v5
5161
with:
62+
token: ${{ secrets.CODECOV_TOKEN }}
5263
file: ./coverage.xml
5364
fail_ci_if_error: false
5465

.github/workflows/publish.yml

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,79 @@
11
name: Publish to PyPI
22

33
on:
4-
release:
5-
types: [published]
6-
workflow_dispatch:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: false
11+
12+
permissions:
13+
contents: read
714

815
jobs:
16+
test:
17+
name: Run Tests Before Publishing
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Install uv
24+
uses: astral-sh/setup-uv@v3
25+
26+
- name: Set up Python
27+
uses: actions/setup-python@v5
28+
with:
29+
python-version: '3.12'
30+
31+
- name: Install dependencies
32+
run: uv pip install --system -e ".[dev]"
33+
34+
- name: Run ruff
35+
run: ruff check .
36+
37+
- name: Run mypy
38+
run: mypy contractions/ tests/
39+
40+
- name: Run tests with coverage
41+
run: pytest tests/ --cov=contractions --cov-report=term
42+
943
deploy:
44+
name: Build and Publish to PyPI
1045
runs-on: ubuntu-latest
46+
needs: test
1147
permissions:
48+
contents: read
1249
id-token: write
1350

1451
steps:
1552
- name: Checkout code
1653
uses: actions/checkout@v4
17-
with:
18-
fetch-depth: 0
54+
55+
- name: Extract version from tag
56+
id: get_version
57+
run: |
58+
VERSION=${GITHUB_REF#refs/tags/v}
59+
echo "version=${VERSION}" >> $GITHUB_OUTPUT
60+
echo "Publishing version: ${VERSION}"
61+
62+
- name: Update version in _version.py
63+
run: |
64+
echo "__version__ = \"${{ steps.get_version.outputs.version }}\"" > contractions/_version.py
65+
cat contractions/_version.py
66+
67+
- name: Install uv
68+
uses: astral-sh/setup-uv@v3
1969

2070
- name: Set up Python
2171
uses: actions/setup-python@v5
2272
with:
2373
python-version: '3.12'
2474

2575
- name: Install build dependencies
26-
run: |
27-
python -m pip install --upgrade pip
28-
pip install build twine
29-
30-
- name: Update version from git commits
31-
run: |
32-
COMMIT_COUNT=$(git rev-list --all --count)
33-
MAJOR=$(grep 'MAJOR_VERSION = ' setup.py | sed 's/.*"\([0-9]*\)".*/\1/')
34-
MINOR=$(grep 'MINOR_VERSION = ' setup.py | sed 's/.*"\([0-9]*\)".*/\1/')
35-
VERSION="${MAJOR}.${MINOR}.${COMMIT_COUNT}"
36-
37-
sed -i "s/MICRO_VERSION = \"[0-9]*\"/MICRO_VERSION = \"${COMMIT_COUNT}\"/" setup.py
38-
sed -i "s/__version__ = \"[0-9.]*\"/__version__ = \"${VERSION}\"/" contractions/__init__.py
39-
40-
echo "Building version: ${VERSION}"
76+
run: uv pip install --system build twine
4177

4278
- name: Build package
4379
run: python -m build

.gitignore

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,13 @@ __pycache__/
1616
/pip-selfcheck.json
1717
.tox/
1818
.cache
19-
.coverage
19+
.coverage
20+
coverage.xml
21+
htmlcov/
22+
.pytest_cache/
23+
*.egg-info/
24+
.mypy_cache/
25+
.ruff_cache/
26+
.dmypy.json
27+
dmypy.json
28+
.hypothesis/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pip install sane-contractions
3131
uv pip install sane-contractions
3232
```
3333

34-
[uv](https://github.com/astral-sh/uv) is 10-100x faster than pip. See [UV_USAGE.md](UV_USAGE.md) for more details.
34+
[uv](https://github.com/astral-sh/uv) is 10-100x faster than pip and is a drop-in replacement.
3535

3636
## Quick Start
3737

UV_USAGE.md

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

contractions/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1+
from ._version import __version__
12
from .api import add, add_dict, load_json, preview
23
from .core import fix
34

4-
__version__ = "0.1.72"
5-
6-
__all__ = ["fix", "add", "add_dict", "load_json", "preview"]
5+
__all__ = ["fix", "add", "add_dict", "load_json", "preview", "__version__"]

contractions/_version.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
__version__ = "0.2.0"
2+

0 commit comments

Comments
 (0)