Skip to content

Latest commit

 

History

History
110 lines (80 loc) · 2.99 KB

README.md

File metadata and controls

110 lines (80 loc) · 2.99 KB

Sample Project - Python

Docs Test

Sample structure and setup for a Python project which includes:

  • pre-commit hooks (static formatters and type checking)
  • mkdoc generation from docstrings
  • unittest execution

Installation

# install requirements
make init
make install

# install pre-commit configuration
poetry run pre-commit install

Usage

Run Pre-Commit Hooks

# To run the pre-commit hooks against staged files before committing:
uv run pre-commit run

# To run a particular pre-commit hook against staged files before committing:
# uv run pre-commit run <hook>
uv run pre-commit run ruff-format
uv run pre-commit run ruff
uv run pre-commit run mypy

# To run a particular pre-commit hook against all files (staged and unstaged, before committing):
uv run pre-commit run ruff --all-files

# run checks regardless of git status
uv run ruff format --check src
uv run mypy src
uv run ruff src

Run Unittests

# Run all unittests
make test

# Run specific tests
uv run pytest -vv tests/test_placeholder.py::test_Sample_init

Run All Checks

# Run all tests, lints, and checks
make test-all

# run all nox lints
uv run nox -R -s lint

Build Docs

# Build docs
make doc-build
make doc-serve

Distribution

# Build sdist and wheel
make build

# Only build wheel
uv build --wheel

# Publish to PyPI
export UV_PUBLISH_TOKEN="<my-pypi-token>"
uv publish
uv publish --token "<my-pypi-token>"

Pre-commit Hooks

Pre-Commit hooks run during git commit ... in order to apply checks for quality and format prior to commit.

The checks contained in this repo include (in the order in which they run):

  • Various checkers and formatters to verify valid file types, file size, and end of line and end of file whitespace/newlines
  • ruff format applies standard code style formatting (just like black, but faster)
  • ruff checks code for "lint"
  • mypy is used for static type checking
  • sqlfluff checks and fixes sql formatting and linting
  • uv checks on valid and aligned pyproject.toml and uv.lock files
  • commitlint enforces commit message conforms to conventional commit format

If you want ruff format to ignore a particular section of code, you can add the comments # fmt: off and # fmt: on before and after the respective block of code (same as you would if using black).

If you want mypy to ignore a particular line of code, you can add the comment # type: ignore to the end of that line. If # type: ignore is added to the very top of a file, mypy will ignore the entire file.

If you absolutely must commit without adhering to the pre-commit hooks, then you can use git commit -n ... where -n is shorthand for --no-verify.

TODOs

  • [ ]