diff --git a/.copier-answers.yml b/.copier-answers.yml new file mode 100644 index 0000000..848ada6 --- /dev/null +++ b/.copier-answers.yml @@ -0,0 +1,27 @@ +# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY +_commit: 16ecf4e +_src_path: gh:pdhall99/python-project-template +author_email: 20580126+pdhall99@users.noreply.github.com +author_name: PD Hall +copyright_year: 2026 +docs_enabled: true +github_owner: pdhall99 +keywords: +- astronomy +- astrophysics +- bezier curves +- binary stars +- close binaries +- contact binaries +- equipotential surfaces +- lagrange points +- roche lobe +- roche model +- roche potential +- svg +package_name: rocheometry +project_description: Compute the equipotential geometry of binary systems in the classical + Roche model +project_name: rocheometry +python_support: eol +runtime_dependencies: [] diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..db89a5d --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,28 @@ +version: 2 + +# Each update waits a week before proposing a new release (cooldown), so a +# compromised release has time to be noticed before it reaches the project. +updates: + # Workflow actions are pinned to commit SHAs with version comments, which + # Dependabot updates together. + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "monthly" + cooldown: + default-days: 7 + groups: + github-actions: + patterns: ["*"] + + # When this bumps ruff-pre-commit, bump ruff in pyproject.toml's check-code + # group to the same version in the same pull request. + - package-ecosystem: "pre-commit" + directory: "/" + schedule: + interval: "monthly" + cooldown: + default-days: 7 + groups: + pre-commit: + patterns: ["*"] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9c15ba3..0a10e5a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,6 @@ on: - "[0-9]+.[0-9]+.[0-9]+" pull_request: branches: ["main"] - types: [ready_for_review] workflow_dispatch: permissions: @@ -16,14 +15,10 @@ permissions: env: RUNNER: &runner "ubuntu-24.04" JOB_TIMEOUT: &job_timeout 30 + # The oldest supported Python: runs the tools, type checks and release checks. TOOL_PYTHON_VERSION: "3.11" - COVERAGE_PYTHON: "3.14" HATCH_VERSION: "1.18.2" UV_VERSION: "0.13.9" - DISTRIBUTION_NAME: "rocheometry" - IMPORT_NAME: "rocheometry" - DOCS_ENABLED: "true" - DOCS_DIR: "site" concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -35,7 +30,7 @@ jobs: runs-on: *runner timeout-minutes: *job_timeout steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 persist-credentials: false @@ -63,10 +58,9 @@ jobs: timeout-minutes: *job_timeout outputs: matrix: ${{ steps.matrix.outputs.matrix }} - coverage_env: ${{ steps.matrix.outputs.coverage_env }} coverage_python: ${{ steps.matrix.outputs.coverage_python }} steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false @@ -107,19 +101,13 @@ jobs: if not rows: raise SystemExit("No Python versions found in the Hatch test matrix") - coverage = next( - ( - row - for row in rows - if row["python"] == os.environ["COVERAGE_PYTHON"] - ), - rows[0], - ) + # Coverage is measured on one Python only, the newest: its tracer + # (sys.monitoring with branches, 3.14+) has the lowest overhead. + coverage = max(rows, key=lambda row: tuple(map(int, row["python"].split(".")))) with open(os.environ["GITHUB_OUTPUT"], "a") as output: matrix = json.dumps({"include": rows}, separators=(",", ":")) print(f"matrix={matrix}", file=output) - print(f"coverage_env={coverage['environment']}", file=output) print(f"coverage_python={coverage['python']}", file=output) PY @@ -135,7 +123,7 @@ jobs: matrix: ${{ fromJSON(needs.discover-tests.outputs.matrix) }} steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: # Required for hatch-vcs to resolve the version from tags fetch-depth: 0 @@ -154,11 +142,8 @@ jobs: - name: Install hatch run: uv tool install "hatch==$HATCH_VERSION" - # Coverage is measured on one Python only: its low-overhead tracer - # (sys.monitoring with branches, 3.14+) takes the default tier in about - # 15 minutes, where the other tracers take close to an hour. - name: Run tests with coverage - if: matrix.python == env.COVERAGE_PYTHON + if: matrix.python == needs.discover-tests.outputs.coverage_python env: TEST_ENVIRONMENT: ${{ matrix.environment }} TEST_PYTHON: ${{ matrix.python }} @@ -167,75 +152,13 @@ jobs: hatch run "$TEST_ENVIRONMENT:cov-report-markdown" >> "$GITHUB_STEP_SUMMARY" - name: Run tests - if: matrix.python != env.COVERAGE_PYTHON + if: matrix.python != needs.discover-tests.outputs.coverage_python env: TEST_PYTHON: ${{ matrix.python }} run: hatch test -vv --python "$TEST_PYTHON" --parallel - - name: Rename coverage files - if: matrix.python == env.COVERAGE_PYTHON - env: - TEST_PYTHON: ${{ matrix.python }} - run: | - shopt -s nullglob - files=(.coverage*) - if ((${#files[@]} == 0)); then - echo "No coverage files found" >&2 - exit 1 - fi - for f in "${files[@]}"; do - mv "$f" "$f.$TEST_PYTHON" - done - - - name: Upload coverage files - if: matrix.python == env.COVERAGE_PYTHON - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 - with: - name: coverage-${{ matrix.python }} - path: .coverage* - compression-level: 0 - include-hidden-files: true - if-no-files-found: ignore - - coverage: - name: Coverage report - if: github.ref_type != 'tag' - runs-on: *runner - timeout-minutes: *job_timeout - needs: [discover-tests, test] - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - with: - fetch-depth: 0 - persist-credentials: false - - - uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0 - with: - version: ${{ env.UV_VERSION }} - enable-cache: ${{ !startsWith(github.ref, 'refs/tags/') }} # zizmor: ignore[cache-poisoning] disabled for release tags - - - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 - with: - python-version: ${{ needs.discover-tests.outputs.coverage_python }} - - - name: Install hatch - run: uv tool install "hatch==$HATCH_VERSION" - - - name: Download coverage artifacts - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 - with: - pattern: coverage* - merge-multiple: true - - - name: Combine and report - env: - COVERAGE_ENVIRONMENT: ${{ needs.discover-tests.outputs.coverage_env }} - run: | - hatch run "$COVERAGE_ENVIRONMENT:cov-combine" - hatch run "$COVERAGE_ENVIRONMENT:cov-report" - hatch run "$COVERAGE_ENVIRONMENT:cov-report-markdown" >> "$GITHUB_STEP_SUMMARY" - - - name: Upload HTML report + - name: Upload HTML coverage report + if: matrix.python == needs.discover-tests.outputs.coverage_python uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: name: coverage-report @@ -246,7 +169,7 @@ jobs: runs-on: *runner timeout-minutes: *job_timeout steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false @@ -270,7 +193,7 @@ jobs: runs-on: *runner timeout-minutes: *job_timeout steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 persist-credentials: false @@ -301,47 +224,36 @@ jobs: if: github.ref_type != 'tag' runs-on: *runner timeout-minutes: *job_timeout - outputs: - enabled: ${{ steps.config.outputs.enabled }} steps: - - name: Read docs configuration - id: config - run: echo "enabled=$DOCS_ENABLED" >> "$GITHUB_OUTPUT" - - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - if: steps.config.outputs.enabled == 'true' + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 persist-credentials: false - uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0 - if: steps.config.outputs.enabled == 'true' with: version: ${{ env.UV_VERSION }} enable-cache: ${{ !startsWith(github.ref, 'refs/tags/') }} # zizmor: ignore[cache-poisoning] disabled for release tags - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 - if: steps.config.outputs.enabled == 'true' with: python-version: ${{ env.TOOL_PYTHON_VERSION }} - name: Install hatch - if: steps.config.outputs.enabled == 'true' run: uv tool install "hatch==$HATCH_VERSION" - name: Build docs - if: steps.config.outputs.enabled == 'true' run: hatch run docs:build - name: Upload Pages artifact - if: steps.config.outputs.enabled == 'true' && github.event_name == 'push' && github.ref == 'refs/heads/main' - uses: actions/upload-pages-artifact@7b1f4a764d45c48632c6b24a0339c27f5614fb0b # v4 + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + uses: actions/upload-pages-artifact@7b1f4a764d45c48632c6b24a0339c27f5614fb0b # v4.0.0 with: - path: ${{ env.DOCS_DIR }} + path: site pages: name: Deploy docs - if: needs.docs.outputs.enabled == 'true' && github.event_name == 'push' && github.ref == 'refs/heads/main' + if: github.event_name == 'push' && github.ref == 'refs/heads/main' needs: docs runs-on: *runner timeout-minutes: *job_timeout @@ -354,7 +266,7 @@ jobs: steps: - name: Deploy to GitHub Pages id: deployment - uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4 + uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5 release-checks: name: Release checks @@ -362,7 +274,7 @@ jobs: runs-on: *runner timeout-minutes: 120 steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 persist-credentials: false @@ -393,8 +305,10 @@ jobs: runs-on: *runner timeout-minutes: *job_timeout needs: [precommit, test, accuracy-smoke, evidence] + outputs: + distribution_name: ${{ steps.project.outputs.name }} steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 persist-credentials: false @@ -411,6 +325,19 @@ jobs: - name: Install hatch run: uv tool install "hatch==$HATCH_VERSION" + - name: Read project name + id: project + run: | + python - <<'PY' + import os + import tomllib + from pathlib import Path + + project = tomllib.loads(Path("pyproject.toml").read_text())["project"] + with open(os.environ["GITHUB_OUTPUT"], "a") as output: + print(f"name={project['name']}", file=output) + PY + - name: Validate release tag if: github.ref_type == 'tag' env: @@ -432,6 +359,8 @@ jobs: - name: Extract release notes if: github.ref_type == 'tag' + env: + DISTRIBUTION_NAME: ${{ steps.project.outputs.name }} run: | mkdir -p release-notes awk -v heading="## [$GITHUB_REF_NAME]" ' @@ -472,18 +401,37 @@ jobs: assert "rocheometry/_data/surface-potential-map.json" in wheel.namelist() PY - - name: Smoke-test release wheel - if: github.ref_type == 'tag' + # Runs on every build, so packaging problems show up before a release. + # Only a release tag also checks the version against the tag. + - name: Smoke-test wheel + env: + TAG: ${{ github.ref_type == 'tag' && github.ref_name || '' }} run: | uv venv --python "$TOOL_PYTHON_VERSION" /tmp/package-smoke uv pip install --python /tmp/package-smoke/bin/python dist/*.whl - TAG="$GITHUB_REF_NAME" /tmp/package-smoke/bin/python - <<'PY' + /tmp/package-smoke/bin/python - <<'PY' import os + from email.parser import HeaderParser from importlib import import_module from importlib.metadata import version + from pathlib import Path + from zipfile import ZipFile - assert version(os.environ["DISTRIBUTION_NAME"]) == os.environ["TAG"] - import_module(os.environ["IMPORT_NAME"]) + # Both names come from the wheel's own metadata (PEP 794 Import-Name). + (wheel,) = Path("dist").glob("*.whl") + with ZipFile(wheel) as zf: + (meta,) = [n for n in zf.namelist() if n.endswith(".dist-info/METADATA")] + metadata = HeaderParser().parsestr(zf.read(meta).decode()) + + name = metadata["Name"] + import_names = [ + n.split(";")[0].strip() for n in metadata.get_all("Import-Name", []) + ] + assert import_names, f"{wheel.name} has no Import-Name: set import-names" + if os.environ["TAG"]: + assert version(name) == os.environ["TAG"], (version(name), os.environ["TAG"]) + for import_name in import_names: + import_module(import_name) PY - name: Upload release distributions @@ -535,7 +483,7 @@ jobs: runs-on: *runner environment: name: pypi - url: https://pypi.org/project/rocheometry/ + url: ${{ format('https://pypi.org/project/{0}/', needs.build.outputs.distribution_name) }} timeout-minutes: *job_timeout needs: [build, release-checks] permissions: @@ -556,7 +504,7 @@ jobs: if: github.ref_type == 'tag' runs-on: *runner timeout-minutes: *job_timeout - needs: pypi + needs: [build, pypi] permissions: contents: write steps: @@ -576,6 +524,7 @@ jobs: env: GH_TOKEN: ${{ github.token }} GH_REPO: ${{ github.repository }} + DISTRIBUTION_NAME: ${{ needs.build.outputs.distribution_name }} run: | gh release create "$GITHUB_REF_NAME" dist/* \ --title "$DISTRIBUTION_NAME $GITHUB_REF_NAME" \ diff --git a/.github/workflows/verification.yml b/.github/workflows/verification.yml index cd4be3a..6368f0a 100644 --- a/.github/workflows/verification.yml +++ b/.github/workflows/verification.yml @@ -33,7 +33,7 @@ jobs: runs-on: *runner timeout-minutes: 180 steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 persist-credentials: false @@ -58,7 +58,7 @@ jobs: runs-on: *runner timeout-minutes: 60 steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false @@ -83,7 +83,7 @@ jobs: timeout-minutes: 90 continue-on-error: true steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false diff --git a/.gitignore b/.gitignore index b6f0f0f..176c3f7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,22 +1,226 @@ +# Byte-compiled / optimized / DLL files __pycache__/ -*.py[cod] +*.py[codz] +*$py.class + +# C extensions *.so -*.egg-info/ + +# Distribution / packaging +.Python build/ +develop-eggs/ dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ .coverage .coverage.* -htmlcov/ -.pytest_cache/ -.ruff_cache/ -.pyrefly_cache/ -.mypy_cache/ +.cache +nosetests.xml +coverage.xml +*.cover +*.py.cover +*.lcov .hypothesis/ -.venv/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +# Pipfile.lock + +# UV +# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# uv.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +# poetry.lock +# poetry.toml + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python. +# https://pdm-project.org/en/latest/usage/project/#working-with-version-control +# pdm.lock +# pdm.toml +.pdm-python +.pdm-build/ + +# pixi +# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control. +# pixi.lock +# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one +# in the .venv directory. It is recommended not to include this directory in version control. +.pixi/* +!.pixi/config.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule* +celerybeat.pid + +# Redis +*.rdb +*.aof +*.pid + +# RabbitMQ +mnesia/ +rabbitmq/ +rabbitmq-data/ + +# ActiveMQ +activemq-data/ + +# SageMath parsed files +*.sage.py + +# Environments +.env +.envrc +.venv +env/ venv/ -.ipynb_checkpoints/ -.DS_Store -.cache/ -src/rocheometry/_version.py +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject +# Rope project settings +.ropeproject + +# mkdocs documentation /site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +# .idea/ + +# Abstra +# Abstra is an AI-powered process automation framework. +# Ignore directories containing user credentials, local state, and settings. +# Learn more at https://abstra.io/docs +.abstra/ + +# Visual Studio Code +# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore +# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore +# and can be added to the global gitignore or merged into this file. However, if you prefer, +# you could uncomment the following to ignore the entire vscode folder +# .vscode/ +# Temporary file for partial code execution +tempCodeRunnerFile.py + +# Ruff stuff: +.ruff_cache/ + +# PyPI configuration file +.pypirc + +# Marimo +marimo/_static/ +marimo/_lsp/ +__marimo__/ + +# Streamlit +.streamlit/secrets.toml + +src/rocheometry/_version.py + +# Not covered above +.pyrefly_cache/ +.DS_Store diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ec684b6..de524b0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,7 +21,8 @@ repos: - id: mixed-line-ending - id: name-tests-test args: [--pytest-test-first] - exclude: ^tests/(.*/)?_[^/]+\.py$ + # Test helper modules start with an underscore + exclude: ^tests/(.*/)?_[^/]*\.py$ - id: trailing-whitespace args: [--markdown-linebreak-ext=md] diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..f64b4af --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,3 @@ +# Agent instructions + +Follow the [contributor guide](docs/CONTRIBUTING.md), in particular [running commands](docs/CONTRIBUTING.md#running-commands). diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 7f1ce9e..7be951f 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +### Added + +- `Import-Name` package metadata ([PEP 794](https://peps.python.org/pep-0794/)), declaring `rocheometry` as the import name + ## [0.1.0] - 2026-11-17 ### Added diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index f9e57e9..d4dda4f 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -10,6 +10,23 @@ Contributions can include: - Adding or improving tests - Making code changes +This guide covers: + +- [Raising issues](#raising-issues) + - [Reporting bugs](#reporting-bugs) + - [Suggesting changes](#suggesting-changes) +- [Making changes](#making-changes) + - [Setting up your environment](#setting-up-your-environment) + - [Working on a branch](#working-on-a-branch) + - [Changing documentation](#changing-documentation) + - [Changing code](#changing-code) + - [Checking your changes](#checking-your-changes) + - [Opening a pull request](#opening-a-pull-request) +- [Maintaining the project](#maintaining-the-project) + - [Releasing a version](#releasing-a-version) + - [Updating from the template](#updating-from-the-template) +- [Running commands](#running-commands) + ## Raising issues Use GitHub issues to report bugs or suggest changes. @@ -49,7 +66,9 @@ Where useful, include: For substantial changes, please raise an issue before starting implementation, so that any decisions can be made before significant work is done. -## Prerequisites +## Making changes + +### Setting up your environment For code contributions you will need: @@ -57,13 +76,11 @@ For code contributions you will need: - A development environment with: - Python 3.11 (the minimum version of Python supported) - - `hatch>=1.17` + - `hatch>=1.18` - Access to the internet for GitHub and installation of packages from PyPI If Hatch is not available in your development environment, see the [Hatch installation instructions](https://hatch.pypa.io/latest/install/). -## Setup - The project uses Hatch to manage Python environments for development. To set up your development environment, run @@ -72,7 +89,7 @@ To set up your development environment, run hatch run pre-commit:install ``` -## Workflow +### Working on a branch To make a contribution: @@ -86,22 +103,29 @@ To make a contribution: Keep pull requests focused on a single change where practical. Unrelated changes are easier to review when submitted separately. -### Release evidence - -The [release results](https://github.com/pdhall99/rocheometry/tree/main/accuracy/results) record the run that measured the library, including a hash of the code it measured. -A release is published only when that hash matches the release commit's code, so any change to code in `src/` needs a complete release run from a clean checkout (`hatch run accuracy:run`) before the next release. -Comments, formatting and docstrings do not count. -Changing a numerical constant, a numerical path or a packaged fit also means re-recording the fingerprints. -Observations and checkpoints are never reused. -A failed holdout is reported without retuning. -Numerical and contract changes are reviewed separately. - Documentation-only and other non-code contributions can use the same workflow. Only the checks and definition-of-done items relevant to the change need to apply. -### During development +### Changing documentation + +#### Writing Markdown -#### Testing +Write Markdown prose with one sentence per source line. + +#### Building the docs + +The documentation site is built with Zensical from `docs/site/`. + +To preview the site while you edit it, and to build it as CI does, run + +```shell +hatch run docs:serve # Serve the site locally, rebuilding it as files change +hatch run docs:build # Build the site into site/ +``` + +### Changing code + +#### Running tests `hatch test` passes any arguments after its own flags through to `pytest`, so during development you can narrow to one file or test rather than running the full matrix each time: @@ -116,7 +140,8 @@ Use these commands for a fast iterative development loop. Run the full `hatch test --all` matrix before opening a pull request. -Tests mirror `src/rocheometry/`. +The `tests/` directory should mirror the package structure under `src/rocheometry/`. +Test modules are named `test_*.py`; name helper modules in `tests/` with a leading underscore, such as `_helpers.py`. Building and checking the packaged fits is in `fits/`, and accuracy studies over the whole domain are in `accuracy/`, not pytest. #### Adding dependencies @@ -125,7 +150,23 @@ Add dependencies in `pyproject.toml`. The core package is intentionally dependency-free; a new runtime dependency requires a design-level justification. -### Checks +#### Recording release evidence + +The [release results](https://github.com/pdhall99/rocheometry/tree/main/accuracy/results) record the run that measured the library, including a hash of the code it measured. +A release is published only when that hash matches the release commit's code, so any change to code in `src/` needs a complete release run from a clean checkout (`hatch run accuracy:run`) before the next release. +Comments, formatting and docstrings do not count. +Changing a numerical constant, a numerical path or a packaged fit also means re-recording the fingerprints. +Observations and checkpoints are never reused. +A failed holdout is reported without retuning. +Numerical and contract changes are reviewed separately. + +#### Writing docstrings + +Use concise Google-style docstrings. +Let annotations carry types and signatures carry ordinary defaults. +Avoid boilerplate documentation that merely repeats the signature. + +### Checking your changes Pull requests must pass checks in CI before they can be merged into main. @@ -149,12 +190,105 @@ After running the commands, review and commit the resulting changes — otherwis A clean run that leaves no changes means there was nothing to fix. -### Definition of done +### Opening a pull request + +Pull requests are squash-merged, with the pull request title as the commit message. +Write the title as a short summary of the change in the imperative, such as "Add support for X". Changes are ready for review when all applicable items below are complete: - Relevant tests have been added or updated in the `tests/` directory - Relevant documentation has been added to or updated in the `docs/` directory - Relevant Google-style docstrings have been added or updated +- User-facing changes are recorded under `## [Unreleased]` in `docs/CHANGELOG.md` - All applicable checks above pass - Generated fixes from linting or formatting checks have been committed + +Record changes in `docs/CHANGELOG.md` under the [Keep a Changelog](https://keepachangelog.com/) headings `Added`, `Changed`, `Deprecated`, `Removed`, `Fixed` and `Security`. +Record only changes that affect users of the package, including changes to the supported Python versions. + +## Maintaining the project + +### Releasing a version + +Maintainers make releases by pushing a version tag to `main`. +CI does the rest: nothing is built or uploaded by hand. + +1. Choose the version number, `X.Y.Z`, following [Semantic Versioning](https://semver.org/). +2. In a pull request, move the unreleased changes in `docs/CHANGELOG.md` into a section for the release, and merge it: + + - Rename `## [Unreleased]` to `## [X.Y.Z] - YYYY-MM-DD`, and add a new, empty `## [Unreleased]` above it + - Update the links at the end of the file, for example for a first release: + + ```markdown + [Unreleased]: https://github.com/pdhall99/rocheometry/compare/0.1.0...HEAD + [0.1.0]: https://github.com/pdhall99/rocheometry/releases/tag/0.1.0 + ``` + + For later releases, compare `[Unreleased]` with the new version, and the new version with the previous one: + + ```markdown + [Unreleased]: https://github.com/pdhall99/rocheometry/compare/0.2.0...HEAD + [0.2.0]: https://github.com/pdhall99/rocheometry/compare/0.1.0...0.2.0 + ``` +3. Tag the merged commit on `main`, and push the tag: + + ```shell + git switch main + git pull + git tag X.Y.Z + git push origin X.Y.Z + ``` + + Tags are plain `X.Y.Z`, without a `v` prefix: the package version comes from the tag. +4. Follow the tag's CI run. + It checks the tag is `X.Y.Z` and on `main`, runs the checks and tests, builds the package, and checks the wheel's version matches the tag. +5. If the `pypi` environment requires approval, approve the deployment in the run (**Review deployments**). + CI then publishes to PyPI, and creates a GitHub release with the changelog section as its notes and the built package attached. + +If the run fails before publishing, for example because `docs/CHANGELOG.md` has no section for the tag, fix the problem through a pull request, then move the tag to the fixed commit: + +```shell +git push --delete origin X.Y.Z +git switch main +git pull +git tag --force X.Y.Z +git push origin X.Y.Z +``` + +Once a version is on PyPI it cannot be uploaded again, so release any fix as a new version. + +### Updating from the template + +This project was generated from a [Copier](https://copier.readthedocs.io/) template, recorded with your answers to its questions in `.copier-answers.yml`. + +To apply a newer version of the template, run + +```shell +uvx copier update --defaults +``` + +Review the changes and resolve any conflicts, where the project has changed the same lines as the template, then commit them through a pull request. + +A template update can change the supported Python versions; record any change to them in `docs/CHANGELOG.md`. + +## Running commands + +Run every development command through Hatch, which manages the environments for the project: don't install packages with `pip` or run tools such as `pytest` or `ruff` directly. + +- Don't skip pre-commit hooks or checks, for example with `git commit --no-verify` +- Don't edit `src/rocheometry/_version.py`: it is generated from the git tag +- Commit any changes the checks make, as described in [checking your changes](#checking-your-changes) + +```shell +hatch run pre-commit:install # Set up the pre-commit hooks +hatch test # Run the tests on the default version of Python +hatch test --all # Run the tests on every version of Python in the matrix +hatch check code --fix # Check and fix linting and formatting +hatch check types # Check type annotations +hatch run pre-commit:ci # Run all pre-commit hooks +hatch run accuracy:smoke # Run every accuracy study on one small job +hatch run docs:serve # Serve the documentation site locally +hatch run docs:build # Build the documentation site +hatch build # Build the package +``` diff --git a/pyproject.toml b/pyproject.toml index e0774d0..4ce7ad8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,12 +1,13 @@ # [build-system] [build-system] build-backend = "hatchling.build" -requires = [ "hatch-vcs", "hatchling" ] +requires = [ "hatch-vcs", "hatchling>=1.32" ] # -------------------------------------------------------------------------------------- # [project] [project] name = "rocheometry" +import-names = [ "rocheometry" ] description = """\ Compute the equipotential geometry of binary systems in the classical Roche model\ """ @@ -76,7 +77,7 @@ test = [ "coverage-enable-subprocess==1", "hypothesis~=6.0", "pytest~=9.0", - "pytest-mock~=3.10", + "pytest-mock~=3.12", "pytest-randomly~=5.0", "pytest-rerunfailures~=16.0", "pytest-sugar", @@ -120,6 +121,9 @@ speed = [] # -------------------------------------------------------------------------------------- # [tool.hatch] +[tool.hatch] +requires-hatch = ">=1.18" + [tool.hatch.version.raw-options] version_scheme = "no-guess-dev" local_scheme = "no-local-version" @@ -243,12 +247,19 @@ dependency-groups = [ "check-types" ] hooks = "pre-commit run --all-files {args}" types = "pyrefly check {args}" +[tool.hatch.envs.notebook] +dependencies = [ "ipywidgets", "jupyterlab", "pip" ] + +[tool.hatch.envs.notebook.scripts] +lab = "jupyter lab" + [tool.hatch.envs.plot] python = "3.11" installer = "uv" features = [ "plot" ] [tool.hatch.envs.pre-commit] +detached = true skip-install = true dependencies = [ "pre-commit" ] @@ -368,7 +379,17 @@ errors = { implicit-any-empty-container = "ignore" } # -------------------------------------------------------------------------------------- # [tool.pytest] -[tool.pytest.ini_options] +[tool.pytest] +# The slow tier is opt-in: `hatch test -- -m slow` overrides this selection. +addopts = [ "-ra", "-q", "--doctest-modules", "--doctest-glob=*.md", "-m", "not slow" ] +filterwarnings = [ "error" ] +log_level = "INFO" +markers = [ "slow: numerical sweeps with independent integration references" ] +minversion = "9.0" +# The crosschecks and the tools (accuracy, fits, speed) are imported from the +# checkout. +pythonpath = [ "." ] +strict = true testpaths = [ "tests", "crosschecks/tests", @@ -377,12 +398,6 @@ testpaths = [ "README.md", "docs/site", ] -# The crosschecks and the tools (accuracy, fits, speed) are imported from the -# checkout. -pythonpath = [ "." ] -# The slow tier is opt-in: `hatch test -- -m slow` overrides this selection. -addopts = "-ra -q --doctest-modules --doctest-glob='*.md' -m 'not slow'" -markers = [ "slow: numerical sweeps with independent integration references" ] # -------------------------------------------------------------------------------------- # [tool.coverage] diff --git a/tests/computers/lobe_slope/test_sampled.py b/tests/computers/lobe_slope/test_sampled.py index 4b9dcb8..79cef83 100644 --- a/tests/computers/lobe_slope/test_sampled.py +++ b/tests/computers/lobe_slope/test_sampled.py @@ -65,7 +65,11 @@ def test_default_lobe_slope_agrees_with_reference(qi: float) -> None: assert actual == pytest.approx(reference, abs=1e-6, rel=0) -@pytest.mark.parametrize("factory", [Fitted()._computers, Reference()._computers]) +@pytest.mark.parametrize( + "factory", + [Fitted()._computers, Reference()._computers], + ids=["fitted", "reference"], +) def test_lobe_slopes_stay_within_hill_limit_and_decrease_strictly( factory: Callable[[], ComputerSet], ) -> None: diff --git a/tests/computers/surface_selection/test_volume_inversion.py b/tests/computers/surface_selection/test_volume_inversion.py index cdb74d0..d6a7417 100644 --- a/tests/computers/surface_selection/test_volume_inversion.py +++ b/tests/computers/surface_selection/test_volume_inversion.py @@ -145,7 +145,9 @@ def volume(field: RocheField, level: float, /) -> float: @pytest.mark.parametrize( - "factory", [rocheometry.Fitted()._computers, rocheometry.Reference()._computers] + "factory", + [rocheometry.Fitted()._computers, rocheometry.Reference()._computers], + ids=["fitted", "reference"], ) @pytest.mark.parametrize("qi", [0.03, 1.0, 4.0]) def test_fill_potential_round_trips_and_exact_endpoints( diff --git a/tests/test_package.py b/tests/test_package.py new file mode 100644 index 0000000..7be19bf --- /dev/null +++ b/tests/test_package.py @@ -0,0 +1,2 @@ +def test_import() -> None: + __import__("rocheometry")