-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from openscm/switch-to-pdm
Switch to pdm for repo management
- Loading branch information
Showing
49 changed files
with
4,164 additions
and
760 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY | ||
_commit: v0.7.0 | ||
_src_path: gl:climate-resource/copier-core-python-repository | ||
_commit: v0.4.1 | ||
_src_path: gl:znicholls/copier-core-python-repository | ||
email: [email protected] | ||
initial_setup: true | ||
include_cli: false | ||
name: Zebedee Nicholls | ||
notebook_dependencies: false | ||
notebook_based_docs: true | ||
pandas_doctests: false | ||
plot_dependencies: false | ||
project_description_short: Handling of units related to simple climate modelling. | ||
project_name_human: OpenSCM-Units | ||
project_name_pip: openscm-units | ||
project_name_python: openscm_units | ||
project_url: https://github.com/openscm/openscm-units | ||
track_lock_file: false | ||
track_lock_file: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,45 @@ | ||
name: "Setup Python and Poetry" | ||
description: "setup Python and Poetry with caches" | ||
name: "Setup Python and pdm" | ||
description: "setup Python and pdm with caches" | ||
|
||
inputs: | ||
os: | ||
description: "Operating system to use" | ||
required: false | ||
default: "ubuntu-latest" | ||
python-version: | ||
description: "Python version to use" | ||
required: true | ||
venv-id: | ||
description: "ID to identify cached environment (should be unique from other steps)" | ||
required: true | ||
poetry-dependency-install-flags: | ||
description: "Flags to pass to poetry when running `poetry install --no-interaction --no-root`" | ||
pdm-dependency-install-flags: | ||
description: "Flags to pass to pdm when running `pdm install`" | ||
required: true | ||
run-poetry-install: | ||
description: "Should we run the poetry install steps" | ||
run-pdm-install: | ||
description: "Should we run the pdm install steps" | ||
required: false | ||
default: true | ||
|
||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Install poetry | ||
- name: Write file with install flags | ||
shell: bash | ||
run: | | ||
pipx install poetry | ||
which poetry | ||
poetry --version # Check poetry installation | ||
- name: Lock poetry | ||
# Lock file is needed for the next step, | ||
# but we don't track our lock file | ||
# so we we generate one here. | ||
shell: bash | ||
run: poetry lock | ||
- name: Set up Python ${{ inputs.python-version }} | ||
id: setup-python | ||
uses: actions/setup-python@v5 | ||
echo "${{ inputs.pdm-dependency-install-flags }}" > pdm-install-flags.txt | ||
- name: Setup PDM | ||
id: setup-pdm | ||
uses: pdm-project/[email protected] | ||
with: | ||
python-version: ${{ inputs.python-version }} | ||
cache: poetry | ||
- name: Set Poetry environment | ||
shell: bash | ||
run: | | ||
# This line used to be needed, but seems to have been | ||
# sorted with newer poetry versions. We can still check whether | ||
# the right version of python is used by looking at the output of | ||
# `poetry run which python` below and whether the right version | ||
# of python is used in the tests (or whatever step is being done) | ||
# poetry env use "python${{ inputs.python-version }}" | ||
poetry config virtualenvs.create true | ||
poetry config virtualenvs.in-project true | ||
cache: true | ||
cache-dependency-path: | | ||
./pdm.lock | ||
./pdm-install-flags.txt | ||
- name: Install dependencies | ||
if: ${{ (inputs.run-poetry-install == 'true') && (steps.setup-python.outputs.cache-hit != 'true') }} | ||
shell: bash | ||
if: ${{ (inputs.run-pdm-install == 'true') && (steps.setup-pdm.outputs.cache-hit != 'true') }} | ||
run: | | ||
poetry install --no-interaction --no-root ${{ inputs.poetry-dependency-install-flags }} | ||
pdm install --no-self ${{ inputs.pdm-dependency-install-flags }} | ||
# Now run same command but let the package install too | ||
- name: Install package | ||
# To ensure that the package is always installed, this step is run even if the cache was hit | ||
if: ${{ inputs.run-poetry-install == 'true' }} | ||
shell: bash | ||
# To ensure that the package is always installed, this step is run even if the cache was hit | ||
if: ${{ inputs.run-pdm-install == 'true' }} | ||
run: | | ||
poetry install --no-interaction ${{ inputs.poetry-dependency-install-flags }} | ||
poetry run python --version # Check python version just in case | ||
pdm install ${{ inputs.pdm-dependency-install-flags }} | ||
pdm run which python | ||
pdm run python --version # Check python version just in case |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,3 @@ | ||
## Announcements | ||
|
||
* Announcement 1 | ||
|
||
## Changes | ||
|
||
* Change 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,15 +5,17 @@ on: | |
inputs: | ||
bump_rule: | ||
type: choice | ||
description: How to bump the project's version (see https://python-poetry.org/docs/cli/#version) | ||
description: How to bump the project's version (see https://github.com/carstencodes/pdm-bump#usage) | ||
options: | ||
- patch | ||
- no-pre-release | ||
# no micro because we always sit on a pre-release in main, | ||
# so we would always use no-pre-release instead of micro | ||
# - micro | ||
- minor | ||
- major | ||
- prepatch | ||
- preminor | ||
- premajor | ||
- prerelease | ||
- "pre-release --pre alpha" | ||
- "pre-release --pre beta" | ||
- "pre-release --pre release-candidate" | ||
required: true | ||
|
||
jobs: | ||
|
@@ -24,44 +26,58 @@ jobs: | |
env: | ||
CI_COMMIT_EMAIL: "[email protected]" | ||
steps: | ||
- name: Check out repository | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
token: "${{ secrets.PERSONAL_ACCESS_TOKEN }}" | ||
|
||
# towncrier imports the package as part of building so we have to | ||
# install the pacakage (to keep things slim, we only install the main | ||
# dependencies, which also means that we get a test that we can import | ||
# the package with only the compulsory dependencies installed for free) | ||
- uses: ./.github/actions/setup | ||
- name: Setup PDM | ||
uses: pdm-project/setup-pdm@v4 | ||
with: | ||
python-version: "3.11" | ||
venv-id: "bump" | ||
poetry-dependency-install-flags: "--only main" | ||
python-version: "3.9" | ||
|
||
- name: Install towncrier | ||
- name: Install pdm-bump | ||
run: | | ||
poetry run pip install towncrier | ||
pdm self add pdm-bump | ||
- name: Create bump and changelog | ||
- uses: ./.github/actions/setup | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
pdm-dependency-install-flags: "-G dev" | ||
|
||
- name: Create bump and changelog | ||
run: | | ||
git config --global user.name "$GITHUB_ACTOR" | ||
git config --global user.email "$CI_COMMIT_EMAIL" | ||
BASE_VERSION=`sed -ne 's/^version = "\([0-9\.a]*\)"/\1/p' pyproject.toml` | ||
echo "Bumping from version $BASE_VERSION" | ||
# Bump | ||
BASE_VERSION=`poetry version -s` | ||
NEW_VERSION=`poetry version -s ${{ github.event.inputs.bump_rule }}` | ||
echo "Bumping version $BASE_VERSION > $NEW_VERSION" | ||
poetry run towncrier build --yes --version v$NEW_VERSION | ||
pdm bump ${{ github.event.inputs.bump_rule }} | ||
NEW_VERSION=`sed -ne 's/^version = "\([0-9\.a]*\)"/\1/p' pyproject.toml` | ||
echo "Bumping to version $NEW_VERSION" | ||
# Build CHANGELOG | ||
pdm run towncrier build --yes --version v$NEW_VERSION | ||
# Commit, tag and push | ||
git commit -a -m "bump: version $BASE_VERSION -> $NEW_VERSION" | ||
git tag v$NEW_VERSION | ||
git push && git push --tags | ||
# Bump to alpha (so that future commits do not have the same | ||
# version as the tagged commit) | ||
BASE_VERSION=`poetry version -s` | ||
NEW_VERSION=`poetry version -s prerelease` | ||
BASE_VERSION=`sed -ne 's/^version = "\([0-9\.a]*\)"/\1/p' pyproject.toml` | ||
# Bump to pre-release of next version | ||
pdm bump pre-release --pre alpha | ||
NEW_VERSION=`sed -ne 's/^version = "\([0-9\.a]*\)"/\1/p' pyproject.toml` | ||
echo "Bumping version $BASE_VERSION > $NEW_VERSION" | ||
# Commit and push | ||
git commit -a -m "bump(pre-release): version $BASE_VERSION > $NEW_VERSION" | ||
git push && git push --tags | ||
git push |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,12 +15,11 @@ jobs: | |
uses: actions/checkout@v4 | ||
- uses: ./.github/actions/setup | ||
with: | ||
os: "ubuntu-latest" | ||
python-version: "3.9" | ||
venv-id: "docs" | ||
poetry-dependency-install-flags: "--all-extras --only 'main,dev'" | ||
python-version: "3.11" | ||
pdm-dependency-install-flags: "-G :all" | ||
- name: mypy | ||
run: MYPYPATH=stubs poetry run mypy src | ||
run: | | ||
MYPYPATH=stubs pdm run mypy src | ||
docs: | ||
if: ${{ !github.event.pull_request.draft }} | ||
|
@@ -30,18 +29,22 @@ jobs: | |
uses: actions/checkout@v4 | ||
- uses: ./.github/actions/setup | ||
with: | ||
os: "ubuntu-latest" | ||
python-version: "3.9" | ||
venv-id: "docs" | ||
poetry-dependency-install-flags: "--all-extras --only 'main,docs'" | ||
python-version: "3.11" | ||
pdm-dependency-install-flags: "-G docs -G :all" | ||
- name: docs | ||
# Disable warning as error on build because something weird happens | ||
# with how pint has set things up. In future, add the `-W` flag back | ||
# in here. | ||
# (see https://github.com/hgrecco/pint/blob/fc1aeba21823092007adc62fae96596e15aa0127/pint/registry.py#L109) | ||
# and how autodoc-typehints tries to then handle the types | ||
# (see https://github.com/tox-dev/sphinx-autodoc-typehints/issues/186) | ||
run: poetry run sphinx-build --keep-going -T -b html docs/source docs/build | ||
run: | | ||
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 | ||
# Just in case, undo the staged changes | ||
git restore --staged . && git restore . | ||
tests: | ||
strategy: | ||
|
@@ -52,27 +55,33 @@ jobs: | |
runs-on: "${{ matrix.os }}" | ||
defaults: | ||
run: | ||
# This might be needed for Windows and doesn't seem to affect unix-based systems | ||
# so we include it. If you have better proof of whether this is needed or not, | ||
# This might be needed for Windows | ||
# and doesn't seem to affect unix-based systems so we include it. | ||
# If you have better proof of whether this is needed or not, | ||
# feel free to update. | ||
shell: bash | ||
steps: | ||
- name: Check out repository | ||
uses: actions/checkout@v4 | ||
- uses: ./.github/actions/setup | ||
with: | ||
os: "${{ matrix.os }}" | ||
python-version: "${{ matrix.python-version }}" | ||
venv-id: "tests-${{ runner.os }}" | ||
poetry-dependency-install-flags: "--all-extras" | ||
python-version: ${{ matrix.python-version }} | ||
# 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: | | ||
poetry run pytest -r a -v src tests --doctest-modules --cov=src --cov-report=term-missing --cov-report=xml | ||
poetry run coverage report | ||
pdm run pytest -r a -v src tests --doctest-modules --cov=src --cov-report=term-missing --cov-report=xml | ||
pdm run coverage report | ||
- name: Upload coverage reports to Codecov with GitHub Action | ||
uses: codecov/[email protected] | ||
env: | ||
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | ||
|
||
imports-without-extras: | ||
strategy: | ||
fail-fast: false | ||
|
@@ -85,32 +94,30 @@ jobs: | |
uses: actions/checkout@v4 | ||
- uses: ./.github/actions/setup | ||
with: | ||
python-version: "${{ matrix.python-version }}" | ||
venv-id: "imports-without-extras-${{ runner.os }}" | ||
poetry-dependency-install-flags: "--only main" | ||
python-version: ${{ matrix.python-version }} | ||
pdm-dependency-install-flags: "--prod --without :all" | ||
- name: Check importable without extras | ||
run: poetry run python scripts/test-install.py | ||
run: pdm run python scripts/test-install.py | ||
|
||
check-build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out repository | ||
uses: actions/checkout@v4 | ||
- uses: ./.github/actions/setup | ||
- name: Setup PDM | ||
uses: pdm-project/setup-pdm@v4 | ||
with: | ||
python-version: "3.9" | ||
venv-id: "check-build-${{ runner.os }}" | ||
run-poetry-install: false | ||
poetry-dependency-install-flags: "not used" | ||
pdm-dependency-install-flags: "not-used" | ||
run-pdm-install: false | ||
- name: Build package | ||
run: | | ||
poetry build --no-interaction | ||
pdm build | ||
- name: Check build | ||
run: | | ||
tar -tvf dist/openscm_units-*.tar.gz --wildcards '*openscm_units/py.typed' | ||
tar -tvf dist/openscm_units-*.tar.gz --wildcards 'openscm_units-*/LICENCE' | ||
check-dependency-licences: | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
@@ -119,12 +126,11 @@ jobs: | |
- uses: ./.github/actions/setup | ||
with: | ||
python-version: "3.9" | ||
venv-id: "licence-check" | ||
poetry-dependency-install-flags: "--all-extras" | ||
pdm-dependency-install-flags: "-G dev" | ||
- name: Check licences of dependencies | ||
shell: bash | ||
run: | | ||
TEMP_FILE=$(mktemp) | ||
poetry export --without=tests --without=docs --without=dev > $TEMP_FILE | ||
poetry run liccheck -r $TEMP_FILE -R licence-check.txt | ||
pdm export --prod > $TEMP_FILE | ||
pdm run liccheck -r $TEMP_FILE -R licence-check.txt | ||
cat licence-check.txt |
Oops, something went wrong.