Hi team, when using pants on Jenkins pipeline, is ...
# general
w
Hi team, when using pants on Jenkins pipeline, is there a way I could get the generated hash value? In pants, we have PANTS_NAMED_CACHES_DIR. For example,
Copy code
PANTS_NAMED_CACHES_DIR="/myProject/pants/named_caches"
when running pytest, I see that the libraries are loaded in
Copy code
"/myProject/pants/named_caches/pex_root/venvs/s/4d6744fa/venv/lib/python3.9/....."
is there a way I could get the value “4d6744fa”
e
There is, but this is a Pex generated value that Pants knows little about. What do you need this path for exactly?
Maybe more fruitful - you've had 3? questions (this one being the 3rd) IIRC recently revolving around pytest and Pants and I think 0 of those has been resolved in Slack, they're all just dangling threads. It might be good to get a more comprehensive view of the problem you are trying to tackle. Is it at all possible to get an open source view of the problem you're working on?
w
yeah, I need to overwrite the library in place in Jenkins pipeline, so I need to find the location of where the file of that library is stored
sorry, unfortunately it’s a bit hard to recreate the same environment from my work laptop to my personal laptop😅 I eventually found some workarounds for those errors that are not pants related, so I just didn’t continue the thread
e
There will be no easy way to do this. Why do you need to overwrite a library like this though?
w
there’s an error in the library, I need to switch some code in place
what’s the “no-easy” way you mentioned?
e
Well, from within the venv, aka in your code running in the venv, you can always
import x; x.__file__
to get the path of the library. However, that imports the broken library; so you need to unimport it (recursively) - no easy task in Python. That leads to the idea of running that step in a subprocess using sys.executable and retrieving the result by printing it to a piped stdout, for example. Super crazy. Can you not fork and patch the library instead or is the library not available via VCS?
w
unfortunately no….
is there a way I could do something like python -c “import x; x.__file__” in pants
e
What do you mean "in pants"?
Is it tests having this issue or something else?
w
ahhh, I would like to change the library file before I run
Copy code
pants test ...
e
Why must it be before?
Why not in a conftest file as a pre-test step?
w
hmm we could, that’s a good suggestion
thanks