Skip to content

Commit 7384818

Browse files
authored
Merge pull request #10 from BrentWilkins/Upgrade_to_currently_supported_Python_version_Oct_version
Python version bump with related improvements (October version)
2 parents c323792 + 10ae02e commit 7384818

File tree

6 files changed

+118
-17
lines changed

6 files changed

+118
-17
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Test Version Management
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
tags:
7+
- 'v*'
8+
pull_request:
9+
branches: [ main ]
10+
11+
jobs:
12+
test-version:
13+
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
python-version: ['3.10', '3.11', '3.12', '3.13']
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0 # Full history for version tools that use git
23+
24+
- name: Set up Python ${{ matrix.python-version }}
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: ${{ matrix.python-version }}
28+
29+
- name: Install package and dev dependencies
30+
run: |
31+
python -m pip install --upgrade pip
32+
pip install -e .[dev]
33+
34+
- name: Test version can be imported
35+
run: |
36+
python -c "import cli; print(f'Package version: {cli.__version__}')"
37+
38+
- name: Test importlib.metadata version access
39+
run: |
40+
python -c "import importlib.metadata; version = importlib.metadata.version('cli'); print(f'Metadata version: {version}')"
41+
42+
- name: Verify version consistency
43+
run: |
44+
# Get version from package import
45+
IMPORT_VERSION=$(python -c "import cli; print(cli.__version__)")
46+
# Get version from metadata
47+
METADATA_VERSION=$(python -c "import importlib.metadata; print(importlib.metadata.version('cli'))")
48+
49+
echo "Import version: $IMPORT_VERSION"
50+
echo "Metadata version: $METADATA_VERSION"
51+
52+
if [ "$IMPORT_VERSION" != "$METADATA_VERSION" ]; then
53+
echo "ERROR: Version mismatch between import and metadata!"
54+
exit 1
55+
fi
56+
57+
echo "SUCCESS: Version consistency verified"
58+
59+
60+
- name: Run type checking and formatting
61+
run: |
62+
mypy cli
63+
black --check cli
64+
65+
# Only run on tag pushes to verify git tag matches version
66+
- name: Verify version matches git tag
67+
if: startsWith(github.ref, 'refs/tags/v')
68+
run: |
69+
# Extract version from git tag (e.g., 'v1.2.3' -> '1.2.3')
70+
TAG_VERSION=${GITHUB_REF#refs/tags/v}
71+
# Get version from installed package
72+
INSTALLED_VERSION=$(python -c "import importlib.metadata; print(importlib.metadata.version('cli'))")
73+
74+
echo "Git tag version: $TAG_VERSION"
75+
echo "Installed version: $INSTALLED_VERSION"
76+
77+
if [ "$TAG_VERSION" != "$INSTALLED_VERSION" ]; then
78+
echo "ERROR: Git tag version doesn't match installed version!"
79+
exit 1
80+
fi
81+
82+
echo "SUCCESS: Git tag and installed versions match"
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
__pycache__/
2-
*.py[cod]
31
*$py.class
2+
**.log
3+
*.egg-info/
4+
*.py[cod]
5+
.DS_Store
46
.env
7+
.python-version
58
.venv/
6-
venv/
7-
.DS_Store
8-
**.log
9-
dist/
9+
__pycache__/
1010
build/
11-
*.egg-info/
11+
dist/
12+
venv/

starter-templates/python-cli/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pip install dist/*.whl
3232
```
3333

3434
## Project Structure
35+
3536
- `cli/` - Source files
3637
- `tests/` - Test files
3738
- `pyproject.toml` - Project configuration
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
"""A Python CLI application."""
22

3-
__version__ = "0.1.0"
3+
from importlib.metadata import PackageNotFoundError, version
4+
5+
try:
6+
__version__ = version("cli")
7+
except PackageNotFoundError:
8+
# Package not installed, fallback for development
9+
try:
10+
import toml # type: ignore[import-untyped]
11+
12+
__version__ = toml.load("pyproject.toml")["project"]["version"]
13+
except Exception:
14+
__version__ = "unknown"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
# Python CLI Template Knowledge
22

33
## Project Overview
4+
45
A minimal Python CLI application template with modern Python features and type hints.
56

67
## Key Features
8+
79
- Uses virtual environments for isolation
810
- Type hints and mypy for static type checking
911
- Modern Python packaging with pyproject.toml
1012
- Black for code formatting
1113

1214
## Verifying changes
15+
1316
After every change, run:
17+
1418
```bash
1519
mypy cli && black --check cli
1620
```
21+
1722
This will check for type errors and formatting issues.

starter-templates/python-cli/pyproject.toml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,28 @@
22
name = "cli"
33
version = "0.1.0"
44
description = "A Python CLI application"
5-
requires-python = ">=3.8"
5+
requires-python = ">=3.10"
66
dependencies = []
77

88
[project.optional-dependencies]
99
dev = [
10-
"mypy>=1.8.0",
11-
"black>=24.1.1",
12-
"pytest>=8.0.0",
10+
"black>=25.1.0",
11+
"mypy>=1.17.1",
12+
"pytest>=8.4.2",
13+
"toml>=0.10.2", # In case someone forgets to run `pip install -e ".[dev]"`
1314
]
1415

1516
[build-system]
1617
requires = ["hatchling"]
1718
build-backend = "hatchling.build"
1819

20+
[tool.black]
21+
line-length = 88
22+
target-version = ['py310']
23+
1924
[tool.mypy]
20-
python_version = "3.8"
25+
python_version = "3.10"
2126
strict = true
2227
warn_return_any = true
2328
warn_unused_configs = true
2429
disallow_untyped_defs = true
25-
26-
[tool.black]
27-
line-length = 88
28-
target-version = ['py38']

0 commit comments

Comments
 (0)