Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to using copier template #14

Merged
merged 6 commits into from
Sep 26, 2024
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: 15 additions & 0 deletions .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY
_commit: v0.4.1
_src_path: gl:znicholls/copier-core-python-repository
email: [email protected]
include_cli: true
name: Zebedee Nicholls
notebook_based_docs: true
pandas_doctests: false
plot_dependencies: false
project_description_short: Command-line tool for uploading to zenodo.
project_name_human: OpenSCM Zenodo
project_name_pip: openscm-zenodo
project_name_python: openscm_zenodo
project_url: https://github.com/openscm/OpenSCM-zenodo
track_lock_file: true
1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/bug.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def test_bug_12():

- OS: [e.g. Windows, Linux, macOS]
- Python version [e.g. Python 3.11]
- Please also upload your `poetry.lock` file (first run `poetry lock` to make sure the lock file is up-to-date)

## Additional context
<!--- Add any other context about the problem here. -->
23 changes: 17 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: ./.github/actions/setup
with:
python-version: "3.11"
pdm-dependency-install-flags: "-G dev"
pdm-dependency-install-flags: "-G :all"
- name: mypy
run: |
MYPYPATH=stubs pdm run mypy src
Expand All @@ -30,11 +30,17 @@ jobs:
- uses: ./.github/actions/setup
with:
python-version: "3.11"
pdm-dependency-install-flags: "-G docs -G dev"
pdm-dependency-install-flags: "-G docs -G :all"
- name: docs
run: |
pdm run typer openscm_zenodo.cli utils docs --output docs/cli/index.md --name openscm-zenodo
pdm run mkdocs build --strict
- uses: ./.github/actions/setup
with:
python-version: "3.11"
pdm-dependency-install-flags: "-G docs -G :all -G dev"
- name: docs-with-changelog
run: |
# Check CHANGELOG will build too
pdm run towncrier build --yes
pdm run mkdocs build --strict
Expand All @@ -61,11 +67,16 @@ jobs:
- uses: ./.github/actions/setup
with:
python-version: ${{ matrix.python-version }}
pdm-dependency-install-flags: "-G tests"
# TODO: sort out zenodo token
# When running the tests, install with all optional dependencies
# to get maximum test coverage.
# If we find that we're getting failures
# when people try to run without installing optional dependencies,
# we should add a CI step that runs the tests without optional dependencies too.
# We don't have that right now, because we're not sure this pain point exists.
pdm-dependency-install-flags: "-G :all -G tests"
- name: Run tests
run: |
pdm run pytest -r a -v src tests --doctest-modules
pdm run pytest -r a -v src tests
- name: Run tests with zenodo token
# Only run these on one machine to avoid CI fighting each other by modifying the same Zenodo record
if: ${{ (matrix.python-version == '3.11') && (matrix.os == 'ubuntu-latest') }}
Expand All @@ -90,7 +101,7 @@ jobs:
- uses: ./.github/actions/setup
with:
python-version: ${{ matrix.python-version }}
pdm-dependency-install-flags: "--prod"
pdm-dependency-install-flags: "--prod --without :all"
- name: Check importable without extras
run: pdm run python scripts/test-install.py

Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ defaults:
jobs:
deploy-pypi:
name: Deploy to PyPI
# Having an environment for deployment is strongly recommend by PyPI
# https://docs.pypi.org/trusted-publishers/adding-a-publisher/#github-actions
# You can comment this line out if you don't want it.
environment: deploy
runs-on: ubuntu-latest
permissions:
# this permission is mandatory for trusted publishing with PyPI
Expand Down
27 changes: 24 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
# Notebooks
*.ipynb

# Auto-generated docs and helper files
docs/api/*
!docs/api/.gitkeep
docs/cli/*
!docs/cli/.gitkeep

# pdm stuff
.pdm-python

# CI stuff
pdm-install-flags.txt
# Databases
*.db

# Jupyter cache
.jupyter_cache

# licence check
# IDE stuff
.idea/

# Ruff cache
.ruff_cache

# Licence check
licence-check.txt

# Byte-compiled / optimized / DLL files
Expand Down Expand Up @@ -136,3 +154,6 @@ dmypy.json

# Pyre type checker
.pyre/

# Mac stuff
*.DS_Store
22 changes: 13 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ ci:
autofix_prs: false
autoupdate_schedule: quarterly
autoupdate_branch: pre-commit-autoupdate
# Skip steps that won't run on pre-commit CI for various reasons,
# mostly because they rely on local things.
skip: [ ]
# Currently network access isn't supported in the pre-commit CI product.
skip: [pdm-lock-check, pdm-export, pdm-sync]

# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: 'v4.5.0'
rev: "v4.5.0"
hooks:
- id: check-added-large-files
- id: check-ast
Expand All @@ -34,7 +33,7 @@ repos:
language: fail
files: "\\.rej$"
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.1.8'
rev: "v0.1.8"
hooks:
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]
Expand All @@ -43,10 +42,15 @@ repos:
rev: 2.17.0
hooks:
# Check that the lock file is up to date.
# We need the pdm lock file too
# so that we can build locked version of the package.
- id: pdm-lock-check
args: [ --dev, --group, ":all" ]
# Put a requirements.txt file in the repo too
args: ["--dev", "-G", ":all", "--strategy", "inherit_metadata" ]
# Put requirements.txt files in the repo too
- id: pdm-export
args: ['--prod', '-o', 'requirements.txt', '--without-hashes']
name: export-requirements
args: ["-o", "requirements-locked.txt", "--without-hashes", "--prod"]
- id: pdm-export
name: export-requirements-docs
args: ["-o", "requirements-docs-locked.txt", "--without-hashes", "-G", ":all", "-G", "docs"]
- id: pdm-sync
args: [ -G, ":all" ]
9 changes: 2 additions & 7 deletions .readthedocs.yml → .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Thank you also https://browniebroke.com/blog/specify-docs-dependency-groups-with-poetry-and-read-the-docs/

# Required
version: 2

Expand All @@ -13,13 +11,10 @@ build:
tools:
python: "3.11"
jobs:
post_create_environment:
- pip install pdm
post_install:
# RtD seems to be not happy with poetry installs,
# RtD seems to be not happy with pdm installs,
# hence use pip directly instead.
- pdm export -f requirements --output requirements.txt --with docs
- python -m pip install -r requirements.txt
- python -m pip install -r requirements-docs-locked.txt
- python -m pip list
pre_build:
- pip install --no-deps .
Expand Down
38 changes: 21 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,30 @@ checks: ## run all the linting checks of the codebase
ruff-fixes: ## fix the code using ruff
# format before and after checking so that the formatted stuff is checked and
# the fixed stuff is formatted
pdm run ruff format src tests scripts
pdm run ruff check src tests scripts --fix
pdm run ruff format src tests scripts
pdm run ruff format src tests scripts docs
pdm run ruff check src tests scripts docs --fix
pdm run ruff format src tests scripts docs


.PHONY: test
test: ## run the tests
pdm run pytest src tests -r a -v --doctest-modules --cov=src

# Note on code coverage and testing:
# You must specify cov=src as otherwise funny things happen when doctests are
# involved.
# If you want to debug what is going on with coverage, we have found
# that adding COVERAGE_DEBUG=trace to the front of the above command
# can be very helpful as it shows you if coverage is tracking the coverage
# You must specify cov=src.
# Otherwise, funny things happen when doctests are involved.
# If you want to debug what is going on with coverage,
# we have found that adding COVERAGE_DEBUG=trace
# to the front of the below command
# can be very helpful as it shows you
# if coverage is tracking the coverage
# of all of the expected files or not.
# We are sure that the coverage maintainers would appreciate a PR that improves
# the coverage handling when there are doctests and a `src` layout like ours.
# We are sure that the coverage maintainers would appreciate a PR
# that improves the coverage handling when there are doctests
# and a `src` layout like ours.

docs/cli/index.md: src/openscm_zenodo/cli/__init__.py ## auto-generate the typer app docs
pdm run typer openscm_zenodo.cli utils docs --output docs/cli/index.md --name openscm-zenodo

.PHONY: docs
docs: docs/cli/index.md ## build the docs
Expand All @@ -63,22 +69,20 @@ docs-strict: docs/cli/index.md ## build the docs strictly (e.g. raise an error
docs-serve: docs/cli/index.md ## serve the docs locally
pdm run mkdocs serve

docs/cli/index.md: src/openscm_zenodo/cli/__init__.py ## auto-generate the typer app docs
pdm run typer openscm_zenodo.cli utils docs --output docs/cli/index.md --name openscm-zenodo

.PHONY: changelog-draft
changelog-draft: ## compile a draft of the next changelog
pdm run towncrier build --draft
pdm run towncrier build --draft --version draft

.PHONY: licence-check
licence-check: ## Check that licences of the dependencies are suitable
# Will likely fail on Windows, but Makefiles are in general not Windows
# compatible so we're not too worried
pdm export -o $(TEMP_FILE) --without=tests --without=docs --without=dev
pdm export --without=tests --without=docs --without=dev > $(TEMP_FILE)
pdm run liccheck -r $(TEMP_FILE) -R licence-check.txt
rm $(TEMP_FILE)
rm -f $(TEMP_FILE)

.PHONY: virtual-environment
virtual-environment: ## update virtual environment, create a new one if it doesn't already exist
pdm install -G :all
pdm lock --dev --group :all --strategy inherit_metadata
pdm install --dev --group :all
pdm run pre-commit install
Loading
Loading