I'm trying to set default `interpreter_constraint`...
# general
q
I'm trying to set default `interpreter_constraint`s and `resolve`s for different apps in a monorepo, using BUILD files in the root folder for each app. Trying to follow this https://www.pantsbuild.org/docs/targets#field-default-values The BUILD files in each app folder look like this:
Copy code
__defaults__({
    (python_sources, python_tests): {
        "interpreter_constraints": ["3.11.5"],
        "resolve": "weather"
    }    
})
But it's not working. I get:
UnrecognizedResolveNamesError: Unrecognized resolve name from the field 'resolve' in the target...
for a file in a subfolder. Am I doing something wrong here?
b
Could you share your
pants.toml
? Or at least the sections related to python and resolves?
q
Copy code
[GLOBAL]
pants_version = "2.17.0"
backend_packages = [
    "pants.backend.build_files.fmt.black",
    "pants.backend.python",
    "pants.backend.python.lint.black",
    "pants.backend.experimental.python.lint.ruff",
    "pants.backend.experimental.python.typecheck.pyright"
]

[source]
root_patterns = [ "src", "tests" ]

[python]
# Python version can be overridden for a component in the component's BUILD file.
interpreter_constraints = ["3.11.5"]
enable_resolves = true

[python.resolves]
weather = "components/weather/dependencies/requirements.lock"

[pyright]
version="pyright@1.1.326"

[test]
use_coverage = true

[coverage-py]
report = "html"
output_dir = "coverage_report"
global_report = true
'component' == 'app'
b
okay. Nothing leaping out to me there. You might have to debug it by narrowing it down to a minimal example? E.g. hopefully it reproduces with one app/one python file?
q
Okay will do, thanks :)
c
can you share the full error message (with only sensitive parts redacted)?
e
So, it doesn't seem like it would explain the particular error message, but in both cases -
pants.toml
and the
__defaults__
-
interpreter_constraints = ["3.11.5"]
is completely bogus. The constraint must be a specifier string like
"==3.11.5"
, for example. There must be an operator.
Unless Pants has grown some "convenience feature" and translates a thing that looks like a version number into an
==<version number>
for you?
Pex will say something like this if not:
Copy code
$ pex --interpreter-constraint 3.11.5
Could not find a compatible interpreter.

Examined the following interpreters:
1.)                                  /home/jsirois/bin/pex.venv/bin/python3.12 CPython==3.12.0
2.)                      /home/jsirois/.pyenv/versions/pypy2.7-7.3.12/bin/pypy PyPy==2.7.18
3.)                    /home/jsirois/.pyenv/versions/pypy3.5-7.0.0/bin/pypy3.5 PyPy==3.5.3
4.)                 /home/jsirois/.pyenv/versions/pypy3.10-7.3.12/bin/pypy3.10 PyPy==3.10.12
5.)                      /home/jsirois/.pyenv/versions/pypy3.6-7.3.3/bin/pypy3 PyPy==3.6.12
6.)                      /home/jsirois/.pyenv/versions/pypy3.7-7.3.9/bin/pypy3 PyPy==3.7.13
7.)                     /home/jsirois/.pyenv/versions/pypy3.8-7.3.11/bin/pypy3 PyPy==3.8.16
8.)                   /home/jsirois/.pyenv/versions/pypy3.9-7.3.12/bin/pypy3.9 PyPy==3.9.17
9.)                        /home/jsirois/.pyenv/versions/3.11.5/bin/python3.11 CPython==3.11.5
10.)                         /home/jsirois/.pyenv/versions/2.7.18/bin/python2.7 CPython==2.7.18
11.)              /home/jsirois/dev/pantsbuild/jsirois-pex/.tox/.tox/bin/python CPython==3.10.12
12.) /home/jsirois/dev/pantsbuild/jsirois-pex/.tox/py311-integration/bin/python CPython==3.11.0
13.)                     /home/jsirois/.pyenv/versions/3.12.0rc2/bin/python3.12 CPython==3.12.0
14.)                         /home/jsirois/.pyenv/versions/3.5.10/bin/python3.5 CPython==3.5.10
15.)                         /home/jsirois/.pyenv/versions/3.6.15/bin/python3.6 CPython==3.6.15
16.)                         /home/jsirois/.pyenv/versions/3.7.17/bin/python3.7 CPython==3.7.17
17.)                         /home/jsirois/.pyenv/versions/3.8.18/bin/python3.8 CPython==3.8.18
18.)                         /home/jsirois/.pyenv/versions/3.9.18/bin/python3.9 CPython==3.9.18

No interpreter compatible with the requested constraints was found:

  Version matches 3.11.5
Vs:
Copy code
$ pex --interpreter-constraint ==3.11.5
Python 3.11.5 (main, Sep  3 2023, 13:19:33) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>>