Search code examples
pythonassertpython-poetry

Run poetry-installed python scripts in optimized mode


I have a pyproject.toml:

[tool.poetry.scripts]
# aka entry points or console scripts for setup.py users
merge = 'mypackage.__main__:main'

mypackage contains some assert statements that I do not want run in production, but I would like to run these scripts in "optimized" mode.

Is this possible to do with a poetry script?


Solution

  • As related on my ill-thought-out feature request for Poetry, I should just be setting PYTHONOPTIMIZE=1 for the user running these packages in production, which is functionally identical to calling the script with -O.