Skip to content

Commit

Permalink
Merge pull request #70 from hkoller/main
Browse files Browse the repository at this point in the history
Refactoring of build management
  • Loading branch information
sstroemer authored Feb 3, 2025
2 parents 7417a5d + 41b2c3a commit ba91f19
Show file tree
Hide file tree
Showing 10 changed files with 2,262 additions and 88 deletions.
15 changes: 15 additions & 0 deletions .github/actions/set-versions/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: 'Set versions'
description: 'Sets env variables with various software versions used in the workflows'

runs:
using: 'composite'
steps:
- name: "set UV version"
shell: bash
run: echo "VERSION_UV=0.5.25" >> $GITHUB_ENV

- name: "set Julia version"
shell: bash
run: echo "VERSION_JULIA=1.11.2" >> $GITHUB_ENV


42 changes: 22 additions & 20 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,34 @@ name: documentation

on: [push, pull_request, workflow_dispatch]

# needed to allow julia-actions/cache to delete old caches that it has created
permissions:
contents: write
actions: write
contents: read

jobs:
docs:
# needs: run_tests
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: ./.github/actions/set-versions
- uses: julia-actions/setup-julia@v2
with:
python-version: "3.11"
- name: Install dependencies
run: |
pip install sphinx myst_parser myst-nb sphinxawesome-theme sphinx-togglebutton jupytext
- name: Install local package
run: |
pip install -e .
version: ${{env.VERSION_JULIA}}
- uses: julia-actions/cache@v2
- uses: astral-sh/setup-uv@v5
with:
version: ${{env.VERSION_UV}}
- name: Sphinx build
run: |
sphinx-build docs docs/_build
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
if: ${{ github.ref == 'refs/heads/main' }}
with:
publish_branch: gh-pages
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docs/_build/
force_orphan: true
uv run sphinx-build docs docs/_build
# TODO: Re-enable after merge
# - name: Deploy to GitHub Pages
# uses: peaceiris/actions-gh-pages@v3
# if: ${{ github.ref == 'refs/heads/main' }}
# with:
# publish_branch: gh-pages
# github_token: ${{ secrets.GITHUB_TOKEN }}
# publish_dir: docs/_build/
# force_orphan: true
8 changes: 4 additions & 4 deletions .github/workflows/pypi_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ on:
permissions:
contents: read
id-token: write

jobs:
# Build it.
build-package:
name: Build & inspect package
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: hynek/build-and-inspect-python-package@v2

# Publish to PyPI.
pypi-publish:
needs: build-package
name: Upload release to PyPI
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
environment: release
steps:
- name: Download packages built by build-and-inspect-python-package
Expand Down
42 changes: 20 additions & 22 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,30 @@ name: pytest

on: [push, pull_request]

# needed to allow julia-actions/cache to delete old caches that it has created
permissions:
actions: write
contents: read

jobs:
run_tests:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Install Python
uses: actions/setup-python@v5
- uses: ./.github/actions/set-versions
- uses: julia-actions/setup-julia@v2
with:
python-version: "3.11"
- name: Install poetry
uses: abatilo/actions-poetry@v2
- name: Setup a local virtual environment (if no poetry.toml file)
run: |
poetry config virtualenvs.create true --local
poetry config virtualenvs.in-project true --local
- uses: actions/cache@v3
name: Define a cache for the virtual environment based on the dependencies lock file
version: ${{env.VERSION_JULIA}}
- uses: julia-actions/cache@v2
- uses: astral-sh/setup-uv@v5
with:
path: ./.venv
key: venv-${{ hashFiles('poetry.lock') }}
- name: Install the project dependencies
run: poetry install --with test
version: ${{env.VERSION_UV}}
- name: Run the automated tests
run: poetry run pytest
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4.0.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: ait-energy/iesopt
run: uv run pytest

# TODO: Re-enable after merge
# - name: Upload coverage reports to Codecov
# uses: codecov/codecov-action@v4.0.1
# with:
# token: ${{ secrets.CODECOV_TOKEN }}
# slug: ait-energy/iesopt
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ cython_debug/
**/juliapkg.json

# Prevent tracking root folder Python files
*.py
/*.py

# Temp. directory
tmp_test/
Expand Down
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.13
4 changes: 2 additions & 2 deletions docs/dynamic/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,13 @@ def _dyn_core_create_md(cc: str):
f"# Using Julia (`IESopt.jl`):\n"
f"import IESopt\n\n"
f"model = IESopt.run(...) # assuming this is your model\n"
f"IESopt.get_component(model, \"your_{info['component']}\").{info['type_short']}.{info['name']}\n"
f'IESopt.get_component(model, "your_{info["component"]}").{info["type_short"]}.{info["name"]}\n'
f"```\n\n"
f"```python\n"
f"# Using Python (`iesopt`):\n"
f"import iesopt\n\n"
f"model = iesopt.run(...) # assuming this is your model\n"
f"model.get_component(\"your_{info['component']}\").{info['type_short']}.{info['name']}\n"
f'model.get_component("your_{info["component"]}").{info["type_short"]}.{info["name"]}\n'
f"```\n\n"
f":::\n\n"
)
Expand Down
91 changes: 52 additions & 39 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,63 +1,67 @@
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.poetry]
[project]
name = "iesopt"
version = "2.4.2"
version = "2.4.3.dev0"
description = "IESopt -- an Integrated Energy System Optimization framework."
keywords = ["integrated energy systems", "optimization", "energy model", "modelling"]
authors = [
"Stefan Strömer <8915976+sstroemer@users.noreply.github.com>",
{name="Stefan Strömer", email="8915976+sstroemer@users.noreply.github.com"}
]
maintainers = [
"Stefan Strömer <8915976+sstroemer@users.noreply.github.com>",
{name="Stefan Strömer", email="8915976+sstroemer@users.noreply.github.com"}
]
readme = "README.md"
license = "MIT"
license = {text="MIT"}
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
]
requires-python = ">=3.10"
dependencies = [
"pathlib >= 1.0.0",
"pandas >= 2.0.0",
"pydantic >= 2.7.4",
"python-dotenv >= 1.0.1",
# the Julia dependencies are intentionally pinned!
"juliacall == 0.9.20",
"juliapkg == 0.1.13",
]
homepage = "https://github.com/ait-energy/iesopt"
documentation = "https://ait-energy.github.io/iesopt"
repository = "https://github.com/ait-energy/iesopt"

[tool.poetry.urls]
"Issues" = "https://github.com/ait-energy/iesopt/issues"
"Changelog" = "https://github.com/ait-energy/iesopt/releases"
[project.urls]
Homepage = "https://github.com/ait-energy/iesopt"
Documentation = "https://ait-energy.github.io/iesopt"
Repository = "https://github.com/ait-energy/iesopt"
Issues = "https://github.com/ait-energy/iesopt/issues"

[tool.poetry.dependencies]
python = "^3.11"
pathlib = "^1.0.0"
juliacall = "^0.9.20"
pandas = "^2.0.0"
juliapkg = "^0.1.13"
pydantic = "^2.7.4"
python-dotenv = "^1.0.1"
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.poetry.group.dev.dependencies]
ruff = "^0.4.7"
codespell = "^2.3.0"
pre-commit = "^3.8.0"
[dependency-groups]
dev = [
# code quality
"pre-commit >= 3.8.0",

[tool.poetry.group.docs.dependencies]
myst-parser = "^3.0.1"
sphinx = "^7.3.7"
sphinxawesome-theme = "^5.2.0"
sphinx-togglebutton = "^0.3.2"
ipywidgets = "^8.1.3"
myst-nb = "^1.1.0"
jupytext = "^1.16.4"
# test
"pytest >= 8.2.2",
"pytest-cov >= 5.0.0",
"pytest-ruff >= 0.3.2",
"tox>=4.24.1",
"tox-uv>=1.20.2",

[tool.poetry.group.test.dependencies]
pytest = "^8.2.2"
pytest-cov = "^5.0.0"
pytest-ruff = "^0.3.2"
# doc
"myst-parser >= 3.0.1",
"sphinx >= 7.3.7",
"sphinxawesome-theme >= 5.2.0",
"sphinx-togglebutton >= 0.3.2",
"ipywidgets >= 8.1.3",
"myst-nb >= 1.1.0",
"jupytext >= 1.16.4",
]

[tool.ruff]
line-length = 120
Expand All @@ -73,3 +77,12 @@ addopts = [
"--cov-report=xml:coverage.xml",
"--cov=iesopt",
]

[tool.tox]
requires = ["tox>=4.19"]
env_list = ["3.10", "3.11", "3.12", "3.13"]

[tool.tox.env_run_base]
description = "Run tests under {base_python}"
package = "wheel"
commands = [["pytest"]]
53 changes: 53 additions & 0 deletions tag_release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash
set -e

RED="\e[31m"
GREEN="\e[32m"
BLUE="\e[94m"
ENDCOLOR="\e[0m"

# make sure the git repo is clean
test -z "$(git status --porcelain)" || (echo -e "${RED}Repository is dirty. Aborting. ${ENDCOLOR}" && exit 1)

# store current git hash for undo command
current_git_hash=$(git show --oneline -s | cut -f 1 -d" ")
undo_command="git reset --hard $current_git_hash"
echo -e "If anything goes wrong use $BLUE $undo_command $ENDCOLOR to reset your repository."

# Get the current version from pyproject.toml and make sure it is a .dev version
version="$(uvx --from=toml-cli toml get --toml-path=pyproject.toml project.version)"
echo "Current Project version is $version"
if [[ ! $version == *".dev"* ]]; then
echo -e "${RED}$version is no dev version. Aborting.${ENDCOLOR}"
exit 1
fi

# Determine release version
version="$(echo $version | sed 's/\.dev.*$//')"

# Ask user
echo -e "Release version ${GREEN} $version ${ENDCOLOR} ? [y/N]"
read answer
if [[ ! $answer =~ ^[Yy]$ ]] ; then
echo "Aborted" && exit 1
fi

# Switch pyproject.toml to release version and commit
uvx --from=toml-cli toml set --toml-path=pyproject.toml project.version $version
git commit -am"Tag release version $version"

# Tag this version
tag="v$version"
echo "Creating tag: $tag"
git tag $tag

# Start the next dev version
new_version="$(echo $version | awk -F. '{$NF = $NF + 1;} 1' | sed 's/ /./g')".dev0

echo "Starting new version: $new_version"
uvx --from=toml-cli toml set --toml-path=pyproject.toml project.version $new_version
git commit -am"Start developing version $new_version"

echo -e "Tag created. Use $BLUE git push --tags $ENDCOLOR to make this release permanent"
echo -e "Or undo all changes with $GREEN $undo_command && git tag --delete $tag $ENDCOLOR"

Loading

0 comments on commit ba91f19

Please sign in to comment.