diff --git a/docs/content/creating-tesseracts/advanced.md b/docs/content/creating-tesseracts/advanced.md index c1400c4f..343e870d 100644 --- a/docs/content/creating-tesseracts/advanced.md +++ b/docs/content/creating-tesseracts/advanced.md @@ -150,6 +150,10 @@ After that is done, you will be able to use the `tesseract-runtime` command in y This is the exact same command that is launched inside Tesseract containers to run their various endpoints, and its syntax mirrors the one of `tesseract run`. +```{note} +When running without containerization, the directory containing `tesseract_api.py` is automatically added to `PYTHONPATH`, allowing you to import additional Python modules from that directory. This behavior matches what happens inside Tesseract containers, where the path containing `tesseract_api.py` is also added to `PYTHONPATH`. +``` + For instance, to call the `apply` function, rather than first building a `helloworld` image and running this command: ```bash diff --git a/docs/content/examples/building-blocks/localdependency.md b/docs/content/examples/building-blocks/localdependency.md index 452e3336..e31a30e7 100644 --- a/docs/content/examples/building-blocks/localdependency.md +++ b/docs/content/examples/building-blocks/localdependency.md @@ -47,6 +47,10 @@ We can then specify it as a local dependency in `tesseract_requirements.txt` by ./cowsay-6.1-py3-none-any.whl ``` +```{note} +If you have additional Python modules in the same directory as `tesseract_api.py`, you can import them directly without any special configuration. The directory containing `tesseract_api.py` is automatically added to `PYTHONPATH` in the container environment. +``` + Finally, let's build the Tesseract, and verify it works ```bash $ tesseract build . diff --git a/tesseract_core/sdk/templates/Dockerfile.base b/tesseract_core/sdk/templates/Dockerfile.base index c5132696..a4bc92ab 100644 --- a/tesseract_core/sdk/templates/Dockerfile.base +++ b/tesseract_core/sdk/templates/Dockerfile.base @@ -83,6 +83,7 @@ COPY "{{ tesseract_source_directory }}/tesseract_api.py" ${TESSERACT_API_PATH} RUN chmod 444 ${TESSERACT_API_PATH} ENV PATH="/python-env/bin:$PATH" +ENV PYTHONPATH="/tesseract:$PYTHONPATH" {% if config.build_config.package_data %} # Copy package data to image