Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions starter-templates/python-cli/.github/workflows/test-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Test Version Management

on:
push:
branches: [ main, develop ]
tags:
- 'v*'
pull_request:
branches: [ main ]

jobs:
test-version:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10', '3.11', '3.12', '3.13']

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history for version tools that use git

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install package and dev dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[dev]

- name: Test version can be imported
run: |
python -c "import cli; print(f'Package version: {cli.__version__}')"

- name: Test importlib.metadata version access
run: |
python -c "import importlib.metadata; version = importlib.metadata.version('cli'); print(f'Metadata version: {version}')"

- name: Verify version consistency
run: |
# Get version from package import
IMPORT_VERSION=$(python -c "import cli; print(cli.__version__)")
# Get version from metadata
METADATA_VERSION=$(python -c "import importlib.metadata; print(importlib.metadata.version('cli'))")

echo "Import version: $IMPORT_VERSION"
echo "Metadata version: $METADATA_VERSION"

if [ "$IMPORT_VERSION" != "$METADATA_VERSION" ]; then
echo "ERROR: Version mismatch between import and metadata!"
exit 1
fi

echo "SUCCESS: Version consistency verified"


- name: Run type checking and formatting
run: |
mypy cli
black --check cli

# Only run on tag pushes to verify git tag matches version
- name: Verify version matches git tag
if: startsWith(github.ref, 'refs/tags/v')
run: |
# Extract version from git tag (e.g., 'v1.2.3' -> '1.2.3')
TAG_VERSION=${GITHUB_REF#refs/tags/v}
# Get version from installed package
INSTALLED_VERSION=$(python -c "import importlib.metadata; print(importlib.metadata.version('cli'))")

echo "Git tag version: $TAG_VERSION"
echo "Installed version: $INSTALLED_VERSION"

if [ "$TAG_VERSION" != "$INSTALLED_VERSION" ]; then
echo "ERROR: Git tag version doesn't match installed version!"
exit 1
fi

echo "SUCCESS: Git tag and installed versions match"
15 changes: 8 additions & 7 deletions starter-templates/python-cli/.gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
__pycache__/
*.py[cod]
*$py.class
**.log
*.egg-info/
*.py[cod]
.DS_Store
.env
.python-version
.venv/
venv/
.DS_Store
**.log
dist/
__pycache__/
build/
*.egg-info/
dist/
venv/
1 change: 1 addition & 0 deletions starter-templates/python-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pip install dist/*.whl
```

## Project Structure

- `cli/` - Source files
- `tests/` - Test files
- `pyproject.toml` - Project configuration
13 changes: 12 additions & 1 deletion starter-templates/python-cli/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
"""A Python CLI application."""

__version__ = "0.1.0"
from importlib.metadata import PackageNotFoundError, version

try:
__version__ = version("cli")
except PackageNotFoundError:
# Package not installed, fallback for development
try:
import toml # type: ignore[import-untyped]

__version__ = toml.load("pyproject.toml")["project"]["version"]
except Exception:
__version__ = "unknown"
5 changes: 5 additions & 0 deletions starter-templates/python-cli/knowledge.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
# Python CLI Template Knowledge

## Project Overview

A minimal Python CLI application template with modern Python features and type hints.

## Key Features

- Uses virtual environments for isolation
- Type hints and mypy for static type checking
- Modern Python packaging with pyproject.toml
- Black for code formatting

## Verifying changes

After every change, run:

```bash
mypy cli && black --check cli
```

This will check for type errors and formatting issues.
19 changes: 10 additions & 9 deletions starter-templates/python-cli/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,28 @@
name = "cli"
version = "0.1.0"
description = "A Python CLI application"
requires-python = ">=3.8"
requires-python = ">=3.10"
dependencies = []

[project.optional-dependencies]
dev = [
"mypy>=1.8.0",
"black>=24.1.1",
"pytest>=8.0.0",
"black>=25.1.0",
"mypy>=1.17.1",
"pytest>=8.4.2",
"toml>=0.10.2", # In case someone forgets to run `pip install -e ".[dev]"`
]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.black]
line-length = 88
target-version = ['py310']

[tool.mypy]
python_version = "3.8"
python_version = "3.10"
strict = true
warn_return_any = true
warn_unused_configs = true
disallow_untyped_defs = true

[tool.black]
line-length = 88
target-version = ['py38']