wemake-services/django-split-settings

Include an absolute path file.

alexsilva opened this issue · 8 comments

I've been checking the code and it doesn't seem possible to include a file with absolute path. Is there any alternative in this regard ?

The code always gathers the file paths relative to the settings it calls include.

pattern = os.path.join(conf_path, conf_file)

Thanks for raising this question!

I would love to know more about your use-case. Why do you need the absolute path?

In my case it would be for plugins to be able to add configuration files without being in the main package.

Is not it. Plugins settings is loaded and added to the main project settings at startup.

Django boot

Load settings
---- Load plugins
---- Loaf plugins settings (add abs path)

A simple os.path.isabs(conf_file) check already solves this issue.

    for conf_file, __name in args:
        saved_included_file = scope.get('__included_file__')
        if not os.path.isabs(conf_file):
            pattern = os.path.join(conf_path, conf_file)
        else:
            pattern = conf_file
        # find files per pattern, raise an error if not found (unless file is
        # optional)
        files_to_include = glob.glob(pattern)
        if not files_to_include and not isinstance(conf_file, _Optional):
            raise IOError('No such file: {}'.format(pattern))

The thing is that I don't want to add a core support for this case. Why?
Because generally absolute paths are a disaster! It is guaranteed not to work as someone expects.

So, I would like to find any other ways to help you in your extraordinary use-case.