Skip to content

Commit

Permalink
Merge branch 'topic/default/nox-release-wheels' into 'branch/default'
Browse files Browse the repository at this point in the history
Nox release wheels

Closes #35 and #36

See merge request fluiddyn/fluidfft!53
  • Loading branch information
paugier committed Feb 8, 2024
2 parents 13b08dd + 8fe662c commit 6b4dd96
Show file tree
Hide file tree
Showing 5 changed files with 252 additions and 0 deletions.
123 changes: 123 additions & 0 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
name: Build
on:
- push
- pull_request

jobs:

wheels:
runs-on: ${{ matrix.os }}-latest
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu
architecture: x86_64
# really long (2 hours), see next job wheel-ubuntu-aarch64
# - os: ubuntu
# architecture: aarch64
- os: macos
architecture: x86_64
- os: macos
architecture: arm64
- os: windows
architecture: AMD64
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v2
with:
platforms: arm64
if: runner.os == 'Linux' && matrix.architecture == 'aarch64'

- uses: actions/setup-python@v5
with:
python-version: 3.x

- name: Build wheels
uses: pypa/cibuildwheel@v2.16.5
env:
CIBW_SKIP: pp* cp36-* cp37-* cp38-* *-musllinux*
CIBW_ARCHS: ${{ matrix.architecture }}
- uses: actions/upload-artifact@v4
with:
name: wheel-${{ matrix.os }}-${{ matrix.architecture }}
path: wheelhouse/*.whl

wheel-ubuntu-aarch64:
if: |
github.event_name == 'push' &&
startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v2
with:
platforms: arm64

- uses: actions/setup-python@v5
with:
python-version: 3.x

- name: Build wheels
uses: pypa/cibuildwheel@v2.16.5
env:
CIBW_SKIP: pp* cp36-* cp37-* cp38-* *-musllinux*
CIBW_ARCHS: aarch64
- uses: actions/upload-artifact@v4
with:
name: wheel-ubuntu-aarch64
path: wheelhouse/*.whl

sdist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: echo ${{ github.ref }}
- run: python -m pip install build twine
- run: python -m build --sdist
- run: twine check --strict dist/*
- uses: actions/upload-artifact@v4
with:
name: sdist
path: dist/*.tar.gz

check-sdist:
runs-on: ubuntu-latest
needs:
- sdist
steps:
- uses: actions/download-artifact@v4
with:
name: sdist
- uses: actions/setup-python@v5
with:
python-version: 3.11
- run: |
pip install pip -U
ls
pip install fluidfft-*.tar.gz -v --no-deps -C setup-args=-Dtransonic-backend=python
pypi-publish:
name: Upload release to PyPI
if: |
github.event_name == 'push' &&
startsWith(github.ref, 'refs/tags/')
needs:
- wheels
- wheel-ubuntu-aarch64
- sdist
- check-sdist
runs-on: ubuntu-latest
environment:
name: publish
url: https://pypi.org/p/fluidfft
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
steps:
- uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true
- run: ls dist
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
115 changes: 115 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,118 @@ def doc(session):
session.chdir("doc")
session.run("make", "cleanall", external=True)
session.run("make", external=True)


def _get_version_from_pyproject(path=Path.cwd()):
if isinstance(path, str):
path = Path(path)

if not path.name == "pyproject.toml":
path /= "pyproject.toml"

if not path.exists():
raise IOError(f"{path} does not exist.")

in_project = False
version = None
with open(path, encoding="utf-8") as file:
for line in file:
if line.startswith("[project]"):
in_project = True
if line.startswith("version =") and in_project:
version = line.split("=")[1].strip()
version = version[1:-1]
break

assert version is not None
return version


@nox.session(name="add-tag-for-release", venv_backend="none")
def add_tag_for_release(session):
session.run("hg", "pull", external=True)

result = session.run(*"hg log -r default -G".split(), external=True, silent=True)
if result[0] != "@":
session.run("hg", "update", "default", external=True)

version = _get_version_from_pyproject()
print(f"{version = }")

result = session.run("hg", "tags", "-T", "{tag},", external=True, silent=True)
last_tag = result.split(",", 2)[1]
print(f"{last_tag = }")

if last_tag == version:
session.error("last_tag == version")

answer = input(
f'Do you really want to add and push the new tag "{version}"? (yes/[no]) '
)

if answer != "yes":
print("Maybe next time then. Bye!")
return

print("Let's go!")
session.run("hg", "tag", version, external=True)
session.run("hg", "push", external=True)


@nox.session(name="release-plugin", reuse_venv=True)
def release_plugin(session):
"""Release a plugin on PyPI."""

for project in ("build", "twine", "lastversion"):
session.install(project)

try:
short_name = session.posargs[0]
except IndexError:
session.error("No short name given. Use as `nox -R -s release-plugin -- fftw`")
print(short_name)

path = Path.cwd() / f"plugins/fluidfft-{short_name}"

if not path.exists():
session.error(f"{path} does not exist")

version = _get_version_from_pyproject(path)
print(f"{version = }")

ret = session.run(
"lastversion",
f"fluidfft-{short_name}",
"--at",
"pip",
success_codes=[0, 1],
silent=True,
)
if ret.startswith("CRITICAL: No release was found"):
print(ret[len("CRITICAL: ") :])
else:
version_on_pypi = ret.strip()
if version_on_pypi == version:
session.error(f"Local version {version} is already released")

session.chdir(path)

path_dist = path / "dist"
rmtree(path_dist, ignore_errors=True)

command = "python -m build"
if short_name in ["fftw", "mpi_with_fftw", "fftwmpi", "pfft", "p3dfft"]:
command += " --sdist"

session.run(*command.split())
session.run("twine", "check", "dist/*")

answer = input(
f"Do you really want to release fluidfft-{short_name} {version}? (yes/[no]) "
)

if answer != "yes":
print("Maybe next time then. Bye!")
return

session.run("twine", "upload", "dist/*")
7 changes: 7 additions & 0 deletions plugins/fluidfft-builder/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2024 Pierre Augier

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
6 changes: 6 additions & 0 deletions plugins/fluidfft-builder/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Fluidfft-builder

C++ source, Cython templates and build utilities for
[Fluidfft](https://fluidfft.readthedocs.io).

Used as a build dependency for plugins using C++.
1 change: 1 addition & 0 deletions plugins/fluidfft-builder/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ description = "Fluidfft plugin dependencies"
authors = [{name = "Pierre Augier", email = "pierre.augier@univ-grenoble-alpes.fr"}]
license = {file = "LICENSE"}
classifiers = ["License :: OSI Approved :: MIT License"]
readme = "README.md"

[project.urls]
Home = "https://foss.heptapod.net/fluiddyn/fluidfft"
Expand Down

0 comments on commit 6b4dd96

Please sign in to comment.