The reason is that snapcraft creates a venv which, in turn, uses the `ensurepip` command built into the interpreter (and also adds -I to filter out PYTHON* variables). `ensurepip` has some code to ignore any environment variable prefixed with "PIP_" which includes PIP_COMPILE.
https://docs.python.org/3/using/cmdline.html#id2
"-I
... All PYTHON* environment variables are ignored, too. Further restrictions may be imposed to prevent the user from injecting malicious code."
3) ensurepip's filtration of all envars prefixed with "PIP_".
I was trying to disable .pyc files by having PIP_COMPILE=false and PYTHONDONTWRITE BYTECODE= false.
But this isn't possible based on the below.
https:/ /pip.pypa. io/en/stable/ user_guide/ #environment- variables (pip allows environment variables instead of command-line arguments) /docs.python. org/3/using/ cmdline. html#envvar- PYTHONDONTWRITE BYTECODE (PYTHONDONTWRIT EBYTECODE disables writing .pyc files at the interpreter level)
https:/
build- environment: &python- build-environme nt BYTECODE: 'false' # disable .pyc generation by setup.py
- PIP_COMPILE: 'false' # disable .pyc generation in pip
- PYTHONDONTWRITE
- SOURCE_DATE_EPOCH: '1591640328'
However, I still had some .pyc files created.
The reason is that snapcraft creates a venv which, in turn, uses the `ensurepip` command built into the interpreter (and also adds -I to filter out PYTHON* variables). `ensurepip` has some code to ignore any environment variable prefixed with "PIP_" which includes PIP_COMPILE.
See below:
1) venv used by snapcraft
https:/ /github. com/snapcore/ snapcraft/ blob/71cebabd81 55937fa329c94f7 d3559b6b2e723b7 /snapcraft/ plugins/ v2/python. py#L117- L120 PYTHON_ INTERPRETER} " -m venv ${SNAPCRAFT_ PYTHON_ VENV_ARGS} "${SNAPCRAFT_ PART_INSTALL} "
"${SNAPCRAFT_
For example: PYTHON_ INTERPRETER $SNAPCRAFT_ PYTHON_ VENV_ARGS $SNAPCRAFT_ PART_INSTALL cluster/ install
echo $SNAPCRAFT_
python3 /root/parts/
python3 -m venv /root/parts/ cluster/ install
2) ensurepip used by venv with -I option passed.
https:/ /github. com/python/ cpython/ blob/58ec58a42b ece5b2804b178c7 a6a7e67328465db /Lib/venv/ __init_ _.py#L291- L298
'--default- pip']
subprocess. check_output( cmd, stderr= subprocess. STDOUT)
cmd = [context.env_exe, '-Im', 'ensurepip', '--upgrade',
https:/ /docs.python. org/3/using/ cmdline. html#id2
"-I
... All PYTHON* environment variables are ignored, too. Further restrictions may be imposed to prevent the user from injecting malicious code."
3) ensurepip's filtration of all envars prefixed with "PIP_".
https:/ /github. com/python/ cpython/ blob/0f5a28f834 bdac2da8a04597d c0fc5b71e50da9d /Lib/ensurepip/ __init_ _.py#L47- L56 "PIP_") ] /github. com/python/ cpython/ blob/0f5a28f834 bdac2da8a04597d c0fc5b71e50da9d /Lib/ensurepip/ __init_ _.py#L88- L119
keys_to_remove = [k for k in os.environ if k.startswith(
for k in keys_to_remove:
del os.environ[k]
https:/