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
15 changes: 7 additions & 8 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,16 @@ jobs:
with:
python-version: "3.12"

- uses: abatilo/actions-poetry@v2
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
poetry-version: "latest"
version: ">=0.4.0"

- name: install depends
run: |
pip install nox
poetry install
- name: Install dependencies
run: uv sync --extra dev

- name: Run lint checks
run: poetry run nox -s lint
run: uvx nox -s lint

- name: Run tests
run: poetry run nox -s test
run: uvx nox -s test
28 changes: 16 additions & 12 deletions .github/workflows/release_build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ on:
jobs:
release-build:
runs-on: ubuntu-latest
permissions:
contents: write # 用于创建 GitHub Release
steps:
- uses: actions/checkout@v4

Expand All @@ -24,27 +26,29 @@ jobs:
with:
python-version: "3.12"

- uses: abatilo/actions-poetry@v2
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
poetry-version: "latest"
version: ">=0.4.0"

- name: Install nox
run: pip install nox
- name: Install dependencies
run: uv sync --extra dev

- name: build and publish
- name: Build and test
run: |
poetry config pypi-token.pypi ${{ env.PYPI_TOKEN }}
poetry install
poetry run nox -s lint
poetry run nox -s test
poetry run nox -s build
poetry publish
uvx nox -s lint
uvx nox -s test
uvx nox -s build

- name: Publish to PyPI
env:
UV_PUBLISH_TOKEN: ${{ env.PYPI_TOKEN }}
run: uv publish --retry 3

- name: Release
uses: softprops/action-gh-release@v2
with:
files: |
dist/**/*.exe
dist/*.tar.gz
dist/*.whl
generate_release_notes: true
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
/build/
/coverage.xml
/.zip/
/venv/
/venv/
/dist/
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
Binary file added __pycache__/noxfile.cpython-312.pyc
Binary file not shown.
139 changes: 116 additions & 23 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,33 @@
- Code linting and formatting
- Unit testing with coverage reporting
- Package building
- Executable creation
- Project cleaning
- Baseline creation for linting rules

Typical usage example:
nox -s lint # Run linting
nox -s test # Run tests
nox -s build # Build package
nox -s build_exe # Build package with standalone executable
nox -s lint # Run linting
nox -s test # Run tests
nox -s build # Build package
nox -s clean # Clean project
nox -s baseline # Create a new baseline for linting rules
"""
import nox
import shutil
from pathlib import Path


def install_with_uv(session: nox.Session, editable: bool = False) -> None:
"""Helper function to install packages using uv.

Args:
session: Nox session object for running commands
editable: Whether to install in editable mode
"""
session.install("uv")
if editable:
session.run("uv", "pip", "install", "-e", ".[dev]")
else:
session.run("uv", "pip", "install", ".")


@nox.session(reuse_venv=True)
Expand All @@ -25,9 +43,11 @@ def lint(session: nox.Session) -> None:
Args:
session: Nox session object for running commands
"""
session.install("poetry")
# Install dependencies
session.install("ruff")
session.run("poetry", "install", "--only", "dev")
install_with_uv(session, editable=True)

# Run linting checks
session.run(
"ruff",
"check",
Expand All @@ -42,18 +62,22 @@ def lint(session: nox.Session) -> None:
"--diff"
)


@nox.session(reuse_venv=True)
def test(session: nox.Session) -> None:
"""Run the test suite with coverage reporting.

Executes pytest with coverage reporting for the github_action_test package.
Executes pytest with coverage reporting for the repo_scaffold package.
Generates both terminal and XML coverage reports.

Args:
session: Nox session object for running commands
"""
session.install("poetry")
session.run("poetry", "install")
# Install dependencies
install_with_uv(session, editable=True)
session.install("pytest", "pytest-cov", "pytest-mock")

# Run tests
session.run(
"pytest",
"--cov=repo_scaffold",
Expand All @@ -68,28 +92,97 @@ def test(session: nox.Session) -> None:
def build(session: nox.Session) -> None:
"""Build the Python package.

Creates a distributable package using poetry build command
with verbose output and excluding dev dependencies.
Creates a distributable package using uv build command.

Args:
session: Nox session object for running commands
"""
session.install("poetry")
session.run("poetry", "install", "--without", "dev")
session.run("poetry", "build", "-vvv")
session.install("uv")
session.run("uv", "build", "--wheel", "--sdist")


@nox.session(reuse_venv=True)
def build_exe(session: nox.Session) -> None:
"""Build the Python package with standalone executable.
def clean(session: nox.Session) -> None: # pylint: disable=unused-argument
"""Clean the project directory.

Removes build artifacts, cache directories, and other temporary files:
- build/: Build artifacts
- dist/: Distribution packages
- .nox/: Nox virtual environments
- .pytest_cache/: Pytest cache
- .ruff_cache/: Ruff cache
- .coverage: Coverage data
- coverage.xml: Coverage report
- **/*.pyc: Python bytecode
- **/__pycache__/: Python cache directories
- **/*.egg-info: Package metadata

Args:
session: Nox session object (unused)
"""
root = Path(".")
patterns = [
"build",
"dist",
".nox",
".pytest_cache",
".ruff_cache",
".coverage",
"coverage.xml",
"**/*.pyc",
"**/__pycache__",
"**/*.egg-info",
]

for pattern in patterns:
for path in root.glob(pattern):
if path.is_file():
path.unlink()
print(f"Removed file: {path}")
elif path.is_dir():
shutil.rmtree(path)
print(f"Removed directory: {path}")

Creates an executable using poetry-pyinstaller-plugin.
Installs required plugin and builds without dev dependencies.

@nox.session(reuse_venv=True)
def baseline(session: nox.Session) -> None:
"""Create a new baseline for linting rules.

This command will:
1. Add # noqa comments to all existing violations
2. Update the pyproject.toml with new extend-ignore rules
3. Show a summary of changes made

Args:
session: Nox session object for running commands
"""
session.install("poetry")
session.install("poetry", "self", "add", "poetry-pyinstaller-plugin")
session.run("poetry", "install", "--without", "dev")
session.run("poetry", "build", "-vvv")
# Install dependencies
session.install("ruff", "tomlkit")
install_with_uv(session, editable=True)

# Get current violations
result = session.run(
"ruff",
"check",
".",
"--verbose",
"--output-format=json",
silent=True,
success_codes=[0, 1]
)

if result:
# Add noqa comments to existing violations
session.run(
"ruff",
"check",
".",
"--add-noqa",
"--verbose",
success_codes=[0, 1]
)

print("\nBaseline created! The following files were modified:")
session.run("git", "diff", "--name-only", external=True)
else:
print("No violations found. No baseline needed.")
Loading
Loading