Skip to content

Commit

Permalink
Merge pull request #3 from climate-resource/fix-towncrier
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisjared authored Oct 14, 2024
2 parents b496c31 + cfd33f4 commit bbabfe2
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 125 deletions.
12 changes: 5 additions & 7 deletions .github/workflows/bump.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,17 @@ jobs:
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`
BASE_VERSION=$(uv run python scripts/get-version.py)
echo "Bumping from version $BASE_VERSION"
# Bump
uv run pdm bump ${{ github.event.inputs.bump_rule }}
# regex supports 1.1.1a1, 1.1.1b1, 1.1.1rc1
NEW_VERSION=`sed -ne 's/^version = "\([0-9\.abrc]*\)"/\1/p' pyproject.toml`
NEW_VERSION=$(uv run python scripts/get-version.py)
echo "Bumping to version $NEW_VERSION"
# Build CHANGELOG
uv run towncrier build --yes --version v$NEW_VERSION
uvx towncrier build --yes --version v$NEW_VERSION
# Commit, tag and push
git commit -a -m "bump: version $BASE_VERSION -> $NEW_VERSION"
Expand All @@ -66,15 +65,14 @@ jobs:
# Bump to alpha (so that future commits do not have the same
# version as the tagged commit)
BASE_VERSION=`sed -ne 's/^version = "\([0-9\.abrc]*\)"/\1/p' pyproject.toml`
BASE_VERSION=$(uv run python scripts/get-version.py)
# Bump to pre-release of next version
uv run pdm bump pre-release --pre alpha
NEW_VERSION=`sed -ne 's/^version = "\([0-9\.abrc]*\)"/\1/p' pyproject.toml`
NEW_VERSION=$(uv run python scripts/get-version.py)
echo "Bumping version $BASE_VERSION > $NEW_VERSION"
# Commit and push
# Skip pre-commit to avoid pixi install throwing weird errors
git commit -n -a -m "bump(pre-release): version $BASE_VERSION > $NEW_VERSION"
git push
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
key: ${{ runner.os }}-pre-commit
- name: mypy
run: |
uv run pre-commit run --all-files
uvx pre-commit run --all-files
uv run mypy src
tests:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- uses: ./.github/actions/setup
- name: Add version to environment
run: |
PROJECT_VERSION=`sed -ne 's/^version = "\([0-9\.abrc]*\)"/\1/p' pyproject.toml`
PROJECT_VERSION=$(uv run python scripts/get-version.py)
echo "PROJECT_VERSION=$PROJECT_VERSION" >> $GITHUB_ENV
- name: Build datasets
run: |
Expand Down
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,29 @@ help: ## print short description of each target

.PHONY: checks
checks: ## run all the linting checks of the codebase
@echo "=== pre-commit ==="; uv run pre-commit run --all-files || echo "--- pre-commit failed ---" >&2; \
@echo "=== pre-commit ==="; uvx pre-commit run --all-files || echo "--- pre-commit failed ---" >&2; \
echo "======"

.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
uv run ruff format
uv run ruff check --fix
uv run ruff format
uvx ruff@0.6.9 format
uvx ruff@0.6.9 check --fix
uvx ruff@0.6.9 format

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

.PHONY: changelog-draft
changelog-draft: ## compile a draft of the next changelog
uv run towncrier build --draft
uvx towncrier build --draft --version $(shell uv run python scripts/get-version.py)

.PHONY: virtual-environment
virtual-environment: ## update virtual environment, create a new one if it doesn't already exist
uv sync
uv run pre-commit install
uvx pre-commit install

run: ## Generate the book
uv run bookshelf run rcmip-emissions -o dist
Expand Down
1 change: 1 addition & 0 deletions changelog/3.improvement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use get-version script instead of a sed one-liner
9 changes: 4 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "bookshelf-rcmip-emissions"
version = "0.1.0"
version = "0.1.0a1"
description = "Emissions dataset from RCMIP"
readme = "README.md"
requires-python = ">=3.11"
Expand Down Expand Up @@ -59,8 +59,8 @@ convention = "numpy"
docstring-code-format = true

[tool.towncrier]
package = "bookshelf-rcmip-emissions"
package_dir = "src"
# This runs towncrier in non-python mode, so we need to specify the project name and version at run-time
name = "bookshelf-rcmip-emissions"
filename = "CHANGELOG.md"
directory = "changelog/"
title_format = "## RCMIP Emissions {version} ({project_date})"
Expand All @@ -83,6 +83,5 @@ type = [
[tool.uv]
dev-dependencies = [
"mypy>=1.11.2",
"pre-commit>=4.0.1",
"ruff>=0.6.9",
"toml>=0.10.2",
]
29 changes: 29 additions & 0 deletions scripts/get-version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
Extract the current version from pyproject.toml and print to stdout
These can then be used in our release template.
"""

from pathlib import Path

import toml


def get_version() -> str:
"""
Extract the current version from pyproject.toml
"""
version = "unknown"
# adopt path to your pyproject.toml
pyproject_toml_file = Path(__file__).parent.parent / "pyproject.toml"

if pyproject_toml_file.exists() and pyproject_toml_file.is_file():
data = toml.load(pyproject_toml_file)
# check project.version
if "project" in data and "version" in data["project"]:
version = data["project"]["version"]
return version


if __name__ == "__main__":
print(get_version())
117 changes: 12 additions & 105 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bbabfe2

Please sign in to comment.