Skip to content

Commit

Permalink
New nox sessions for releases
Browse files Browse the repository at this point in the history
  • Loading branch information
paugier committed Feb 8, 2024
1 parent 13b08dd commit 78a95b9
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 0 deletions.
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 = "[email protected]"}]
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 78a95b9

Please sign in to comment.