Skip to content

Commit

Permalink
Merge pull request #185 from ImperialCollegeLondon/add-semantic-versi…
Browse files Browse the repository at this point in the history
…oning

Add semantic versioning
  • Loading branch information
tomjholland authored Jan 1, 2025
2 parents d3eef79 + c5cd674 commit 53ef755
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 22 deletions.
33 changes: 30 additions & 3 deletions .github/workflows/publish-to-testpypi.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: "Publish to TestPyPI"

on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
push:
branches:
- main
workflow_dispatch:
Expand All @@ -13,14 +12,19 @@ jobs:

permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
contents: write # for git operations

environment:
name: testpypi
url: https://test.pypi.org/p/PyProBE-Data

steps:
- uses: actions/checkout@v4

with:
fetch-depth: 0 # Fetch all history
fetch-tags: true # Fetch all tags
ref: ${{ github.head_ref || github.ref_name }} # Correct branch reference

- name: Install uv
uses: astral-sh/setup-uv@v5

Expand All @@ -32,6 +36,29 @@ jobs:
- name: Install the project
run: uv sync --all-extras --group format --group test --group docs --group external-integration

- name: Run semantic-release
id: semrel
run: |
uv run semantic-release version \
--prerelease \
--no-commit \
--no-tag \
--skip-build
- name: Update uv lockfile
run: uv lock --upgrade-package pyprobe-data

- name: Get version
id: version
run: |
VERSION=$(grep -o '".*"' pyprobe/_version.py | sed 's/"//g')
echo "version=$VERSION" >> $GITHUB_OUTPUT
- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Update version [skip ci]
tagging_message: "v${{ steps.version.outputs.version }}"

- name: Build
run: uv build

Expand Down
3 changes: 2 additions & 1 deletion pyprobe/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""The PyProBE package."""
from .cell import Cell, __version__, load_archive, make_cell_list # noqa: F401
from ._version import __version__ # noqa: F401
from .cell import Cell, load_archive, make_cell_list # noqa: F401
from .dashboard import launch_dashboard # noqa: F401
from .logger import configure_logging # noqa: F401
from .plot import Plot # noqa: F401
Expand Down
1 change: 1 addition & 0 deletions pyprobe/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "1.1.4"
3 changes: 1 addition & 2 deletions pyprobe/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
import polars as pl
from pydantic import BaseModel, Field, field_validator, validate_call

from pyprobe._version import __version__
from pyprobe.cyclers import arbin, basecycler, basytec, biologic, maccor, neware
from pyprobe.filters import Procedure
from pyprobe.readme_processor import process_readme
from pyprobe.utils import PyBaMMSolution

logger = logging.getLogger(__name__)

__version__ = "1.1.0"


class Cell(BaseModel):
"""A class for a cell in a battery experiment."""
Expand Down
21 changes: 20 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "PyProBE-Data"
authors = [
{name = "Thomas Holland"},
]
version = "1.1.0"
dynamic = ["version"]
requires-python = ">=3.11,<3.13"
license = { file = "LICENSE" }
dependencies = [
Expand Down Expand Up @@ -33,6 +33,7 @@ format = [
"isort>=5.13.2",
"mypy>=1.14.1",
"pre-commit>=4.0.1",
"python-semantic-release>=9.15.2",
]
test = [
"pytest>=8.3.4",
Expand Down Expand Up @@ -71,6 +72,24 @@ exclude = [
"examples/*"
]

[tool.hatch.version]
path = "pyprobe/_version.py"

[tool.semantic_release]
version_source = "tag"
version_variables = ["pyprobe/_version.py:__version__"]
changelog_file = false
branch = "main"
commit_version_number = false # disable auto commits
tag_commit = false # disable auto tagging
prerelease = true
upload_to_pypi = false # disable PyPI upload
upload_to_release = false # disable GitHub release creation

[tool.semantic_release.branches.main]
match = "main"
prerelease = true

[tool.mypy]
disallow_any_explicit = false
disallow_any_generics = true
Expand Down
6 changes: 2 additions & 4 deletions tests/test_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import polars as pl
import pybamm
import pytest
import toml
from numpy.testing import assert_array_equal
from polars.testing import assert_frame_equal

import pyprobe
from pyprobe._version import __version__
from pyprobe.cell import Cell


Expand Down Expand Up @@ -332,14 +332,12 @@ def test_archive(cell_instance):
metadata["PyProBE Version"] = "0.0.0"
with open(os.path.join(input_path, "archive", "metadata.json"), "w") as f:
json.dump(metadata, f)
pyproject_path = os.path.join(os.path.dirname(__file__), "..", "pyproject.toml")
pyproject_data = toml.load(pyproject_path)
with pytest.warns(
UserWarning,
match=(
f"The PyProBE version used to archive the cell was "
f"{metadata['PyProBE Version']}, the current version is "
f"{pyproject_data['project']['version']}. There may be compatibility"
f"{__version__}. There may be compatibility"
f" issues."
),
):
Expand Down
10 changes: 0 additions & 10 deletions tests/test_package.py

This file was deleted.

100 changes: 99 additions & 1 deletion uv.lock

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

0 comments on commit 53ef755

Please sign in to comment.