Skip to content

allow sequence types for fields with requires (can be empty) #827

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 5 additions & 2 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
@@ -182,7 +182,7 @@ jobs:
docker exec slurm bash -c "ls -la /pydra && echo list pydra dir"
docker exec slurm bash -c "CONFIGURE_OPTS=\"-with-openssl=/opt/openssl\" pyenv install -v ${{ matrix.python-version }}"
docker exec slurm bash -c "pyenv global ${{ matrix.python-version }}"
docker exec slurm bash -c "pip install --upgrade pip && pip install -e /pydra[test,psij] && python -c 'import pydra.engine; print(pydra.utils.__version__)'"
docker exec slurm bash -c "pip install --upgrade pip && pip install 'numpy<2' -e /pydra[test,psij] && python -c 'import pydra.engine; print(pydra.utils.__version__)'"
- name: Run pytest
run: |
docker exec slurm bash -c "cd /pydra; pytest pydra/workers/tests/test_worker.py --only-worker=slurm --color=yes"
@@ -315,9 +315,12 @@ jobs:
with:
auto-activate-base: true
activate-environment: ""
# We generate dummy aliases so they can be deleted by conda later without throwing an error
- name: Install MRtrix via Conda
run: |
conda install -c mrtrix3 mrtrix3
alias shview='ls'
alias mrview='ls'
conda install -c conda-forge -c MRtrix3 mrtrix3 libstdcxx-ng
mrconvert --version
- name: Set up Python
uses: actions/setup-python@v5
10 changes: 5 additions & 5 deletions docs/source/tutorial/7-canonical-form.ipynb
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Canonical form and serialisation\n",
"# Canonical forms\n",
"\n",
"## Canonical task form\n",
"\n",
@@ -28,7 +28,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Python-tasks\n",
"### Python-tasks\n",
"\n",
"Python tasks in dataclass form are decorated by `pydra.compose.python.define`\n",
"with inputs listed as type annotations. Outputs are similarly defined in a nested class\n",
@@ -135,7 +135,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Shell-tasks\n",
"### Shell-tasks\n",
"\n",
"The canonical form of shell tasks is the same as for Python tasks, except a string `executable`\n",
"attribute replaces the `function` staticmethod."
@@ -183,7 +183,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Workflow definitions\n",
"### Workflow definitions\n",
"\n",
"Workflows can also be defined in canonical form, which is the same as for Python tasks\n",
"but with a staticmethod called `constructor` that constructs the workflow."
@@ -242,7 +242,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Converting to/from dictionaries\n",
"## Conversion to/from dictionaries\n",
"\n",
"As well as the dataclass-like canonical form, it is also possible to represent all tasks\n",
"in a nested dictionary form, which could be written to a static file (e.g. in JSON or\n",
7 changes: 6 additions & 1 deletion pydra/compose/base/field.py
Original file line number Diff line number Diff line change
@@ -229,7 +229,12 @@ def mandatory(self):

@requires.validator
def _requires_validator(self, _, value):
if value and self.type not in (ty.Any, bool) and not is_optional(self.type):
if (
value
and self.type not in (ty.Any, bool)
and not is_optional(self.type)
and not issubclass(self.type, ty.Sequence)
):
raise ValueError(
f"Fields with requirements must be of optional type (i.e. in union "
f"with None) or boolean, not type {self.type} ({self!r})"