Hi all, I’m looking for assistance resolving the b...
# general
h
Hi all, I’m looking for assistance resolving the bug seen in this thread: https://pantsbuild.slack.com/archives/C046T6T9U/p1680615255429049. I have a Pants setup with the pyenv backend installed, but Pants is selecting (and auto-installing) a Python3.7 interpreter to use with
black==23.9.1
. It’s then failing to run the cached Pex for this tool. It shouldn’t be attempting to use 3.7, do I need to update from 2.16 or include more specific resolves? Relevant parts of my
pants.toml
look like this:
Copy code
[GLOBAL]
pants_version = "2.16.0"
backend_packages = [
    "pants.backend.build_files.fmt.black",
    "pants.backend.python.providers.experimental.pyenv"
]

[python]
interpreter_constraints = ["CPython>=3.9.*"]

[python-bootstrap]
search_path = ["/usr/bin", "<PYENV>"]

[black]
version = "black==23.9.1"
It seems to be including a
python_version < 3.10
requirement from somewhere but from where I am unsure. Error output in thread…
Copy code
% pants fix ::
18:20:11.76 [INFO] Completed: Building black.pex with 2 requirements: black==23.9.1, typing-extensions>=3.10.0.0; python_version < "3.10"
18:20:11.76 [ERROR] 1 Exception encountered:

Engine traceback:
  in `fix` goal

ProcessExecutionFailure: Process 'Building black.pex with 2 requirements: black==23.9.1, typing-extensions>=3.10.0.0; python_version < "3.10"' failed with exit code 1.
stdout:

stderr:
pid 99022 -> pip_cache --log /private/var/folders/r4/fkll0nt120xf9zwh29r1r6zm0000gq/T/pants-sandbox-5QELmO/.tmp/pex-pip-log.msq_pzq3/pip.log download --dest /Users/<user>/.cache/pants/named_caches/pex_root/downloads/resolver_download.z8re_2ou/<user>..pyenv.versions.3.7.13.bin.python3.7 black==23.9.1 typing-extensions>=3.10.0.0; python_version < "3.10" --index-url <https://pypi.python.org/simple> --retries 5 --timeout 15 exited with 1 and STDERR:
ERROR: Could not find a version that satisfies the requirement black==23.9.1
ERROR: No matching distribution found for black==23.9.1
c
There were some significant recent changes with how the versions of tools and lockfiles interact. If you can upgrade to 2.18 it might be easier to straighten out there. Here is a diff of
black
and
pyenv
in the example-python repo that I think is along the lines of what you are trying to do
Copy code
git diff requirements.txt pants.toml | cat
diff --git a/pants.toml b/pants.toml
index dfb564f..6ef4a19 100644
--- a/pants.toml
+++ b/pants.toml
@@ -11,6 +11,7 @@ backend_packages.add = [
   "pants.backend.python.lint.flake8",
   "pants.backend.python.lint.isort",
   "pants.backend.python.typecheck.mypy",
+  "pants.backend.python.providers.experimental.pyenv"
 ]
 
 [anonymous-telemetry]
@@ -21,6 +22,7 @@ repo_id = "3B1D361B-E9F1-49A8-B761-03DCC41FD58E"
 # The Python source root is the repo root. See <https://www.pantsbuild.org/docs/source-roots>.
 root_patterns = ["/"]
 
+
 [python]
 # The default interpreter constraints for code in this repo. Individual targets can override
 #  this with the `interpreter_constraints` field. See
@@ -48,3 +50,9 @@ search_path = ["<PATH>", "<PYENV>"]
 [python-infer]
 # 2.17 is transitioning to a new, faster parser for dependency inference:
 use_rust_parser = true
+
+
+[black]
+#install_from_resolve = "pytest"
+requirements =["//:reqs#black"]
+interpreter_constraints = ["==3.9.*"]
\ No newline at end of file
diff --git a/requirements.txt b/requirements.txt
index 979167d..043ea20 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,7 +1,8 @@
 # Copyright 2020 Pants project contributors.
 # Licensed under the Apache License, Version 2.0 (see LICENSE).
 
+black==23.9.1
 ansicolors==1.1.8
 setuptools>=56.2.0,<57
 types-setuptools>=56.2.0,<58
-pytest==7.1.3
\ No newline at end of file
+pytest==7.1.3
h
Copy code
[black]
interpreter_constraints = ["==3.9.*"]
…looks to be the relevant bit, but I’m interested in why it’s being resolved to 3.7 in my users’ setup.
I have the same issue happening in CI but with the
coverage
tool rather than black
c
Copy code
--coverage-py-interpreter-constraints="['<str>', '<str>', ...]"
  PANTS_COVERAGE_PY_INTERPRETER_CONSTRAINTS
  interpreter_constraints
      default: [
          "CPython>=3.7,<4"
      ]
      current value: [
          "CPython>=3.7,<4"
      ]
      Python interpreter constraints for this tool.
This is all with the pyenv backend right?
h
In CI yes, although I have a user with the same issue (selecting 3.7 for
pants fmt ::
) who isn’t using the pyenv backend but does have pyenv installed (w/ 3.10 and 3.11 interpreters installed). I’m assuming it’s installing the minimum interpreter required based on constraints for these tools? But then unsure why it’s failing to run them?
I’ll pin ICs to 3.9 and see how it gets on and report back
❤️ 1
👍 1