linkml / linkml-runtime

Runtime support for linkml generated models
https://linkml.io/linkml/
Creative Commons Zero v1.0 Universal
24 stars 23 forks source link

Bump pydantic requirement #272

Closed caufieldjh closed 1 year ago

caufieldjh commented 1 year ago

I'm trying to work with llm in OntoGPT, but it requires pydantic>=2.0.0. Linkml-runtime currently requires pydantic (>=1.10.2,<2.0.0).

Loosening the requirement to allow pydantic of >=2 installs pydantic 1.10.7 (on Py3.9, at least) but also appears to pass tests. Mandating pydantic >=2 installs 2.1.1. This means some differences in model definition (e.g., define params to pass to new model objects with __signature__ attribute) but all tests pass after accounting for that.

codecov-commenter commented 1 year ago

Codecov Report

Merging #272 (e143932) into main (74d699c) will increase coverage by 0.17%. Report is 43 commits behind head on main. The diff coverage is 74.15%.

:exclamation: Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff             @@
##             main     #272      +/-   ##
==========================================
+ Coverage   65.86%   66.03%   +0.17%     
==========================================
  Files          56       60       +4     
  Lines        7613     7699      +86     
  Branches     2012     2020       +8     
==========================================
+ Hits         5014     5084      +70     
- Misses       2009     2025      +16     
  Partials      590      590              
Files Changed Coverage Δ
linkml_runtime/linkml_model/validation.py 0.00% <0.00%> (ø)
linkml_runtime/utils/context_utils.py 73.33% <ø> (+5.00%) :arrow_up:
linkml_runtime/loaders/loader_root.py 69.84% <54.28%> (+3.17%) :arrow_up:
linkml_runtime/dumpers/rdf_dumper.py 65.90% <55.55%> (-5.89%) :arrow_down:
linkml_runtime/loaders/delimited_file_loader.py 82.85% <82.85%> (ø)
linkml_runtime/dumpers/json_dumper.py 77.77% <84.61%> (-1.54%) :arrow_down:
linkml_runtime/loaders/yaml_loader.py 92.30% <85.71%> (+1.00%) :arrow_up:
linkml_runtime/utils/schemaview.py 87.79% <88.88%> (ø)
linkml_runtime/dumpers/delimited_file_dumper.py 89.65% <89.65%> (ø)
linkml_runtime/dumpers/__init__.py 100.00% <100.00%> (ø)
... and 12 more
caufieldjh commented 1 year ago

Traces on the erroring tests:

ERROR: tests.test_loaders_dumpers.test_dumpers_pydantic (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: tests.test_loaders_dumpers.test_dumpers_pydantic
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/opt/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/home/runner/work/linkml-runtime/linkml-runtime/tests/test_loaders_dumpers/test_dumpers_pydantic.py", line 7, in <module>
    from tests.test_loaders_dumpers.models.books_normalized_pydantic import Book, BookSeries, Author
  File "/home/runner/work/linkml-runtime/linkml-runtime/tests/test_loaders_dumpers/models/books_normalized_pydantic.py", line 21, in <module>
    use_enum_values = True):
  File "/home/runner/.cache/pypoetry/virtualenvs/linkml-runtime-M8KxIAsy-py3.7/lib/python3.7/site-packages/pydantic/_internal/_model_construction.py", line 123, in __new__
    cls: type[BaseModel] = super().__new__(mcs, cls_name, bases, namespace, **kwargs)  # type: ignore
  File "/opt/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/abc.py", line 126, in __new__
    cls = super().__new__(mcls, name, bases, namespace, **kwargs)
TypeError: __init_subclass__() takes no keyword arguments

======================================================================
ERROR: tests.test_loaders_dumpers.test_loaders_pydantic (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: tests.test_loaders_dumpers.test_loaders_pydantic
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/opt/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/home/runner/work/linkml-runtime/linkml-runtime/tests/test_loaders_dumpers/test_loaders_pydantic.py", line 6, in <module>
    from tests.test_loaders_dumpers.models.books_normalized_pydantic import BookSeries
  File "/home/runner/work/linkml-runtime/linkml-runtime/tests/test_loaders_dumpers/models/books_normalized_pydantic.py", line 21, in <module>
    use_enum_values = True):
  File "/home/runner/.cache/pypoetry/virtualenvs/linkml-runtime-M8KxIAsy-py3.7/lib/python3.7/site-packages/pydantic/_internal/_model_construction.py", line 123, in __new__
    cls: type[BaseModel] = super().__new__(mcs, cls_name, bases, namespace, **kwargs)  # type: ignore
  File "/opt/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/abc.py", line 126, in __new__
    cls = super().__new__(mcls, name, bases, namespace, **kwargs)
TypeError: __init_subclass__() takes no keyword arguments
pkalita-lbl commented 1 year ago

@caufieldjh I pushed a change that updates the pyproject.toml file to indicate that linkml-runtime is compatible in downstream projects with either Pydantic 1 or 2. But I left the poetry.lock file as-is so that we get Pydantic 2 in this project's environment (and compatible with your test changes).

caufieldjh commented 1 year ago

Works for me!