I am developing a project (project-1) that depends on another project (project-2). I am doing constant modification on both, so I don't feel comfortable to install the project-2 to import it. (except if there is a way to easily work on an install library, but even then, I like my work to be self contained since I often deploy it on remote servers using Pycharm)
very simple overview:
project-1/
└── LOT of stuff there
project-2/
└── project_2/
├── __init__.py
├── config.py
├── main.py
└── also LOT of stuff there
currently I have a file called config.py
in my project-2
import sys
from pathlib import Path
# project_1
project_1_path = Path(__file__).parents[2].joinpath('project_1')
project_1_databases_folder = project_1_path.joinpath('databases')
sys.path.insert(0, str(project_1_path))
print('project_2 set in system path')
# project_2
path_project_2 = Path(__file__).parent.parent
path_models_folder = path_project_2.joinpath('models')
path_datasets_folder = path_project_2.joinpath('datasets')
path_experiments_folder = path_project_2.joinpath('experiments')
When I launch the main of my project_2, I do import config as c
. So the path is set and I can use the different path constants.
I was wondering if it is a "good" way and what should I do to improve it. I was thinking of creating a configure
function in the config
file and execute it in the __init__.py
of the package. Not sure which solution is the best
def configure():
sys.path.insert(0, str(project_1_path))
Any feedback would be very much appreciated! thanks