Skip to content

Conversation

@linusseelinger
Copy link
Contributor

@linusseelinger linusseelinger commented Oct 2, 2025

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

@linusseelinger linusseelinger changed the title Add /tesseract to PYTHONPATH, similar to native execution feat: Add /tesseract to PYTHONPATH, similar to native execution Oct 2, 2025
@codecov
Copy link

codecov bot commented Oct 2, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.35%. Comparing base (7a92d45) to head (360b754).

Additional details and impacted files
@@             Coverage Diff             @@
##             main     #372       +/-   ##
===========================================
+ Coverage   66.27%   76.35%   +10.07%     
===========================================
  Files          29       29               
  Lines        3345     3345               
  Branches      525      525               
===========================================
+ Hits         2217     2554      +337     
+ Misses        936      558      -378     
- Partials      192      233       +41     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@apaleyes apaleyes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, thanks! do you want to take this all the way and add an example to showcase this change?

@xalelax
Copy link
Contributor

xalelax commented Oct 6, 2025

I wanted to write the same; full example on just this is probably overkill, but maybe mention it:

@apaleyes
Copy link
Contributor

apaleyes commented Oct 6, 2025

@xalelax why is a full example an overkill? in the simplest case it is literally 3 files, no more than 20 lines each

@xalelax
Copy link
Contributor

xalelax commented Oct 9, 2025

I meant that it's such a small change that probably doing a whole example is a bit too much, not in the sense that it would take us a lot to write it, but that it would be eccessive detail for such a small feature. I'd just mention somewhere in the docs that the path of tesseract_api.py is in the PYTHONPATH (or something more simple and expressive than that), but I'd be fine with an example as well.

@xalelax xalelax enabled auto-merge (squash) October 30, 2025 13:58
@xalelax xalelax merged commit a6ad367 into main Oct 30, 2025
71 of 73 checks passed
@xalelax xalelax deleted the linus/feat-pythonpath-container branch October 30, 2025 14:04
@pasteurlabs pasteurlabs locked and limited conversation to collaborators Oct 30, 2025
@dionhaefner
Copy link
Contributor

I'm a bit confused by this PR, specifically this statement:

This takes containerized execution of tesseract_api.py closer to native execution regarding finding Python modules in the same directory etc.

From my understanding (and testing), native execution via tesseract-runtime does not put the script on PYTHONPATH. I.e., we have now diverged between containerized and non-containerized usage? @linusseelinger @xalelax

@xalelax
Copy link
Contributor

xalelax commented Nov 14, 2025

@dionhaefner you are correct; this would be the case only if one happens to run tesseract-runtime when cwd is the folder where tesseract_api.py lives, which might be common when developing stuff, but not universal even when scoped to just dev work.

TBH I'm not a fan of the concept in general, and if not backed by some user story I'd just revert this, or achieve parity by adding to the PYTHONPATH the parent of TESSERACT_API_PATH (once it's done on the runtime, there should be no need to add it in the dockerfile btw)

@linusseelinger WDYT?

(also, sorry for the late reply, I had missed this 🙏 )

@dionhaefner
Copy link
Contributor

achieve parity by adding to the PYTHONPATH the parent of TESSERACT_API_PATH

Yes either this or add a sharp edge to the docs (with a snippet that does sys.path.append(os.path.dirname(__file__))). I'm not sure if there are unintended side effects when adding the parent dir to the path. It's certainly unintuitive though that users also need to add Python modules to package_data in order to play well with containerization. So if they already need to make a conscious choice on where to put their auxiliary modules, they might as well add them to sys.path?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants