<#20537 Can't convince Pants/Pex to run/build with...
# github-notifications
c
#20537 Can't convince Pants/Pex to run/build with `PYTHONOPTIMIZE=2` or `-OO` mode. Issue created by originalrkk Describe the bug I am trying to coax Pants into creating Docker images and Pex binaries that contain no assertions or docstrings (Python
-OO
mode). Our binaries are built similar to this: https://www.pantsbuild.org/blog/2022/08/02/optimizing-python-docker-deploys-using-pants (For whatever reason, we couldn't get the full option to work -- the final Docker image kept failing to find third-party dependencies like
awswrangler
-- but we use two
pex_binary()
targets for srcs/deps that feed into a single
docker_image()
.) Here's what I've tried: • Setting
env={'PYTHONOPTIMIZE': '2'}
on
pex_binary()
BUILD rules. • Using
ENV PYTHONOPTIMIZE=2
in the Docker image commands. • Using
ENTRYPOINT ["env", "PYTHONOPTIMIZE=2", "/bin/{name}/pex"]
in the final Docker image. • Using
CMD env PYTHONOPTIMIZE=2 /bin/{name}/pex
in lieu of
ENTRYPOINT
. • Setting
--inject-env=PYTHONOPTIMIZE=2
in the
RUN PEX_TOOLS=1
invocations; it doesn't recognize the flag. • Setting it in
[subprocess-environment].env_vars
in pants.toml. None of these work -- if we point at a toy program with an
assert 0 == 1
, it will alway fails rather than skipping over the assertion. Pants version 2.17.0 OS Linux pantsbuild/pants