NowanIlfideme / pydantic-yaml

YAML support for Pydantic models

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Install without extras result in broken package

csitarichie opened this issue · comments

If pydantic-yaml is installed on a bare system or empty venv without extras running the example code produces import error

like this

 File "src/yaml-parser/yaml_parser/yaml_parser.py", line 2, in <module>
    from pydantic_yaml import YamlStrEnum, YamlModel
ImportError: cannot import name 'YamlStrEnum' from 'pydantic_yaml' (/workspace/.pyenv_mirror/poetry/virtualenvs/yaml-parser-F1ZEnFR_-py3.8/lib/python3.8/site-packages/pydantic_yaml/__init__.py)

by installing with extras"ruamel pyyaml solves the problem and example tuns.

Hmm, I'm not sure what the proper behavior here should be. Since I made the decision to support ruamel.yaml AND pyyaml, but don't want to force installation of either package, there needs to be a dependency on them somewhere. One option is to force an error when installing, which would probably avoid the above case. The other option would be to allow importing them but failing to read/write YAML if there's no library installed (which probably seems worse!).

Related SO question https://stackoverflow.com/questions/73659287/importerror-cannot-import-name-yamlmodel-from-pydantic-yaml

I find it weird that all errors are silenced on import / init eval. What's the reasoning here? On install we're not importing anything, and on import it should scream one of these required deps are missing. Otherwise the user doesn't know what's going on.

Do you want to allow installing from source? Why wouldn't the error be raised then?