Skip to content

Commit a6ad367

Browse files
feat: Add /tesseract to PYTHONPATH, similar to native execution (#372)
#### Description of changes Add `/tesseract` to `PYTHONPATH` in Tesseract containers. This takes containerized execution of `tesseract_api.py` closer to native execution regarding finding Python modules in the same directory etc. #### Testing done Local testing --------- Co-authored-by: Alessandro Angioi <[email protected]>
1 parent 7a92d45 commit a6ad367

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

docs/content/creating-tesseracts/advanced.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ After that is done, you will be able to use the `tesseract-runtime` command in y
150150
This is the exact same command that is launched inside Tesseract containers to run their
151151
various endpoints, and its syntax mirrors the one of `tesseract run`.
152152

153+
```{note}
154+
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`.
155+
```
156+
153157
For instance, to call the `apply` function, rather than first building a `helloworld` image and running this command:
154158

155159
```bash

docs/content/examples/building-blocks/localdependency.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ We can then specify it as a local dependency in `tesseract_requirements.txt` by
4747
./cowsay-6.1-py3-none-any.whl
4848
```
4949

50+
```{note}
51+
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.
52+
```
53+
5054
Finally, let's build the Tesseract, and verify it works
5155
```bash
5256
$ tesseract build .

tesseract_core/sdk/templates/Dockerfile.base

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ COPY "{{ tesseract_source_directory }}/tesseract_api.py" ${TESSERACT_API_PATH}
8383
RUN chmod 444 ${TESSERACT_API_PATH}
8484

8585
ENV PATH="/python-env/bin:$PATH"
86+
ENV PYTHONPATH="/tesseract:$PYTHONPATH"
8687

8788
{% if config.build_config.package_data %}
8889
# Copy package data to image

0 commit comments

Comments
 (0)