Skip to content

Commit

Permalink
Merge branch 'topic/default/zenodo' into 'branch/default'
Browse files Browse the repository at this point in the history
Automatic upload to Zenodo

Closes #39

See merge request fluiddyn/fluidimage!112
  • Loading branch information
paugier committed May 28, 2024
2 parents 96f6105 + f811f20 commit 134c874
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 8 deletions.
13 changes: 13 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ stages:
- test-release
- doc
- build
- zenodo

variables:
COVERAGE_DIR: .coverage_$CI_COMMIT_SHA
Expand Down Expand Up @@ -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
6 changes: 5 additions & 1 deletion .hgignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,8 @@ image_samples/*/Images.*_example*
.pytest_cache/*
**/.mypy_cache

.eggs/*
.eggs/*

# zenodo
.zenodo.json
fluidimage-*.zip
24 changes: 24 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -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"
53 changes: 49 additions & 4 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"""
Expand All @@ -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:
Expand Down Expand Up @@ -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())
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}
Expand Down

0 comments on commit 134c874

Please sign in to comment.