SYS_PATH_CONF
The SYS_PATH_CONF
configuration allows you explicitly specify which paths you want to include in your project's sys.path
. Doing so can allow users to import modules and packages from sources outside of their direct project.
If this option is not specified, Prism throws a warning and automatically adds the project directory
To see why this is useful, suppose you had the following directory structure:
all_prism_projects/
|- prism_project_1/
|- prism_project.py
|- tasks/...
|- utils1.py
|- prism_project_2/
|- prism_project.py
|- tasks/...
|- utils2.py
|- prism_project_2/
|- prism_project.py
|- tasks/..
|- utils2.py
|- common_utils.py
By default, each project directory is added to each Prism project's sys.path
at runtime. That means that prism_project_1
can access utils1.py
, prism_project_2
can access utils2.py
, and so on. However, the parent directory (i.e., all_prism_projects/
) is not added to the project's sys.path
by default, so common_utils.py
would not be accessible to any of the projects.
This can easily be remedied with SYS_PATH_CONF
. For example:
# all_prism_projects/prism_project_1/prism_project.py
...
SYS_PATH_CONF = [
Path(__file__).parent,
Path(__file__).parent.parent # added the parent path!
]
...
Now, a module in prism_project_1
can import common_utils
at runtime:
# all_prism_projects/prism_project_1/tasks/example_module.py
import prism_project # this is OK since project directory is in sys.path
import common_utils # this is OK since all_prism_projects/ is in sys.path
import prism.task
class ExampleTask(prism.task.PrismTask)
...
More information on sys.path
can be found here.
Last updated