From 7aaaff10e343010fa198ff64c4278bc97fda3fce Mon Sep 17 00:00:00 2001 From: Laurent Soucasse <135331272+lsoucasse@users.noreply.github.com> Date: Mon, 10 Jun 2024 15:10:59 +0200 Subject: [PATCH 1/2] Add publishing workflow inspired from the GEMDAT package. --- .github/workflows/publish.yaml | 72 ++++++++++++++++++++++++++++++ pyproject.toml | 36 +++++++++++---- tools/generate_requirements_txt.py | 19 ++++++++ 3 files changed, 118 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/publish.yaml create mode 100644 tools/generate_requirements_txt.py diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..d92eef1 --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,72 @@ +name: Publish on PyPI + +on: + release: + types: [published] + workflow_dispatch: + + +jobs: + fix_release_deps: + permissions: write-all + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: '3.12' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip pip-tools setuptools + + - name: Set configuration + run: | + git config --global user.name "${GITHUB_ACTOR}" + git config --global user.email "${GITHUB_ACTOR_ID}+${GITHUB_ACTOR}@users.noreply.github.com" + + - name: Create requirements files + run: | + python tools/generate_requirements_txt.py + pip-compile -o requirements_full.txt pyproject.toml + git add requirements_full.txt requirements.txt + git commit -m "Updated requirements.txt files" || true + + - name: Bump version to new tag + run: | + python -m pip install bump-my-version + bump-my-version bump --new-version $GITHUB_REF_NAME patch + git commit -am "Bump version to: $GITHUB_REF_NAME" + + - name: Push back changes to main and tag + run: | + git tag --force $GITHUB_REF_NAME HEAD + git push --force --tags + git switch -C main + git push --set-upstream -f origin main + + deploy: + needs: fix_release_deps + runs-on: ubuntu-latest + environment: release + permissions: + # IMPORTANT: this permission is mandatory for trusted publishing + id-token: write + + steps: + - uses: actions/checkout@v3 + with: + ref: ${{ github.ref_name }} + + - uses: actions/setup-python@v4 + with: + python-version: '3.12' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install build setuptools>=61.2 wheel + python -m build --no-isolation + + - name: Publish package + uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/pyproject.toml b/pyproject.toml index 9a68c12..1690327 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,23 +27,41 @@ classifiers = [ keywords = ["exoplanet", "atmosphere"] requires-python = '>=3.10' dependencies = [ - 'matplotlib', - 'natsort', - 'netcdf4', - 'numpy', - 'pandas', - 'scipy', - 'seaborn', - 'tomlkit', - 'f90nml' + "matplotlib", + "natsort", + "netcdf4", + "numpy", + "pandas", + "scipy", + "seaborn", + "tomlkit", + "f90nml" ] [project.urls] homepage = "https://github.com/FormingWorlds/JANUS" +[project.optional-dependencies] +develop = [ + "bump-my-version", + "pytest" +] +publishing = [ + "wheel", + "build" +] + [tool.setuptools] package-dir = {"janus" = "src/janus"} include-package-data = true [tool.pytest.ini_options] testpaths = ["tests"] + +[tool.bumpversion] +current_version = "24.04.04" + +[[tool.bumpversion.files]] +filename = "pyproject.toml" +search = "version = \"{current_version}\"" +replace = "version = \"{new_version}\"" diff --git a/tools/generate_requirements_txt.py b/tools/generate_requirements_txt.py new file mode 100644 index 0000000..a148c33 --- /dev/null +++ b/tools/generate_requirements_txt.py @@ -0,0 +1,19 @@ +from __future__ import annotations + +from pathlib import Path + +import tomllib + +this_script = Path(__file__) +root = this_script.parents[1] +pyproject = root / 'pyproject.toml' + +with open(pyproject, 'rb') as f: + metadata = tomllib.load(f) + dependencies = metadata['project']['dependencies'] + +with open('requirements.txt', 'w') as f: + this_script_rel = this_script.relative_to(root) + f.write(f'# generated by {this_script_rel}\n') + f.write('\n'.join(dependencies)) + f.write('\n') From 8a2280b68c57b37073720d8bcaa064b5d079193e Mon Sep 17 00:00:00 2001 From: Laurent Soucasse <135331272+lsoucasse@users.noreply.github.com> Date: Mon, 10 Jun 2024 15:51:09 +0200 Subject: [PATCH 2/2] Update pyproject.toml Co-authored-by: Stef Smeets --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 1690327..34f4d07 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -47,6 +47,7 @@ develop = [ "pytest" ] publishing = [ + "twine", "wheel", "build" ]