From 78a95b97928122824d5d8250127e66db0396c88e Mon Sep 17 00:00:00 2001 From: paugier Date: Thu, 8 Feb 2024 22:31:16 +0100 Subject: [PATCH] New nox sessions for releases --- noxfile.py | 115 ++++++++++++++++++++++++ plugins/fluidfft-builder/LICENSE | 7 ++ plugins/fluidfft-builder/README.md | 6 ++ plugins/fluidfft-builder/pyproject.toml | 1 + 4 files changed, 129 insertions(+) create mode 100644 plugins/fluidfft-builder/LICENSE create mode 100644 plugins/fluidfft-builder/README.md diff --git a/noxfile.py b/noxfile.py index 41dc210..3beaa28 100644 --- a/noxfile.py +++ b/noxfile.py @@ -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/*") diff --git a/plugins/fluidfft-builder/LICENSE b/plugins/fluidfft-builder/LICENSE new file mode 100644 index 0000000..6ce3e51 --- /dev/null +++ b/plugins/fluidfft-builder/LICENSE @@ -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. diff --git a/plugins/fluidfft-builder/README.md b/plugins/fluidfft-builder/README.md new file mode 100644 index 0000000..50830ef --- /dev/null +++ b/plugins/fluidfft-builder/README.md @@ -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++. diff --git a/plugins/fluidfft-builder/pyproject.toml b/plugins/fluidfft-builder/pyproject.toml index fe42b1a..8195e50 100644 --- a/plugins/fluidfft-builder/pyproject.toml +++ b/plugins/fluidfft-builder/pyproject.toml @@ -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"