Skip to content
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

Detect missing pydantic dependency (e.g. pydantic-settings or extra types) #104

Open
kkirsche opened this issue Jul 18, 2023 · 4 comments
Open
Labels
good first issue Good for newcomers

Comments

@kkirsche
Copy link
Contributor

Hey team,

I wasn't sure if you would be comfortable with this, but what's your opinion on telling the user when they are missing a pydantic dependency, such as pydantic-settings is using BaseSettings in Pydantic V1?

This could spit out a warning (whether that's stdout, stderr, log.txt, or somewhere else) or a # TODO comment if the pydantic-settings package isn't installed.

This will help users more quickly identify when their application requires packages that are not currently installed.

To detect if a package is installed without importing it (for safety reasons), importlib.util can be used:

from importlib.util import find_spec

print(find_spec("pydantic-settings"))
# ''

print(find_spec("pydantic"))
# 'ModuleSpec(name='pydantic', loader=<_frozen_importlib_external.SourceFileLoader object at 0x104e18240>, origin='/Users/kkirsche/.asdf/installs/python/3.11.4/lib/python3.11/site-packages/pydantic/__init__.py', submodule_search_locations=['/Users/kkirsche/.asdf/installs/python/3.11.4/lib/python3.11/site-packages/pydantic'])'

Documentation on find_spec:
https://docs.python.org/3/library/importlib.html#importlib.util.find_spec

@Kludex
Copy link
Member

Kludex commented Jul 18, 2023

Hmmm... I think it makes sense to log a message telling the user to install it. 👍

@Kludex Kludex added the good first issue Good for newcomers label Sep 18, 2023
@Kludex
Copy link
Member

Kludex commented Sep 18, 2023

PR welcome to add a TODO above the import pydantic_settings.

@Kludex
Copy link
Member

Kludex commented Dec 27, 2023

Actually, a message on stdout would be better.

@yctomwang
Copy link

@Kludex Hi Marcelo, I am a huge fan of the pydantic and I have always wanted to contribute to things related to it. I have made an attempt to add a message on stdout! Thanks again for the great work you guys put into pydantic and bump-pydantic!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants