I have code that reads a configuration file in a __init__.py
file inside a certain module. Let's say I have a structure like this:
dir/
setup.py
src/
__init__.py
properties/
config.yaml
module/
__init__.py ---> this file reads src/properties/config.yaml
The code to read is something like this:
with open(os.path.join(_ROOT, os.path.normpath('src/properties/config.yaml'))) as f:
config = yaml.load(f)
Where _ROOT
is defined in the top src/__init__.py
as follows:
ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
Basically, _ROOT=dir
.
This works like a charm in every platform, except when src
is used as a zip package on which reading returns a FileNotFoundError: ... No such file or directory: ... package.zip\\src\\properties\\config.yaml
.
Is there a way to address this problem, do I need to deal the situation when package is zipped, should I avoid loading the file inside the package code...?
I tried an extensive google search for this but I found nothing.
Thank you in advance.