I have a python codebase with the following folder structure
project/
│
├── src/
│ ├
│ ├──utils/
│ │
│ ├──data/
│ │
│ ├──module1/
│ │
│ └──module2/
│
├──data/
│ │
│ ├──raw/
│ │
│ ├──processed/
I have an app.py file in module1 that imports utils/utils.py. app.py calls a function in utils.py and passes a path - say 'data/raw/test.pdf'. and the function in utils.py fetches the file and returns something back. What is the best way to include the path in both locations, assuming that the invocation is done from a different directory?
Using a simple relative path like
path = '../../data/raw/test.pdf'
file = pathlib.Path(__file__).parent / path
isn't super helpful since I use a path relative to module1/app.py, but when this is passed to utils/utils.py, the relative reference might end up being different.
What is the best practice for referencing paths that may be passed from a function in one directory to another function in a different project (different directory)? Do we have to resort to using absolute paths in such cases?