gentle-painting-24549
11/29/2022, 5:17 PMconda install gdcm
inside of tox to run our tests. Without having access to Conda an alternative I’ve found is to use python-gdcm
instead which is a Python wrapper for GDCM. I’ve tried to attach this dependency to the tests using a `python_requirement`:
python_requirement(
name="gdcm",
requirements=["python-gdcm"],
)
python_tests(
name="tests",
sources=[
"tests/**/test_*.py",
"tests/test_*.py",
],
dependencies=[
":conftest",
":test-resources",
":gdcm",
],
)
However this doesn’t work and python-gdcm
doesn’t get installed into the underlying testing PEXs unless I add this snippet to one of my test files:
try:
import gdcm # noqa
except ImportError:
pass
How can I have the tests depend on python-gdcm
without the attempted import? Or alternatively, how can I give Pants access to the underlying gdcm binary (for example, one that was installed by brew or conda on the host system)?polite-garden-50641
11/29/2022, 5:21 PMmodule_mapping
that will let pants know that python-gdcm
exposes the gdcm
module.
See: https://www.pantsbuild.org/docs/python-third-party-dependencies#use-modules-and-module_mapping-when-the-module-name-is-not-standardgentle-painting-24549
11/29/2022, 5:22 PMrefined-addition-53644
11/29/2022, 5:25 PMrefined-addition-53644
11/29/2022, 5:25 PMpex_binary(
name="service",
entry_point="awslambdaric",
dependencies=["3rdparty/python:resolve#awslambdaric", ":infra_sources"],
layout="packed",
execution_mode="venv",
)
refined-addition-53644
11/29/2022, 5:26 PMawslambdaric
explictlygentle-painting-24549
11/29/2022, 5:29 PM❯ ./pants dependencies packages/example/tests/test_example.py | grep requirements
requirements:reqs#numpy
requirements:reqs#pytest
requirements:reqs#python-gdcm
And now here’s what happens when I comment it out:
❯ ./pants dependencies packages/example/tests/test_example.py | grep requirements
requirements:reqs#numpy
requirements:reqs#pytest
Everything else is the same on the BUILD file for those two examples:
python_tests(
name="tests",
sources=[
"tests/**/test_*.py",
"tests/test_*.py",
],
dependencies=[
":conftest",
":test-resources",
"requirements:reqs#python-gdcm",
],
)
refined-addition-53644
11/29/2022, 5:33 PM./pants test directory-to-tests:tests
The file’s dependencies are only being shown for the imports you have.refined-addition-53644
11/29/2022, 5:34 PMrefined-addition-53644
11/29/2022, 5:36 PMpython_test
python_test(name="test_example", source="test_example.py", dependencies=["insert_explicit"]
Please verify the correct syntax
Then you can attach python_tests to have explicit dependency on this test target but you can’t use the glob then.gentle-painting-24549
11/29/2022, 5:38 PMtests
target directly. But they succeed when I uncomment the try/except block.refined-addition-53644
11/29/2022, 5:43 PMdependencies --transitive
gentle-painting-24549
11/29/2022, 5:48 PM--transitive
but the behavior is still the same: even though the requirements:reqs#python-gdcm
target is explicitly declared and attached to the tests
target via dependencies - it doesn’t actually get attached as a dependency unless the try/except ImportError block exists.refined-addition-53644
11/29/2022, 5:50 PMgentle-painting-24549
11/29/2022, 5:54 PMpackages/example/BUILD
looks like this:
python_sources(
name="lib",
sources=[
"example/**/*.py",
"example/*.py",
],
)
python_tests(
name="tests",
sources=[
"tests/**/test_*.py",
"tests/test_*.py",
],
dependencies=[
"requirements:reqs#python-gdcm",
],
)
python_distribution(
name="dist",
dependencies=[
":lib",
],
provides=setup_py(
name="example",
version="0.0.0",
),
generate_setup=True,
)
And my BUILD file @ requirements/BUILD
looks like this:
python_requirements(
name="reqs",
source="requirements.txt",
module_mapping={
"python-gdcm": ["gdcm"],
},
)
refined-addition-53644
11/29/2022, 6:19 PMgentle-painting-24549
11/29/2022, 6:37 PMgentle-painting-24549
11/29/2022, 7:09 PM