diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e0b6c28..c9cc5c2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,6 +6,7 @@ stages: - test-release - doc - build + - zenodo variables: COVERAGE_DIR: .coverage_$CI_COMMIT_SHA @@ -145,3 +146,15 @@ build:package: paths: - dist expire_in: 24 hrs + + +zenodo:upload: + stage: zenodo + image: python:3.11 + rules: + - if: $CI_COMMIT_TAG =~ /^[0-9]+\.[0-9]+/ + needs: [] + before_script: + - pip install nox + script: + - nox -s zenodo-upload diff --git a/.hgignore b/.hgignore index 3889d3b..6d1bb3d 100644 --- a/.hgignore +++ b/.hgignore @@ -86,4 +86,8 @@ image_samples/*/Images.*_example* .pytest_cache/* **/.mypy_cache -.eggs/* \ No newline at end of file +.eggs/* + +# zenodo +.zenodo.json +fluidimage-*.zip diff --git a/CITATION.cff b/CITATION.cff new file mode 100644 index 0000000..61c21dd --- /dev/null +++ b/CITATION.cff @@ -0,0 +1,24 @@ +cff-version: 1.2.0 +message: If you use this software, please cite it using these metadata. +title: "Fluidimage: a Python framework to study flows from images" +abstract: | + Image processing is a common method in fluid mechanics, with various algorithms such + as Particle Image Velocimetry (PIV) or Light Induced Fluorescence (LIF) used to + compute velocity, vorticity, concentration or temperature fields. Fluidimage is a + Python framework to process images of fluids and analyze the results. +authors: + + - family-names: Augier + given-names: Pierre + orcid: https://orcid.org/0000-0001-9481-4459 + +# Note: the values of "version" and "date-released" might not correspond to the last uploaded version. +# The correct values are in the file pyproject.toml and CHANGES.md. +version: 0.5.2 +date-released: "2024-05-24" +identifiers: + - description: This is the collection of archived snapshots of all versions of Fluidimage + type: doi + value: "10.5281/zenodo.11359207" +license: CECILL-2.1 +repository-code: "https://foss.heptapod.net/fluiddyn/fluidimage" diff --git a/noxfile.py b/noxfile.py index bfeaf96..c53d0f9 100644 --- a/noxfile.py +++ b/noxfile.py @@ -10,9 +10,9 @@ """ +import json import os - -from datetime import timedelta +from datetime import datetime, timedelta from functools import partial from pathlib import Path from time import time @@ -143,6 +143,11 @@ def _get_version_from_pyproject(path=Path.cwd()): return version +def _get_last_tag(session): + result = session.run("hg", "tags", "-T", "{tag},", external=True, silent=True) + return result.split(",", 2)[1] + + @nox.session(name="add-tag-for-release", venv_backend="none") def add_tag_for_release(session): """Add a tag to the repo for a new version""" @@ -157,8 +162,7 @@ def add_tag_for_release(session): 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] + last_tag = _get_last_tag(session) print(f"{last_tag = }") if last_tag == version: @@ -190,3 +194,44 @@ def detect_pythran_extensions(session): [str(p)[:-3].replace("/", ".") for p in paths_pythran_files] ) ) + + +@nox.session(name="zenodo-upload") +def zenodo_upload(session): + """Upload an archive on Zenodo""" + + session.install("cffconvert") + session.install("gitlab2zenodo") + + version = _get_version_from_pyproject() + last_tag = _get_last_tag(session) + + assert version == last_tag + + now = datetime.now() + str_date = f"{now.year}-{now.month}-{now.day}" + + command = "cffconvert -i CITATION.cff -f zenodo" + result = session.run(*command.split(), external=True, silent=True) + + zenodo_info = json.loads(result) + zenodo_info["publication_date"] = str_date + zenodo_info["version"] = version + + print(zenodo_info) + + with open(".zenodo.json", "w", encoding="utf-8") as file: + json.dump(zenodo_info, file) + + name_zip = f"fluidimage-{version}.zip" + + command = ( + f"hg archive {name_zip} --type zip " + "-X old -X try -X bench -X dev -X docker -X image_samples" + ) + result = session.run(*command.split(), external=True) + + zenodo_token = os.getenv("zenodo_token") + if zenodo_token is not None: + command = f"g2z-send -i {zenodo_token} -t 11359207 -s -m .zenodo.json {name_zip}" + session.run(*command.split()) diff --git a/pyproject.toml b/pyproject.toml index e95b5b7..132846d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -135,9 +135,9 @@ dev = [ ] [tool.pdm.scripts] -black = "black src doc" -isort = "isort --atomic --tc src bench doc/examples" -black_check = "black --check src doc" +black = "black src doc noxfile.py" +isort = "isort --atomic --tc src bench doc/examples noxfile.py" +black_check = "black --check src doc noxfile.py" lint = {shell="pylint -rn --rcfile=pylintrc --jobs=$(nproc) src --exit-zero"} validate_code = {composite = ["black_check", "lint"]} format = {composite = ["black", "isort"]}