hundreds-father-404
06/15/2021, 8:33 PMinterpreter_constraints
on a pex_binary
target would override the transitive closure. In v2, we "fixed" it to instead act like all other interpreter constraints, to be mixed in.
The practical impact is described in https://www.pantsbuild.org/docs/python-interpreter-compatibility#using-multiple-python-versions-in-the-same-project
This means that every dependency of a target must also be compatible with its interpreter constraints.Thoughts if that was a mistake or not?
enough-analyst-54434
06/15/2021, 8:34 PMhundreds-father-404
06/15/2021, 8:34 PMinterpreter_constraints
to python_distribution
to likely fix an issue @big-xylophone-43403 reported, and because I think it's sensible for python_distribution
to have the field similar to how pex_binary
has it
So I'm revisiting if we should override vs. mix-inhundreds-father-404
06/15/2021, 8:35 PMWhy was the 1st decision considered rock solid at the time?Which decision: v1 to override, or the decision to change v2 to add in?
enough-analyst-54434
06/15/2021, 8:35 PMenough-analyst-54434
06/15/2021, 8:38 PMhundreds-father-404
06/15/2021, 8:38 PMenough-analyst-54434
06/15/2021, 8:38 PMenough-analyst-54434
06/15/2021, 8:39 PMhundreds-father-404
06/15/2021, 8:41 PMhundreds-father-404
06/15/2021, 8:44 PMinterpreter_constraints_override
(exclusive w/ interpreter_constraints
). In the meantime, stick with current sensible behavior. Sg?enough-analyst-54434
06/15/2021, 8:44 PMenough-analyst-54434
06/15/2021, 8:45 PMenough-analyst-54434
06/15/2021, 8:45 PMhundreds-father-404
06/15/2021, 8:46 PMenough-analyst-54434
06/15/2021, 8:48 PMhundreds-father-404
06/15/2021, 8:53 PM['CPython>=2.7,<4', 'CPython>=3.6']Now it correctly results in:
['CPython>=2.7,>=3.6,<4']
enough-analyst-54434
06/15/2021, 8:54 PMenough-analyst-54434
06/15/2021, 8:55 PMhundreds-father-404
06/15/2021, 8:55 PMenough-analyst-54434
06/15/2021, 8:56 PMhundreds-father-404
06/15/2021, 8:57 PMenough-analyst-54434
06/15/2021, 9:16 PMhundreds-father-404
06/15/2021, 9:20 PMprovides=setup_py()
--
I'm waiting for user to confirm in https://pantsbuild.slack.com/archives/C046T6T9U/p1621624847091700, but I'm pretty sure the bug is that they have a python_distribution
with no dependencies on python_library
targets. Meaning transitive closure has no constraints. So Py2 is getting picked up for them, which they can't use
Adding interpreter_constraints
to python_distribution
fixes thisenough-analyst-54434
06/15/2021, 9:30 PMhundreds-father-404
06/15/2021, 9:30 PMenough-analyst-54434
06/15/2021, 9:31 PMenough-analyst-54434
06/15/2021, 9:31 PMenough-analyst-54434
06/15/2021, 9:31 PMenough-analyst-54434
06/15/2021, 9:38 PMhundreds-father-404
06/15/2021, 9:38 PMsetup_py_commands
because we need to know which interpreter to run setuptools
. You removed [setuptools].interprerter_constraints
in 2.4 for correctness reasons
it seems to me that the global constraints should still apply in this case?That is the impact of my PR, we will use global constraints in the default case, whereas we currently would use no constraints at all when running setuptools. I'll put this up rn
enough-analyst-54434
06/15/2021, 9:39 PMhundreds-father-404
06/15/2021, 9:41 PMsetup_py_commands
isn't set, so the ICs are completely ignored. ICs are only used with setup_py.py
to determine what to run setuptools
with + if we have Py2 for namespace packages handlingenough-analyst-54434
06/15/2021, 9:43 PMhundreds-father-404
06/15/2021, 9:46 PMThere is an algorithm to determine IC using target deps. If none, then the default IC.Ah, that may be the source of confusion. The algorithm only uses
[python-setup].interpreter_constraints
as a default for targets who have an interpreter_constraints
field defined. Otherwise it skips the target.
So, if you have only a single python_distribution
target w/ no deps, you get empty constraints backenough-analyst-54434
06/15/2021, 9:48 PMenough-analyst-54434
06/15/2021, 9:49 PMenough-analyst-54434
06/15/2021, 9:50 PMhundreds-father-404
06/15/2021, 10:07 PMrelease.sh
sets `PYTHON_SETUP_INTERPRETER_CONSTRAINTS`:
python_distribution(
name="pants-packaged-py37", interpreter_constraints=["==3.7.*"], **_pants_packaged_kwargs
)
python_distribution(
name="pants-packaged-py38", interpreter_constraints=["==3.8.*"], **_pants_packaged_kwargs
)
python_distribution(
name="pants-packaged-py39", interpreter_constraints=["==3.9.*"], **_pants_packaged_kwargs
)
But that fails due to multiple owners of the same first party code 🤔
--
Even with that, I do think there's value in letting you set constraints on an individual python_distribution
. Examples:
* Your library code works with 3.6+. But you must run setuptools with specifically 3.8, e.g. for the correct native platform to be used. You shouldn't need to constrain your python_library
to do that
* You have no first party code in your dist. Your repo's default is Py2 or Py3.5+. But you're using a newer version of setuptools so you can't run it with Py2
These types of situations are why we added back interpreter_constraints
to pex_binary
and python_awslambda
. @jolly-midnight-72759 and @helpful-lunch-92084 shared that they were setting that field a lot and were very happy to see it come back.enough-analyst-54434
06/15/2021, 10:14 PMhundreds-father-404
06/15/2021, 10:16 PMpex_binary
and python_awslambda
) and that is resilient to situations we can't fully anticipate, where it's not adequate to use [python-setup].interpreter_constraints
to determine what to run setuptools withhelpful-lunch-92084
06/15/2021, 10:17 PMpex_binary(
name = "some_script",
source="some_script.py",
interpreter_constraints=["~3.6"]
)
or
pex_binary(
name="aws",
entry_point="awscli.clidriver:main",
dependencies=["3rdparty/python:awscli"],
interpreter_constraints=["~3.6"],
)
helpful-lunch-92084
06/15/2021, 10:19 PMpython_library(
name = "some_script_lib",
sources=["some_script.py"],
)
pex_binary(
name = "some_script",
entry_point = "some_script.py",
dependencies=[":some_script_lib"],
)
In which case i could set an interpreter_constraint on the python_libraryenough-analyst-54434
06/15/2021, 10:19 PMenough-analyst-54434
06/15/2021, 10:20 PMhundreds-father-404
06/15/2021, 10:23 PMpython_library
targets, so no constraints used
- Last month, Benjy and I realized it was a mistake to remove interpreter_constraints
from pex_binary
and python_awslambda
. We fixed that. I've been pondering past month if we should update python_distribution
to be consistentenough-analyst-54434
06/15/2021, 10:26 PMenough-analyst-54434
06/15/2021, 10:28 PMhelpful-lunch-92084
06/15/2021, 10:28 PMpex_binary(
name="aws",
entry_point="awscli.clidriver:main",
dependencies=["3rdparty/python:awscli"],
interpreter_constraints=["~3.6"],
)
enough-analyst-54434
06/15/2021, 10:28 PMenough-analyst-54434
06/15/2021, 10:28 PMhelpful-lunch-92084
06/15/2021, 10:28 PMhundreds-father-404
06/15/2021, 10:28 PM