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

How do i pass file to load the settings using LazySettings. #140

Open
BHAUTIK04 opened this issue May 19, 2020 · 5 comments
Open

How do i pass file to load the settings using LazySettings. #140

BHAUTIK04 opened this issue May 19, 2020 · 5 comments

Comments

@BHAUTIK04
Copy link

I am using simple-settings module for my app. In one scenario, app has 2 different module and both has settings file with same naming convention(settings/dev.py). In this case when i load module by LazzySettings(settings.dev) at two different places, where it loads same first module. Is there any way we can pass file name with absolute path to load the settings.

@drgarcia1986
Copy link
Owner

It sounds like a python path problem.
For python modules, simple-settings will perform the python import module function to read the file, so the behavior is the same as the regular python import (f.ex import settings.dev).

You could share a simple example to help to found a solution?

Meanwhile (if it's not a problem) you can use another strategy to read settings (yaml, json, toml, etc).

@BHAUTIK04
Copy link
Author

@drgarcia1986 Thanks for your quick reply.
I will create a sample structure for you to find a solution. Across the different apps, I have same structure so I can not change the file strategy from .py to .json or .yaml. Otherwise, I would have change the dir name itself from settings to appname_settings/dev.py.
I will share structure with the issue I am facing.

@drgarcia1986
Copy link
Owner

hi @BHAUTIK04 any news?

@BHAUTIK04
Copy link
Author

BHAUTIK04 commented Jun 18, 2020

sample_settings.zip

Hi @drgarcia1986 , Sorry I did not get time to get back regarding the issue. Here I have created an example structure and attached.
Structure explanation :-

  • project directory - p1, p2, p3
  • p1 is the main project which contains shell script to run python file (run_test.py)
  • p2 and p3 are different directories which contains settings files settings/one.py
    I attach output for the ./abc.sh script.
    image
    Please let me know if you find any solution and suggest me something if I am doing wrong here.

@Drachenfels
Copy link

This was pythonpath problem, to run the project from sample_settings.zip I had to do this:

PYTHONPATH=p1:p2:p3 python p1/run_test.py

Take a look what is the path to settings:

p2/settings/one.py
p3/settings/one.py

Now forget about simple-settings for the moment and run this:

$ PYTHONPATH=p1:p2:p3 python

And then type:

>>> from settings import one
>>> one
<module 'settings.one' from 'p2/settings/one.py'>

There is no way to import settings/one.py from p3, this is how python works.

That being said you can do this:

from p2.settings import one
from p3.settings import one as one_mk2

With big caveat, that PYTHONPATH points to the root of the project and not inidvidual sub-projects (i.e. folder that contains p1, p2 and p3 and not p1, p2, p3 itself).

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

No branches or pull requests

3 participants