dazzling-elephant-33766
09/26/2024, 1:33 PMinstall_from_resolves
with pytest
Following https://www.pantsbuild.org/stable/docs/python/overview/lockfiles#manually-generating-lockfiles
I’ve added the following to my pants.toml
[python]
interpreter_constraints = ['==3.12.*']
enable_resolves = true
resolves_generate_lockfiles = false
run_against_entire_lockfile = true
[python.resolves]
python-default = "requirements.txt"
[pytest]
install_from_resolve = "python-default"
requirements = [
"//:reqs0#pytest-mock",
]
Now running pants test ::
throws an exception
➜ pants-test pants test ::
14:30:05.52 [ERROR] 1 Exception encountered:
Engine traceback:
in `test` goal
AssertionError:
If install_from_resolve
isn’t specified things work as before but I’m forced to use pytest 7.0.1
instead of the one specified in my generated lockfile (not what I want).
I’ve attached the debug logs below:elegant-florist-94385
09/26/2024, 1:37 PMpytest
itself to the pytest.requirements
in your pants.toml.
[pytest]
install_from_Resolve = "python-default"
requirements = [
"//:reqs0#pytest",
"//:reqs0#pytest-mock",
]
dazzling-elephant-33766
09/26/2024, 1:37 PMdazzling-pizza-75442
09/26/2024, 1:40 PMpython-default = "requirements.txt"
- this should be pointing to a lock file, not to the requirements.txt file.elegant-florist-94385
09/26/2024, 1:40 PMpython-default = "requirements.txt"
Just guessing, but it be that there's some confusion where pants is trying to interpret your requirements.txt file as alock filedazzling-elephant-33766
09/26/2024, 1:41 PMrequirements.txt
-style format (ideally with --hash
entries for better supply chain security). For example:
My requirements.txt
has entries like:
aenum==3.1.15 ; sys_platform == 'darwin' or sys_platform == 'linux' \
--hash=sha256:8cbd76cd18c4f870ff39b24284d3ea028fbe8731a58df3aa581e434c575b9559 \
--hash=sha256:e0dfaeea4c2bd362144b87377e2c61d91958c5ed0b4daf89cb6f45ae23af6288
Which is what they have in the docs So I believe I’m doing the right thing here…elegant-florist-94385
09/26/2024, 1:43 PMdazzling-elephant-33766
09/26/2024, 1:44 PMpants generate-lockfiles ::
dazzling-pizza-75442
09/26/2024, 1:44 PMpytest
and pytest-mock
in the output if you do pants list //:reqs0
?dazzling-elephant-33766
09/26/2024, 1:46 PM➜ pants-test pants dependencies //:reqs0 | grep pytest
//:reqs0#pytest
//:reqs0#pytest-cov
//:reqs0#pytest-freezer
//:reqs0#pytest-mock
//:reqs0#pytest-postgresql
the list command just returns itself
➜ pants-test pants list //:reqs0
//:reqs0
elegant-florist-94385
09/26/2024, 1:47 PMdazzling-elephant-33766
09/26/2024, 1:47 PMpython_sources(
name="root",
)
python_requirements(
name="reqs0",
)
python_tests(
name="tests0",
)
dazzling-pizza-75442
09/26/2024, 1:48 PMdefault_resolve = "python-default"
under [python]
in pants.tomldazzling-pizza-75442
09/26/2024, 1:49 PMdazzling-elephant-33766
09/26/2024, 1:50 PMelegant-florist-94385
09/26/2024, 1:53 PMrequirements.txt
file to just a list of package names.
aenum
aiofiles
etc.
If that works, it would suggest the issue is with the file format/parsing.dazzling-pizza-75442
09/26/2024, 1:55 PMdazzling-elephant-33766
09/26/2024, 1:56 PMuv venv
uv pip install -r requirements.txt
uv pip list | awk '{print $1}' > requirements.txt
So now it’s just a list of
aenum
aiofiles
aiohappyeyeballs
aiohttp
And I still get the same
➜ pants-test git:(main) ✗ pants test ::
14:56:00.57 [ERROR] 1 Exception encountered:
Engine traceback:
in `test` goal
AssertionError:
So not a parsing issuedazzling-pizza-75442
09/26/2024, 1:56 PM--keep-sandboxes=on_failure
and see what's in there? Or --test-output=all
to see if you can get more detailsdazzling-elephant-33766
09/26/2024, 1:59 PMpants --no-pantsd -ldebug --keep-sandboxes=on_failure test --test-output=all ::
14:59:03.97 [DEBUG] Lockfile for resolve python-default at requirements.txt has no metadata block, so was not generated by Pants. Lockfile will not be validated.
14:59:04.97 [DEBUG] Completed: Find interpreter for constraints: CPython==3.12.*
14:59:04.97 [DEBUG] Completed: Scheduling: Find interpreter for constraints: CPython==3.12.*
14:59:04.97 [DEBUG] Completed: Find Python interpreter for constraints - CPython==3.12.* - Selected /opt/homebrew/Cellar/python@3.12/3.12.5/Frameworks/Python.framework/Versions/3.12/bin/python3.12 to run PEXes with.
14:59:04.98 [DEBUG] Completed: Resolve transitive targets
14:59:04.98 [DEBUG] Completed: Scheduling: Installing requirements.txt for the resolve `python-default`
14:59:04.99 [DEBUG] Completed: pants.backend.python.util_rules.pex.build_pex
14:59:05.03 [DEBUG] Completed: pants.backend.python.util_rules.python_sources.strip_python_sources
14:59:05.07 [DEBUG] Completed: pants.backend.python.util_rules.pex_from_targets.create_pex_from_targets
14:59:05.09 [DEBUG] Lockfile for resolve python-default at requirements.txt has no metadata block, so was not generated by Pants. Lockfile will not be validated.
14:59:05.09 [DEBUG] Completed: pants.backend.python.util_rules.pex.build_pex
14:59:05.09 [DEBUG] Completed: pants.backend.python.goals.pytest_runner.setup_pytest_for_target
14:59:05.09 [DEBUG] Canceled: pants.backend.python.util_rules.pex.build_pex
14:59:05.09 [DEBUG] Completed: Run Pytest - //test_thing.py:tests0
14:59:05.09 [DEBUG] Completed: `test` goal
14:59:05.09 [DEBUG] computed 1 nodes in 1.400057 seconds. there are 596 total nodes.
14:59:05.09 [ERROR] 1 Exception encountered:
Engine traceback:
in `test` goal
AssertionError:
elegant-florist-94385
09/26/2024, 1:59 PM--keep-sandboxes=always
dazzling-elephant-33766
09/26/2024, 2:07 PMpytest
inside __run.sh
and succeeds when run
15:06:17.03 [INFO] Preserving local process execution dir /private/var/folders/yn/4q7r_wwd16v279lryh84bgtc0000gq/T/pants-sandbox-wlNlZn for Find interpreter for constraints: CPython==3.12.*
15:06:17.03 [DEBUG] /Users/jack/.cache/pants/lmdb_store/immutable/files -> /private/var/folders/yn/4q7r_wwd16v279lryh84bgtc0000gq/T hardlinkable: true
15:06:17.03 [DEBUG] Completed: setup_sandbox
➜ pants-test git:(main) bat /private/var/folders/yn/4q7r_wwd16v279lryh84bgtc0000gq/T/pants-sandbox-wlNlZn/__run.sh
#!/usr/bin/env bash
# This command line should execute the same process as pants did internally.
cd /private/var/folders/yn/4q7r_wwd16v279lryh84bgtc0000gq/T/pants-sandbox-wlNlZn
env -i CPPFLAGS= LANG=en_GB.UTF-8 LDFLAGS= PATH=$'/Users/jack/.rye/shims:/Users/jack/pnpm:/Users/jack/n/bin:/Users/jack/google-cloud-sdk/bin:/opt/homebrew/bin:/Users/jack/nvim-macos-arm64/bin:/Users/jack/.cargo/bin:/Users/jack/bin:/Users/jack/.bun/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/Applications/iTerm.app/Contents/Resources/utilities:/Users/jack/.local/bin' PEX_IGNORE_RCFILES=true PEX_PYTHON=/Users/jack/Library/Caches/nce/6faa4322d1df41d032e4938795c6f2c262ab92bb642a9bac1101cb7d1631f9c1/bindings/venvs/2.22.0/bin/python3.9 PEX_ROOT=.cache/pex_root /Users/jack/Library/Caches/nce/6faa4322d1df41d032e4938795c6f2c262ab92bb642a9bac1101cb7d1631f9c1/bindings/venvs/2.22.0/bin/python3.9 ./pex --tmpdir .tmp --no-emit-warnings --pip-version 24.0 --python-path $'/Users/jack/.pyenv/versions/3.11.9/bin:/Users/jack/.pyenv/versions/3.12.2/bin:/Users/jack/.rye/shims:/Users/jack/pnpm:/Users/jack/n/bin:/Users/jack/google-cloud-sdk/bin:/opt/homebrew/bin:/Users/jack/nvim-macos-arm64/bin:/Users/jack/.cargo/bin:/Users/jack/bin:/Users/jack/.bun/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/Applications/iTerm.app/Contents/Resources/utilities:/Users/jack/.local/bin' --interpreter-constraint $'CPython==3.12.*' -- -c $'import hashlib, os, sys\n\npython = os.path.realpath(sys.executable)\nprint(python)\n\nhasher = hashlib.sha256()\nwith open(python, "rb") as fp:\n for chunk in iter(lambda: fp.read(8192), b""):\n hasher.update(chunk)\nprint(hasher.hexdigest())\n'
dazzling-pizza-75442
09/26/2024, 2:12 PMPreserving local process execution dir... for Run Pytest for ...
- that's the dir to look atdazzling-elephant-33766
09/26/2024, 2:19 PM15:18:18.83 [INFO] Preserving local process execution dir /private/var/folders/yn/4q7r_wwd16v279lryh84bgtc0000gq/T/pants-sandbox-oPTa2w for Find interpreter for constraints: CPython==3.12.*
There isn’t one for pytest
I’m still running:
pants --no-pantsd -ldebug --keep-sandboxes=always test --test-output=all ::
dazzling-pizza-75442
09/26/2024, 2:55 PMCompleted:
in the debug output you pasted