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
How to use decouple with a regular python library? #22
Comments
When you It has a magic that searches for the settings.ini file from the caller's module directory. If it can't find there, it keeps searching up the tree. If you want to have full controle and point directly where your settings.ini is:
This API has room for improvement. You're the 2nd to request something like this. |
I have interest in this feature too. I solve it by override
|
@nielsonsantana can you provide a patch so we can invert the dependency on the path? |
I trying figure out how change your code. Are you suggesting to override "_caller_path"?
for
In my tests, it's work based on where it is called from. Per example, if it is called from a terminal, it will use the local |
…couple como uma biblioteca normal
I'd like to make a design suggestion: avoid configuration handling in libraries. The "right place" to handle configuration is your project (that requires/uses the library). It's better make your library configuration-agnostic, so, the users of your library can use any configuration system. And you can also reduce the number of depedencies. "Wrong" way# mylib.py
class Client:
def __init__(self, url=None):
self.url = config("URL", default="http://localhost/") # myproject.py
from mylib import Client
client = Client() "Right" way# mylib.py
class Client:
def __init__(self, url):
self.url = url # myproject.py
from mylib import Client
url = config("URL", "http://localhost")
client = Client(url) |
I faced this issue when trying to use This PR #28 allows the users to instantiate config = AutoConfig(os.getcwd()) |
Fixed tks to @rmax |
I am using decouple with a library I am developing.
It works just fine when I am testing it from the development directory. However after I install the library and try to import it from a python process started on a arbitrary directory, it cannot find the settings.ini even if I copy it to the directory I am starting python from.
In such cases, where should the settings.ini be placed? this should be made clear in the documentation.
The text was updated successfully, but these errors were encountered: