tr11 / python-configuration

A Python library to load configuration parameters

Home Page:https://tr11.github.io/python-configuration/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature] Improved / verbose dependency handling

DeadlyFirex opened this issue · comments

Description
First of all, great work on the library, I appreciate your work!

As of right now, the __init__.py file for this library properly checks if certain dependencies are available, but does not report anything if libraries are missing, instead, the library simply states it fails to import a certain class or function.
If this issue is agreed upon, I would not mind forking and providing a small change to implement this check.

Context
Currently, this is the output the Python interpreter provides when attempting to import a class or function that does not have it's underlying dependencies installed.

Traceback (most recent call last):
  File "/path/to/configuration.py", line 1, in <module>
    from config import Configuration, ConfigurationSet, EnvConfiguration, TOMLConfiguration, JSONConfiguration
ImportError: cannot import name 'TOMLConfiguration' from 'config' (/path/to/env/lib/python3.11/site-packages/config/__init__.py)

Expected Behavior

  1. Provide a verbose error, for example:
Traceback (most recent call last):
  File "/path/to/configuration.py", line 1, in <module>
    from config import Configuration, ConfigurationSet, EnvConfiguration, TOMLConfiguration, JSONConfiguration
ImportError: Cannot use class <TOMLConfiguration>, install dependency "toml".
  1. Create an optional_requirements.txt.
  2. Create documentation outlining the dependencies of certain classes.

Use Case Examples

  • Developers are capable of identifying missing libraries when using functions/classes that rely on them.
  • Developers can read documentation to identify optional dependencies.
  • Developers receive a verbose exception when attempting to use classes/functions that rely on uninstalled libraries.

Additional Information
N/A

It'd be great to implement 1. as you described, the current behavior isn't great. For 2, we are using poetry to manage dependencies, which already includes a section for the optional libraries here. For the documentation, maybe we can improve the Installing section to list all the optional extra packages and what they do.

Opened pull request: #88
Minor changes to ensure the desired result. Not much else.