Skip to content

Commit

Permalink
Merge pull request #49 from openscm/copier-update
Browse files Browse the repository at this point in the history
Update copier
  • Loading branch information
znicholls authored Feb 7, 2024
2 parents 34100df + 164d672 commit 79eb638
Show file tree
Hide file tree
Showing 23 changed files with 233 additions and 218 deletions.
6 changes: 3 additions & 3 deletions .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Changes here will be overwritten by Copier
_commit: v0.3.0
# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY
_commit: v0.5.2
_src_path: gl:climate-resource/copier-core-python-repository
email: zebedee.nicholls@climate-energy-college.org
initial_setup: false
initial_setup: true
name: Zebedee Nicholls
notebook_dependencies: false
pandas_doctests: false
Expand Down
41 changes: 41 additions & 0 deletions .github/ISSUE_TEMPLATE/bug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
name: Bug report
about: Report a bug
title: ''
labels: bug
assignees: ''

---

## Describe the bug
<!--- A clear and concise description of what the bug is. -->

## Failing Test
<!---
Please put the code (ideally in the form of a unit test) which fails below.
e.g.
```python
def test_bug_12():
# Python code here which fails because of the bug
# This is best if other developers can simply copy and paste this test in
# order to run it
```
-->

## Expected behavior
<!--- A clear and concise description of what you expected to happen. -->

## Screenshots
<!--- If applicable, add screenshots to help explain your problem. -->

## System
<!--- Please complete the following information. -->

- 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. -->
21 changes: 21 additions & 0 deletions .github/ISSUE_TEMPLATE/default.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
name: Default
about: Report an issue or problem
title: ''
labels: triage
assignees: ''

---

## The problem
<!--- Useful to breakdown to "As a [persona], I [want to do], so that [reason] -->

## Definition of "done"
<!---
What are the things that must be true in order to close this issue
We find that describing these as dot points works well.
-->

## Additional context
<!--- Add any additional context can go here -->
29 changes: 20 additions & 9 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
---
name: Feature Request
about: Suggest an idea for this project
about: Request a feature or suggest an idea for this project
title: ''
labels: feature
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
## The motivation

A clear and concise description of what the problem is. Ex. It's annoying that I always have to [...]
<!--- Useful to breakdown to "As a [persona], I [want to do], so that [reason] -->

**Describe the solution you'd like**
## The proposed solution

A clear and concise description of the solution you would like to see.
<!---
If you'd like, please provide a description of the solution you would like to see
**Describe alternatives you've considered**
If you don't have any ideas for the solution, simply leave this blank
-->

A clear and concise description of any alternative solutions or features you've considered.
## Alternatives

**Additional context**
<!---
If you've considered any alternatives, please describe them here
Add any other context or screenshots about the feature request here.
If you don't have any alternatives, simply leave this blank
-->

## Additional context

<!--- Add any additional context can go here -->
7 changes: 4 additions & 3 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Pull request
## Description

## Checklist

Please confirm that this pull request has done the following:

- [ ] Tests added
- [ ] Documentation added (where applicable)
- [ ] Example added (either to an existing notebook or as a new notebook, where applicable)
- [ ] Added to `changelog/`
- [ ] Changelog item added to `changelog/`
52 changes: 30 additions & 22 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name: "Setup Python and Poetry"
description: "setup Python and Poetry with caches"

inputs:
os:
description: "Operating system to use"
required: false
default: "ubuntu-latest"
python-version:
description: "Python version to use"
required: true
Expand All @@ -20,38 +24,42 @@ inputs:
runs:
using: "composite"
steps:
- name: Install poetry
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
shell: bash
run: poetry lock
- name: Set up Python ${{ inputs.python-version }}
id: setup-python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}
- name: Load cached Poetry installation
id: cached-poetry
uses: actions/cache@v3
with:
path: ~/.local # the path depends on the OS
key: poetry-2 # increment to reset cache
- name: Install Poetry
if: steps.cached-poetry.outputs.cache-hit != 'true'
uses: snok/install-poetry@v1
- name: Load cached venv
if: ${{ inputs.run-poetry-install == 'true' }}
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: "venv-${{ inputs.venv-id }}-${{ inputs.python-version }}-${{ hashFiles('**/poetry.lock') }}"
# Install dependencies first so that our package doesn't appear in the cache by accident
- name: Install dependencies
if: ${{ inputs.run-poetry-install == 'true' }}
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
poetry env use ${{ inputs.python-version }}
- name: Install dependencies
if: ${{ (inputs.run-poetry-install == 'true') && (steps.setup-python.outputs.cache-hit != 'true') }}
shell: bash
run: |
poetry install --no-interaction --no-root ${{ inputs.poetry-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
run: poetry install --no-interaction ${{ inputs.poetry-dependency-install-flags }}
run: |
poetry install --no-interaction ${{ inputs.poetry-dependency-install-flags }}
poetry run python --version # Check python version just in case
17 changes: 12 additions & 5 deletions .github/workflows/bump.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,21 @@ jobs:
- name: Create bump and changelog

run: |
BASE_VERSION=`poetry version -s`
NEW_VERSION=`poetry version -s ${{ github.event.inputs.bump_rule }}`
poetry run towncrier build --yes --version v$NEW_VERSION
git config --global user.name "$GITHUB_ACTOR"
git config --global user.email "$CI_COMMIT_EMAIL"
# 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
git commit -a -m "bump: version $BASE_VERSION -> $NEW_VERSION"
git tag v$NEW_VERSION
# 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`
echo "Bumping version $BASE_VERSION > $NEW_VERSION"
git commit -a -m "bump(pre-release): version $BASE_VERSION > $NEW_VERSION"
git push && git push --tags
echo "Bumped to version $NEW_VERSION"
9 changes: 9 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
uses: actions/checkout@v3
- uses: ./.github/actions/setup
with:
os: "ubuntu-latest"
python-version: "3.9"
venv-id: "docs"
poetry-dependency-install-flags: "--all-extras --only 'main,dev'"
Expand All @@ -29,6 +30,7 @@ jobs:
uses: actions/checkout@v3
- uses: ./.github/actions/setup
with:
os: "ubuntu-latest"
python-version: "3.9"
venv-id: "docs"
poetry-dependency-install-flags: "--all-extras --only 'main,docs'"
Expand All @@ -48,11 +50,18 @@ jobs:
os: [ "ubuntu-latest" ]
python-version: [ "3.9", "3.10", "3.11" ]
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,
# feel free to update.
shell: bash
steps:
- name: Check out repository
uses: actions/checkout@v3
- uses: ./.github/actions/setup
with:
os: "${{ matrix.os }}"
python-version: "${{ matrix.python-version }}"
venv-id: "tests-${{ runner.os }}"
poetry-dependency-install-flags: "--all-extras"
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ jobs:
uses: softprops/action-gh-release@v1
with:
body_path: ".github/release_template.md"
token: "${{ secrets.PERSONAL_ACCESS_TOKEN }}"
draft: true
files: |
dist/openscm_units-${{ env.PROJECT_VERSION }}-py3-none-any.whl
dist/openscm_units-${{ env.PROJECT_VERSION }}.tar.gz
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
2 changes: 1 addition & 1 deletion .github/workflows/test-conda-install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ jobs:
shell: bash -l {0}
run: |
which python
python scripts/test_install.py
python scripts/test-install.py
2 changes: 1 addition & 1 deletion .github/workflows/test-pypi-install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ jobs:
uses: actions/checkout@v2
- name: Test installation
run: |
python scripts/test_install.py
python scripts/test-install.py
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
# Jupyter cache
.jupyter_cache

# Ruff cache
.ruff_cache

# Licence check
licence-check.txt

Expand Down
16 changes: 4 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ci:
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: 'v4.4.0'
rev: 'v4.5.0'
hooks:
- id: check-added-large-files
- id: check-ast
Expand All @@ -31,20 +31,12 @@ repos:
language: fail
files: "\\.rej$"
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.263'
rev: 'v0.1.8'
hooks:
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]
- repo: https://github.com/psf/black
rev: '23.3.0'
hooks:
- id: black
# additional to the above, apply black to doctests in source code
- repo: https://github.com/keewis/blackdoc
rev: v0.3.8
hooks:
- id: blackdoc
- id: ruff-format
- repo: https://github.com/python-poetry/poetry
rev: '1.4.2'
rev: '1.7.0'
hooks:
- id: poetry-check
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ endef
export PRINT_HELP_PYSCRIPT


.PHONY: help
help: ## print short description of each target
@python3 -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)

Expand All @@ -27,14 +28,13 @@ checks: ## run all the linting checks of the codebase
echo "=== mypy ==="; MYPYPATH=stubs poetry run mypy src || echo "--- mypy failed ---" >&2; \
echo "======"

.PHONY: black
black: ## format the code using black
poetry run black src tests docs/source/conf.py scripts docs/source/notebooks/*.py
poetry run blackdoc src

.PHONY: ruff-fixes
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
poetry run ruff format src tests scripts docs/source/conf.py docs/source/notebooks/*.py
poetry run ruff src tests scripts docs/source/conf.py docs/source/notebooks/*.py --fix
poetry run ruff format src tests scripts docs/source/conf.py docs/source/notebooks/*.py


.PHONY: test
Expand Down
1 change: 1 addition & 0 deletions changelog/49.trivial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Updated to newer copier template version
10 changes: 9 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,16 @@ def _generate_module_rst_new(*args, **kwargs):
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

# Pick your theme for html output, we typically use the read the docs theme
html_theme = "sphinx_rtd_theme"
html_theme = "sphinx_book_theme"
html_static_path = ["_static"]
html_theme_options = {
"repository_url": "https://github.com/openscm/openscm-units",
"repository_branch": "main",
"path_to_docs": "docs/source",
"use_repository_button": True,
"use_issues_button": True,
"use_edit_page_button": True,
}


# Ignore ipynb files when building (see https://github.com/executablebooks/MyST-NB/issues/363).
Expand Down
Loading

0 comments on commit 79eb638

Please sign in to comment.