bright-book-6256
06/19/2022, 4:56 PMhappy-kitchen-89482
06/20/2022, 8:59 AMhundreds-father-404
06/23/2022, 3:25 PMbright-book-6256
07/05/2022, 4:15 PMrequirements.txt
and requirements_test.txt
, how do I tell Pants to use requirements_test.txt
only for launching tests?happy-kitchen-89482
07/05/2022, 5:04 PMhappy-kitchen-89482
07/05/2022, 5:05 PMrequirements.txt
files represent a "universe" of possible requirements, but Pants picks the subset actually needed in any given scenario, based on dependency inferencehappy-kitchen-89482
07/05/2022, 5:06 PMrequirements.txt
and requirements_test.txt
?hundreds-father-404
07/05/2022, 5:07 PMhappy-kitchen-89482
07/05/2022, 5:07 PMrequirements.txt
for all possible requirements. Again, Pants selects the necessary subset that a test or binary needs. This is different than non-Pants workflows where you have to install an entire requirements file in a venvhappy-kitchen-89482
07/05/2022, 5:07 PMbright-book-6256
07/05/2022, 5:10 PMAre there any overlaps or conflicts betweenno there aren’t.andrequirements.txt
?requirements_test.txt
I understand why you have both for historical reasons and why you might want to have both during a migrationexactly! So I have to put everything in
requirements.txt
but if in the meantime I do something like that:
python_requirements(
name="requirements",
resolve="default",
)
python_requirements(
name="test-requirements",
source="requirements_test.txt",
)
python_tests(
name="tests",
sources=["test/**/test_*.py" ],
dependencies=[":test-requirements"]
)
What do you think about that ?happy-kitchen-89482
07/05/2022, 5:17 PMpython_requirements
targets you have there. But in the future, if you're fully migrated to Pants, that distinction won't be meaningful, so you can unify them.happy-kitchen-89482
07/05/2022, 5:17 PMpython_tests
file you shouldn't need dependencies=[":test-requirements"]
happy-kitchen-89482
07/05/2022, 5:17 PMhappy-kitchen-89482
07/05/2022, 5:18 PMhappy-kitchen-89482
07/05/2022, 5:18 PMdependencies=["#foobar"]
in your examplehappy-kitchen-89482
07/05/2022, 5:19 PMpython_requirements
target generates a foobar
target for the requirement foobar in the requirements file)happy-kitchen-89482
07/05/2022, 5:21 PMdependencies=["path/to:target#foobar"]
- you don't need to have the requirements targets in the same dir as the tests of coursebright-book-6256
07/05/2022, 5:42 PMBUILD
file of every sub-project?
python_requirements(
name="requirements",
resolve="default",
)
python_requirements(
name="test-requirements",
source="requirements_test.txt",
)
happy-kitchen-89482
07/05/2022, 5:51 PMhappy-kitchen-89482
07/05/2022, 5:51 PM3rdparty
directory, or whereverhappy-kitchen-89482
07/05/2022, 5:52 PMbright-book-6256
07/06/2022, 7:55 AMpant.toml
I add pytest-mock
as extra requirements:
[pytest]
extra_requirements = [
"pytest-mock~=3.7",
]
but when I throw the goal test
InvalidLockfileError: You are using the `<default>` lockfile provided by Pants to install the tool `pytest`, but it is not compatible with your configuration:
- You have set different requirements than those used to generate the lockfile. You can fix this by updating `[pytest].version` and/or `[pytest].extra_requirements`, or by using a new custom lockfile.
In the input requirements, but not in the lockfile: ['pytest-mock~=3.7']
In the lockfile, but not in the input requirements: ['pytest-cov!=2.12.1,<3.1,>=2.12']
I can't understand why he has this conflictbright-book-6256
07/06/2022, 8:03 AMIf you change either version or extra_requirements, Pants's default lockfile for Pytest will not work. Either set the lockfile option to a custom path or "<none>" to opt out. See Third-party dependencies.
bright-book-6256
07/06/2022, 9:20 AM@pytest.mark.skip("")
) . if I use pytest it skips it immediately, with pants instead it remains in stuck Building requirements ...
bright-book-6256
07/06/2022, 9:38 AMhundreds-father-404
07/06/2022, 2:35 PM[pytest].extra_requirements
. Only, you should set [pytest].lockfile = "3rdparty/pytest.lock
for example (whatever file path you want), then run ./pants generate-lockfiles --resolve=pytest
hundreds-father-404
07/06/2022, 2:36 PMCan I set debug output as "default" for the test goal ?Like,
./pants test --debug
? Yes. Every option in Pants can be specified on the CLI, env vars, or config file. See https://www.pantsbuild.org/docs/options
Here, you would set in `pants.toml`:
[test]
debug = true
Although, there are some downsides to setting that. You won't get concurrency, and also tests won't be cached. So ./pants test ::
will rerun everything every time - a big reason Pants exissts is for its cachingbright-book-6256
07/07/2022, 7:02 AM$ ./pants generate-lockfiles --resolve=data-creation
09:05:07.70 [INFO] Initializing scheduler...
09:05:08.00 [INFO] Scheduler initialized.
09:08:51.47 [INFO] Completed: Generate lockfile for data-creation
09:08:51.47 [ERROR] 1 Exception encountered:
ProcessExecutionFailure: Process 'Generate lockfile for data-creation' failed with exit code 1.
stdout:
stderr:
ERROR: Could not find a version that satisfies the requirement pantsbuild.pants.testutil<2.14,>=2.13.0a0
ERROR: No matching distribution found for pantsbuild.pants.testutil<2.14,>=2.13.0a0
Do you have any suggestions?
PS.: I have 2 repos set up, the default one and our internal Artifactory.happy-kitchen-89482
07/07/2022, 7:40 AMbright-book-6256
07/07/2022, 7:41 AMbright-book-6256
07/07/2022, 9:23 AMbright-book-6256
07/07/2022, 9:46 AMbright-book-6256
07/07/2022, 10:00 AM⠈ 917.84s Building requirements.pex with 6 requirements: apache-airflow-providers-slack~=3.0.0, apache-airflow[amazon,docker]~=2.0.2, boto3<2.0,>=1.17, pydantic<2.0,>=1.9, pyyaml<6.0.0,>=5.4.1, ruamel.yaml~=0.17
Any suggestions ?
@hundreds-father-404 @happy-kitchen-89482happy-kitchen-89482
07/07/2022, 8:22 PMhappy-kitchen-89482
07/07/2022, 8:22 PMhappy-kitchen-89482
07/07/2022, 8:23 PMbright-book-6256
07/08/2022, 10:44 AMbright-book-6256
07/08/2022, 10:45 AMWhich version of Pants are you on, and are you using a lockfile?Now I'm using
2.13.0a1
bright-book-6256
07/08/2022, 11:11 AMModuleNotFoundError
running the ./pants test
.
My test class has something like that in the head :
...
from my_module.cli.docker.utils import ImageAttrs
...
where my_package is a common folder inside the project that contains the sources.
E ModuleNotFoundError: No module named 'my_module.cli'
What am I doing wrong? 🤯
PS: Running pytest
I don’t have any error
BUILD file:
python_sources(name="lib", sources=["my_module/**/*.py"])
python_tests(
name="tests",
sources=["tests/**/test_*.py"]
)
python_distribution(
name="dist",
dependencies=[":lib"],
provides=python_artifact(
name="my-app",
description="My Application.",
long_description_file="README.md"
),
generate_setup = True,
wheel_config_settings={"--global-option": ["--python-tag", "py37.py38.py39"]},
)
My dir structure:
├── BUILD
├── my_module
│ └── cli
│ └── docker
│ ├── __init__.py
│ └── main.py
└── tests
└── unit_tests
└── test_main.py
bright-book-6256
07/11/2022, 6:55 AMhappy-kitchen-89482
07/11/2022, 6:58 AMhappy-kitchen-89482
07/11/2022, 6:58 AMbright-book-6256
07/11/2022, 7:14 AMbright-book-6256
07/11/2022, 9:59 AM./pants generate-lockfiles --resolve=project-b
I would also like to introduce the creation of the _version.py file within each distribution.
Can you help me ?bright-book-6256
07/11/2022, 3:11 PM./pants generate-lockfiles --resolve=default
I have problembright-book-6256
07/11/2022, 5:20 PMpantsbuild-pants 2.13.0a0 depends on PyYAML<7.0 and >=6.0
for this reason, I have an error during the generation of lockfile. Because my project has this requirement:
awscli 1.25.26 depends on PyYAML<5.5 and >=3.10
😕 I didn't think the pants plugin would affect my build in terms of dependencies...
furthermore, the error message should be more complete at the end of the generate-lockfile goalhappy-kitchen-89482
07/11/2022, 7:36 PMhappy-kitchen-89482
07/11/2022, 7:36 PMbright-book-6256
07/12/2022, 7:52 AMpip install
works.
Requirements file:
click==8.0.4
pydantic==1.9.0
pyyaml==5.3.1
requests==2.26.0
sparkmeasure==0.14.0
pyspark==3.1.2
arcgis==1.9.1
fiona==1.8.21
geopandas==0.10.2
h3==3.7.4
numpy==1.21.6
pandas==1.1.5
pyproj==3.2.1
shapely==1.8.0
google-api-python-client==2.49.0
gspread==5.1.1
oauth2client==4.1.3
datadog==0.42.0
docker==5.0.3
luigi==3.0.3
mysql-connector-python==8.0.29
python-json-logger==2.0.2
python-logstash==0.4.6
slackclient==2.9.4
wcmatch==8.1.2
google.api_core==2.8.2
The goal end with:
09:19:25.79 [ERROR] 1 Exception encountered:
ProcessExecutionFailure: Process 'Generate lockfile for data-ingestion' failed with exit code 1.
stdout:
stderr:
ERROR: Could not find a version that satisfies the requirement numpy==1.21.6
ERROR: No matching distribution found for numpy==1.21.6
happy-kitchen-89482
07/13/2022, 4:05 AMhappy-kitchen-89482
07/13/2022, 4:06 AMhappy-kitchen-89482
07/13/2022, 4:06 AMbright-book-6256
07/13/2022, 6:18 AM./pants generate-lockfiles --resolve=project-b
About the lockfile configuration I had enabled the resolves and I'm using it. You can find more details on the configuration in my example repo:
https://github.com/devcrops-official/pants-project-example/blob/main/3rdparty/python/project-b/requirements.txtbright-book-6256
07/15/2022, 6:15 AMhappy-kitchen-89482
07/16/2022, 8:54 PMhappy-kitchen-89482
07/16/2022, 8:55 PMbright-book-6256
07/20/2022, 12:45 PM./pants generate-lockfiles --resolve=project-b
bright-book-6256
07/20/2022, 1:26 PMhappy-kitchen-89482
07/24/2022, 5:15 PMhappy-kitchen-89482
07/24/2022, 5:20 PMhappy-kitchen-89482
07/24/2022, 5:40 PMCPython>=3.7,<3.11
happy-kitchen-89482
07/24/2022, 5:41 PMhappy-kitchen-89482
07/24/2022, 5:43 PMbright-book-6256
07/25/2022, 8:05 AMFile "/Users/myhome/.cache/pants/named_caches/pex_root/installed_wheels/6242b902db69f59e1092b406655c0fb1634486c47ce563f5fd27277cf4561822/pex-2.1.90-py2.py3-none-any.whl/pex/pep_376.py", line 446, in from_prefix_install
raise RecordNotFoundError(pex.pep_376.RecordNotFoundError: Could not find the installation RECORD for python-certifi-win32 1.6.1 under /Users/myhome/.cache/pants/named_caches/pex_root/installed_wheels/508fd4fb1730cad2d9dada061df737650c8cfaa205d64657faa4cc6a55384402/python_certifi_win32-1.6.1-py2.py3-none-any.whl.d7cadc0956bf44ceb0ed26ade60f6281
Any idea?bright-book-6256
07/25/2022, 8:45 AMProcessExecutionFailure: Process 'Building 15 requirements for requirements.pex from the 3rdparty/python/data-ingestion/dependencies_lock.txt resolve: arcgis==1.9.1, click==8.0.4, geopandas==0.10.2, google.api_core==2.8.2, gspread==5.1.1, h3==3.7.4, oauth2client==4.1.3, pandas==1.1.5, pydantic==1.9.0, pyproj==3.2.1, pyspark==3.1.2, pyyaml==5.3.1, requests==2.26.0, shapely==1.8.0, sparkmeasure==0.14.0' failed with exit code 1.
Could be something between these reqs that bothers it?bright-book-6256
07/25/2022, 8:54 AMbright-book-6256
07/25/2022, 1:52 PMhappy-kitchen-89482
07/25/2022, 3:44 PMplatform_system == "Windows"
environment marker.bright-book-6256
07/25/2022, 3:47 PMhappy-kitchen-89482
07/25/2022, 3:49 PMhappy-kitchen-89482
07/25/2022, 3:51 PMhappy-kitchen-89482
07/25/2022, 3:51 PMpython -m pex.cli lock create $'--style=universal' --resolver-version pip-2020-resolver --interpreter-constraint $'CPython>=3.8,<3.9' $'python-certifi-win32'
happy-kitchen-89482
07/25/2022, 3:51 PMhappy-kitchen-89482
07/25/2022, 3:52 PM/Users/myhome/.cache/pants/named_caches/pex_root/installed_wheels/508fd4fb1730cad2d9dada061df737650c8cfaa205d64657faa4cc6a55384402/python_certifi_win32-1.6.1-py2.py3-none-any.whl.d7cadc0956bf44ceb0ed26ade60f6281
on your system?bright-book-6256
07/25/2022, 3:56 PMlib
and insideenough-analyst-54434
07/25/2022, 3:56 PMbright-book-6256
07/25/2022, 3:56 PMsite-packages
enough-analyst-54434
07/25/2022, 3:57 PMbright-book-6256
07/25/2022, 3:57 PMenough-analyst-54434
07/25/2022, 4:02 PM$ pex python-certifi-win32==1.6.1
Traceback (most recent call last):
File "/home/jsirois/.venv/pex/bin/pex", line 8, in <module>
sys.exit(main())
^^^^^^
File "/home/jsirois/.venv/pex/lib/python3.11/site-packages/pex/bin/pex.py", line 775, in main
catch(
^^^^^^
File "/home/jsirois/.venv/pex/lib/python3.11/site-packages/pex/result.py", line 103, in catch
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/home/jsirois/.venv/pex/lib/python3.11/site-packages/pex/bin/pex.py", line 798, in do_main
pex_builder = build_pex(
^^^^^^^^^^
File "/home/jsirois/.venv/pex/lib/python3.11/site-packages/pex/bin/pex.py", line 681, in build_pex
result = resolve(
^^^^^^^^
File "/home/jsirois/.venv/pex/lib/python3.11/site-packages/pex/resolver.py", line 948, in resolve
build_and_install_request.install_distributions(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jsirois/.venv/pex/lib/python3.11/site-packages/pex/resolver.py", line 714, in install_distributions
for install_result in execute_parallel(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jsirois/.venv/pex/lib/python3.11/site-packages/pex/jobs.py", line 541, in execute_parallel
yield spawn_result.spawned_job.await_result()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jsirois/.venv/pex/lib/python3.11/site-packages/pex/jobs.py", line 220, in await_result
job.wait()
^^^^^^^^^^
File "/home/jsirois/.venv/pex/lib/python3.11/site-packages/pex/jobs.py", line 81, in wait
self._finalize_job()
^^^^^^^^^^^^^^^^^^^^
File "/home/jsirois/.venv/pex/lib/python3.11/site-packages/pex/jobs.py", line 139, in _finalize_job
self._finalizer(self._process.returncode)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jsirois/.venv/pex/lib/python3.11/site-packages/pex/pip/tool.py", line 711, in fixup_install
record = Record.from_prefix_install(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jsirois/.venv/pex/lib/python3.11/site-packages/pex/pep_376.py", line 445, in from_prefix_install
raise RecordNotFoundError(
^^^^^^^^^^^^^^^^^^^^^^^^^^
pex.pep_376.RecordNotFoundError: Could not find the installation RECORD for python-certifi-win32 1.6.1 under /home/jsirois/.pex/installed_wheels/508fd4fb1730cad2d9dada061df737650c8cfaa205d64657faa4cc6a55384402/python_certifi_win32-1.6.1-py2.py3-none-any.whl.353db331daf74436a74d93cf324aa9a9
I'm looking at this over here: https://github.com/pantsbuild/pex/issues/1861bright-book-6256
07/25/2022, 4:04 PMenough-analyst-54434
07/25/2022, 4:24 PM$ pip install --prefix chroot --no-deps python_certifi_win32-1.6.1-py2.py3-none-any.whl
$ tree -L 4 chroot/
chroot/
└── lib
├── python3.10
│ └── site-packages
│ ├── certifi_win32
│ └── python_certifi_win32-1.6.1.dist-info
└── site-packages
└── python-certifi-win32-init.pth
6 directories, 1 file
It's trying to install a .pth
file and misses. Those must belong to the site-packages
directory of a venv which is chroot/lib/python3.10/site-packages
in this case and not chroot/lib/site-packages
. The issue is in how they package the .pth
file:
$ zipinfo -1 python_certifi_win32-1.6.1-py2.py3-none-any.whl
certifi_win32/__init__.py
certifi_win32/bootstrap.py
certifi_win32/wincerts.py
certifi_win32/wrapt_certifi.py
certifi_win32/wrapt_pip.py
python_certifi_win32-1.6.1.data/data/lib/site-packages/python-certifi-win32-init.pth
python_certifi_win32-1.6.1.dist-info/LICENSE
python_certifi_win32-1.6.1.dist-info/METADATA
python_certifi_win32-1.6.1.dist-info/WHEEL
python_certifi_win32-1.6.1.dist-info/top_level.txt
python_certifi_win32-1.6.1.dist-info/RECORD
Instead of storing it as python-certifi-win32-init.pth
at the top-level, they attempt to use the data files mechanism.
All that said, this should not trip Pex up. I'll get up a fix and Pex release today. Once done I can give you some pants.toml
edits here to get you using the fixed Pex.enough-analyst-54434
07/25/2022, 8:38 PM[pex-cli]
version = "v2.1.101"
known_versions = [
"v2.1.101|macos_arm64|d1e29e060b79307719be2a40d16234d1cadd5fc1abab039e091ce3cba8a47cd9|3813284",
"v2.1.101|macos_x86_64|d1e29e060b79307719be2a40d16234d1cadd5fc1abab039e091ce3cba8a47cd9|3813284",
"v2.1.101|linux_arm64|d1e29e060b79307719be2a40d16234d1cadd5fc1abab039e091ce3cba8a47cd9|3813284",
"v2.1.101|linux_x86_64|d1e29e060b79307719be2a40d16234d1cadd5fc1abab039e091ce3cba8a47cd9|3813284",
]
# When trying a new pex version, you can find out the hash and size-in-bytes as follows:
# $ curl -s -L <https://github.com/pantsbuild/pex/releases/download/v2.1.101/pex> | tee >(wc -c) >(shasum -a 256) >/dev/null
Alternatively, Pants 2.14.x and 2.13.x are being patched and the next releases of those will have this fix.bright-book-6256
07/26/2022, 7:09 AMbright-book-6256
08/01/2022, 7:40 AMbright-book-6256
08/02/2022, 7:30 AMbright-book-6256
08/02/2022, 8:10 AMpants test
some test fails to download java 3rdparty dependencies (not always the same test and not always the same deps) but if I run pants test --debug
it works, probably because it is sequential. It seems like I have some bandwidth limit on GitHub (locally works without trouble). Is there a way to configure pants to avoid extreme parallelism?