Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Do not edit - changes here will be overwritten by Copier
_commit: v0.3.0
_commit: v0.4.2
_src_path: gh:fractal-analytics-platform/fractal-tasks-template
author_email: [email protected]
author_name: Joel Luethi
Expand Down
108 changes: 108 additions & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: CI (build and test)

on:
push:
branches: ["main"]
tags:
- "*"
pull_request:
branches: ["main"]


jobs:
tests:
strategy:
matrix:
os: [ubuntu-22.04, macos-latest]
python-version: ["3.9", "3.10", "3.11"]
exclude:
- os: macos-latest
python-version: '3.9'
- os: macos-latest
python-version: '3.10'
name: "Core, Python ${{ matrix.python-version }}, ${{ matrix.os }}"
runs-on: ${{ matrix.os }}
timeout-minutes: 30

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "pip"

- name: Install package
run: python -m pip install -e .[dev]

- name: Install some testing dependencies (hard-coded)
run: python -m pip install pytest pytest-cov devtools jsonschema requests wget pooch

- name: Regenerate the manifest
run: python src/fractal_helper_tasks/dev/create_manifest.py

- name: Cache Pooch folder
id: cache-pooch-folder
uses: actions/cache@v3
with:
path: ~/.cache/pooch
key: pooch-cache

- name: Check if manifest has changed
run: |
if [ -n "$(git diff --exit-code ./src/fractal_helper_tasks/__FRACTAL_MANIFEST__.json)" ]; then
echo "__FRACTAL_MANIFEST__.json has changed. Please run 'python src/fractal_helper_tasks/dev/create_manifest.py' and commit the changes."
exit 1
else
echo "__FRACTAL_MANIFEST__.json has not changed."
fi

- name: Test tasks with pytest
run: pytest --color=yes --cov --cov-report=xml --cov-report=term-missing -s --log-cli-level debug

- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: jluethi/fractal-helper-tasks

deploy:
name: Deploy
needs: tests
if: success() && startsWith(github.ref, 'refs/tags/') && github.event_name != 'schedule'
runs-on: ubuntu-latest

permissions:
# IMPORTANT: this permission is mandatory for trusted publishing on PyPi
# see https://docs.pypi.org/trusted-publishers/
id-token: write
# This permission allows writing releases
contents: write

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: 🐍 Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"

- name: 👷 Build
run: |
python -m pip install build
python -m build

- name: 🚢 Publish to PyPI
# TODO remove the "if: false" line when the package is ready for pypi release
if: false
uses: pypa/gh-action-pypi-publish@release/v1

- uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
files: './dist/*'
52 changes: 0 additions & 52 deletions .github/workflows/ci_pip.yml

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Git ignored is sourced from https://github.com/pydev-guide/pyrepo-copier/blob/main/LICENSE
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down Expand Up @@ -108,4 +109,4 @@ ENV/

# IDE settings
.vscode/
.idea/
.idea/
10 changes: 2 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,12 @@ build-backend = "hatchling.build"

# https://hatch.pypa.io/latest/config/metadata/
[tool.hatch.version]
#path = "src/fractal_helper_tasks/__init__.py"
source = "vcs"

# read more about configuring hatch at:
# https://hatch.pypa.io/latest/config/build/
[tool.hatch.build.targets.wheel]
only-include = ["src"]
sources = ["src"]

# Always include the __FRACTAL_MANIFEST__.json file in the package
[tool.hatch.build]
include = ["__FRACTAL_MANIFEST__.json"]
packages = ["src/fractal_helper_tasks"]


# Project metadata (see https://peps.python.org/pep-0621)
Expand All @@ -33,7 +27,7 @@ authors = [
# Required Python version and dependencies
requires-python = ">=3.9"
dependencies = [
"fractal-tasks-core==1.2.0"
"fractal-tasks-core==1.3.3"
]

# Optional dependencies (e.g. for `pip install -e ".[dev]"`, see
Expand Down
10 changes: 9 additions & 1 deletion src/fractal_helper_tasks/__FRACTAL_MANIFEST__.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"output_types": {
"has_t": false
},
"tags": [
"Singelton time dimension"
],
"executable_non_parallel": "drop_t_dimension.py",
"meta_non_parallel": {
"cpus_per_task": 2,
Expand Down Expand Up @@ -45,6 +48,10 @@
"input_types": {
"is_3D": false
},
"tags": [
"Mixed modality",
"2D to 3D workflows"
],
"executable_parallel": "convert_2D_segmentation_to_3D.py",
"meta_parallel": {
"cpus_per_task": 2,
Expand Down Expand Up @@ -122,5 +129,6 @@
}
],
"has_args_schemas": true,
"args_schema_version": "pydantic_v2"
"args_schema_version": "pydantic_v2",
"authors": "Joel Luethi"
}
3 changes: 2 additions & 1 deletion src/fractal_helper_tasks/dev/create_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
to the package manifest.
"""
PACKAGE = "fractal_helper_tasks"
create_manifest(package=PACKAGE)
AUTHORS = "Joel Luethi"
create_manifest(package=PACKAGE, authors=AUTHORS)
5 changes: 5 additions & 0 deletions src/fractal_helper_tasks/dev/task_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
executable="drop_t_dimension.py",
meta={"cpus_per_task": 2, "mem": 8000},
output_types=dict(has_t=False),
tags=["Singelton time dimension"],
),
ParallelTask(
input_types=dict(is_3D=False),
name="Convert 2D segmentation to 3D",
executable="convert_2D_segmentation_to_3D.py",
meta={"cpus_per_task": 2, "mem": 8000},
tags=[
"Mixed modality",
"2D to 3D workflows",
],
),
]
2 changes: 1 addition & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fractal_helper_tasks
import json
from pathlib import Path

import fractal_helper_tasks

PACKAGE = "fractal_helper_tasks"
PACKAGE_DIR = Path(fractal_helper_tasks.__file__).parent
Expand Down
16 changes: 7 additions & 9 deletions tests/test_valid_task_interface.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json
import subprocess
from shlex import split as shlex_split
from subprocess import PIPE

import pytest
from devtools import debug
Expand All @@ -16,22 +15,21 @@ def validate_command(cmd: str):
debug(cmd)
result = subprocess.run( # nosec
shlex_split(cmd),
stdout=PIPE,
stderr=PIPE,
capture_output=True,
)
# The command must always fail, since tmp_file_args includes invalid
# arguments
assert result.returncode == 1
stderr = result.stderr.decode()
debug(stderr)

# Valid stderr includes pydantic.error_wrappers.ValidationError (type
# Valid stderr includes pydantic.v1.error_wrappers.ValidationError (type
# match between model and function, but tmp_file_args has wrong arguments)
# assert "pydantic.v1.error_wrappers.ValidationError" in stderr
assert "ValidationError" in stderr

# # Valid stderr must include a mention of "unexpected keyword arguments",
# # because we are including some invalid arguments
# assert "unexpected keyword arguments" in stderr
# Valid stderr must include a mention of "Unexpected keyword argument",
# because we are including some invalid arguments
assert "Unexpected keyword argument" in stderr

# # Invalid stderr includes ValueError
# assert "ValueError" not in stderr
Expand All @@ -46,7 +44,7 @@ def test_task_interface(task, tmp_path):
tmp_file_args = str(tmp_path / "args.json")
tmp_file_metadiff = str(tmp_path / "metadiff.json")
with open(tmp_file_args, "w") as fout:
args = dict(wrong_arg_1=123, wrong_arg_2=[1, 2, 3])
args = {"wrong_arg_1": 123, "wrong_arg_2": [1, 2, 3]}
json.dump(args, fout, indent=4)

for key in ["executable_non_parallel", "executable_parallel"]:
Expand Down