Is there a way in pex land (rather, pants + pex la...
# general
w
Is there a way in pex land (rather, pants + pex land) to only package up pre-compiled python files? “Compiled” in the python bytecode sense. This is assuming the same interpreter is doing the compiling and running of said code
e
No. You can ask for pyc in addition to sources but not just pyc.
w
Okay, that was my understanding - but good to confirm it!
Does it make sense that my
__main__.py
would have python3.9 at the top, when I've specified 3.11 interpreter constraints and platforms?
Copy code
#!/usr/bin/env python3.9

import os
import sys


__INSTALLED_FROM__ = '__PEX_EXE__'
pants.toml
Copy code
[python]
enable_resolves = true
interpreter_constraints = [">=3.11"]
#requirement_constraints = "requirements.constraints.txt"

[python.resolves]
pants-plugins = "build-support/pants-plugins/lock.txt"
python-default = "build-support/python/default_lock.txt"

[python.resolves_to_interpreter_constraints]
pants-plugins = [">=3.9,<3.10"]
# BUILD.pants
Copy code
pex_binary(
  name="apigateway",
  dependencies=[
    ":libapigateway", 
    "//:reqs#uvicorn",
  ],
  interpreter_constraints = [">=3.11"],
  output_path="backend/apigateway/apigateway.pex",
  include_tools=True,
  platforms=["linux-x86_64-cp-311-cp311", "macosx-13.3-arm64-cp-311-cp311",]
)
My wheels are all 3.11 as expected, and the only 3.9 reference appears to be that
__ main__.py
e
This should probably be guessed, but you have https://www.pantsbuild.org/docs/reference-pex_binary#codeshebangcode so just be explicit (again).
w
Yep thanks, I found that again a little while ago - and by explicitly setting a python pointing at it, it works fine - I think it was more just surprise. I'm guessing it was 3.9 because Pants was using 3.9 while setting it?
e
Yes.
w
Got it! Thanks
I do think the docs might need to be updated here, if I"m misunderstanding this:
Set the generated PEX to use this shebang, rather than the default of PEX choosing a shebang based on the interpreter constraints.
It's not choosing a default based on the interpreter_constraints when called via Pants
e
Sounds like it. I'm not exactly sure why you're using ICs though since you specify target platforms.
w
Oh, that's not in prod - that was just trying to see if setting that would change the 3.9 result - wasn't production code
This all runs perfectly via my
scie
- but now I have to try
pex
level to get this working in an Azure container controlled by not-me, which is why I'm even fiddling around with this