How To Run a Python Source That Uses Files In Repo Subdirectory #20206
-
I'm likely missing something, but more or less, no matter what I do, pants seems to be running my scripts from repo root, without relocated_files targets present. Repo Structure (Monorepo):
The key idea is that However, I want to be able to use pants to run main.py during development/testing, without breaking the script's access to
At this point, my main question is - why doesn't the python script's working directory use the sandbox directory when that setting is applied? It seems this would resolve my issue. Secondarily, is there any way to run a target with the working directory equal to the BUILD file location for that target? This would be so, so much simpler for my use case I think, but I could not find any way to change the working directory in a way that doesn't break normal, deployed operation. I feel it's likely I'm missing something silly here, so any guidance on how to allow a simple relative file import to work as expected from a script & file with paths relative to their common subdirectory instead of root would be greatly appreciated. I've spent probably 6 hours with the docs trying to get this one thing working 😅 so I've been as thorough as I could. Note: this repo is all on python 3.12, and would not install on the latest stable release, hence the alpha.
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
I don't have time to really dig in yet, but on first glance, I wonder if this is a resources vs. files problem (it's confusing and subtle). Things will only be included in a Does switching from |
Beta Was this translation helpful? Give feedback.
Ah, well. Thanks for trying things.
I don't know of one... except for having the code that is being run itself do this.
For instance, could you have a "local" version of the target itself that varies slightly from the production code? For instance, does a few set-up things like switching directories and/or loading the config before calling into the real
main()
. (For my work codebase, this is effectively what…