-
Notifications
You must be signed in to change notification settings - Fork 6
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
Relax pydantic requirements || Switch to transitional pydantic.v1 #765
Conversation
Hi @tcompa, I have a couple of questions about the failed CI. Could you help me?
|
You should push the |
Just to get started, we could start with just |
A first look at https://python-poetry.org/docs/dependency-specification/#multiple-constraints-dependencies suggests that the original plan (either 1.10.16 or >=2.something) doesn't work in poetry, but from what I'm seeing at the moment it seems that this option doesn't exist for pyproject.toml specifications in general. A likely-working approach here is to use of optional extras (e.g. The downside of sticking to just ">=1.10.16" is that if fractal-tasks-core is not compatible e.g. with pydantic <2.3.0, this will not be enforced anywhere and it will lead to unexpected failures downstream. Of course we can add a runtime check of the version, as a temporary solution. @lorenzocerrone this resonates with our latest packaging discussion. Once we migrate to Pydantic v2 for tasks and core library, the reason for accepting a pydantic V1 dependency would only be due to the schema-generation tools. Having two different packages, in principle, would shift this issue to a more narrow space (namely a dev-tools package, where it's more reasonable to also introduce all sort of verbose runtime checks). |
What kind of error do you get with |
This is the error I get running Poetry often uses the syntax So the possible solutions are:
|
Got it, thanks. I saw it was working on poetry but I had not checked with pip.
I would be in favor of this option, with one of the mitigations you suggest. |
Same here
Good! I will first try the post install hook, and if that gets too convoluted, I will add simple runtime check. |
This sounds good to me! Either version of 2 is a good approach for my taste, as we very likely then basically never run into this check :) |
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
In the end I implemented a simple run time check in the main fractal-tasks-core/fractal_tasks_core/__init__.py Lines 4 to 20 in ac8a453
|
@@ -208,7 +208,7 @@ def napari_workflows_wrapper( | |||
if image_inputs: | |||
img_array = da.from_zarr(f"{zarr_url}/{level}") | |||
# Loop over image inputs and assign corresponding channel of the image | |||
for (name, params) in image_inputs: | |||
for name, params in image_inputs: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick question: which tool/version/configuration is making this change? (or did you make it on purpose?)
We don't have such a strict definition of syntax in the repo, and the change is OK.
But let's make sure we use the same tools/versions/configurations to avoid unnecessary diffs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was by mistake, and I agree we should avoid this unnecessary diff. I have been using pro-commits, but I still have some nonstandard setup in my VSCode. I will try to fix it, and if I still have some issues, we can discuss them in our next one-on-one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a couple of tiny comments, but it's all good from my side.
From a clean virtual env $ pip install -e . pydantic==2.0.0
...
$ python -c 'import fractal_tasks_core'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/tommaso/Fractal/fractal-tasks-core/fractal_tasks_core/__init__.py", line 22, in <module>
_check_pydantic_version()
File "/home/tommaso/Fractal/fractal-tasks-core/fractal_tasks_core/__init__.py", line 16, in _check_pydantic_version
raise ImportError(
ImportError: Pydantic version 2.0 is not supported. Please use version ==1.10.16 or >=2.6.3.
---------------------
$ pip install -e . pydantic==1.10.15
Obtaining file:///home/tommaso/Fractal/fractal-tasks-core
Installing build dependencies ... done
Checking if build backend supports build_editable ... done
Getting requirements to build editable ... done
Preparing editable metadata (pyproject.toml) ... done
Collecting pydantic==1.10.15
Using cached pydantic-1.10.15-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.1 MB)
Requirement already satisfied: typing-extensions>=4.2.0 in ./venv/lib/python3.10/site-packages (from pydantic==1.10.15) (4.12.2)
Requirement already satisfied: docstring-parser<0.16,>=0.15 in ./venv/lib/python3.10/site-packages (from fractal-tasks-core==1.0.3a0) (0.15)
Requirement already satisfied: defusedxml<0.8.0,>=0.7.1 in ./venv/lib/python3.10/site-packages (from fractal-tasks-core==1.0.3a0) (0.7.1)
Requirement already satisfied: lxml<5.0.0,>=4.9.1 in ./venv/lib/python3.10/site-packages (from fractal-tasks-core==1.0.3a0) (4.9.4)
Requirement already satisfied: filelock==3.13.* in ./venv/lib/python3.10/site-packages (from fractal-tasks-core==1.0.3a0) (3.13.4)
Requirement already satisfied: pandas<2,>=1.2.0 in ./venv/lib/python3.10/site-packages (from fractal-tasks-core==1.0.3a0) (1.5.3)
Requirement already satisfied: dask>=2023.1.0 in ./venv/lib/python3.10/site-packages (from fractal-tasks-core==1.0.3a0) (2024.6.0)
INFO: pip is looking at multiple versions of <Python from Requires-Python> to determine which version is compatible with other requirements. This could take a while.
INFO: pip is looking at multiple versions of pydantic to determine which version is compatible with other requirements. This could take a while.
ERROR: Cannot install fractal-tasks-core==1.0.3a0 and pydantic==1.10.15 because these package versions have conflicting dependencies.
The conflict is caused by:
The user requested pydantic==1.10.15
fractal-tasks-core 1.0.3a0 depends on pydantic>=1.10.16
To fix this you could try to:
1. loosen the range of package versions you've specified
2. remove package versions to allow pip attempt to solve the dependency conflict
ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts
---------------------
$ pip install -e . pydantic==1.10.16
...
$ python -c 'import fractal_tasks_core; import pydantic; print(pydantic.__version__)'
1.10.16
---------------------
$ pip install -e .
...
$ python -c 'import fractal_tasks_core; import pydantic; print(pydantic.__version__)'
2.7.4 This is all as expected. |
Quick question: is there any specific reason for accepting up to v2.6.2? Anything special supported only starting from 2. |
Looks good to me overall! :) |
There are no strong reasons on my side. It was the lowest version I tested on my tasks (including generating some schemas). |
Checklist before merging
CHANGELOG.md
Following the discussion in #760, this PR:
pydantic.v1
pydantic = ">=1.10.16"
pydantic==1.10.16
&pydantic>=2.6.3
pydantic >2* & <2.6.3