https://pantsbuild.org/ logo
a

ambitious-actor-36781

06/24/2021, 12:39 AM
I could have sworn I saw somewhere in the docs there's a way to use a
python_distribution
instead of a
python_library
in tests. ... I have a library that I'm trying to bring into the fold that makes heavy use of setuptools entrypoints and ... stuff. Which doesn't seem to play nice at all with pants.
e

enough-analyst-54434

06/24/2021, 12:46 AM
I think you read this: https://www.pantsbuild.org/docs/python-test-goal#testing-your-packaging-pipeline If that doesn't get you down the road, speak up.
a

ambitious-actor-36781

06/24/2021, 12:48 AM
ah cheers
still might not work when things it depends on are brought into the fold. But should be enough to test and ship a backwards-compatible version
Not sure this is working right? Here's the dependencies of the distributable:
Copy code
$  pants dependencies //src/python/sportr_app:sportr_app_dist
src/python/sportr_app/__init__.py
src/python/sportr_app/app.py
src/python/sportr_app/initialization.py
src/python/sportr_app/main.py
src/python/sportr_app/plugins/__init__.py:../sportr_app
src/python/sportr_app/plugins/console_commands.py:../sportr_app
src/python/sportr_app/system_plugins/__init__.py:../sportr_app
src/python/sportr_app/system_plugins/app_loader.py:../sportr_app
src/python/sportr_app/system_plugins/logging/__init__.py:../../sportr_app
src/python/sportr_app/system_plugins/logging/logging.py:../../sportr_app
src/python/sportr_app/system_plugins/logging/logging_formatter.py:../../sportr_app
src/python/sportr_app/system_plugins/logging/loglimiter.py:../../sportr_app
src/python/sportr_app/system_plugins/logging/source_monitoring_logging.py:../../sportr_app
src/python/sportr_app/system_plugins/plugin_loader.py:../sportr_app
src/python/sportr_app/system_plugins/settings.py:../sportr_app
src/python/sportr_app/utils.py
Yet, when the test runs, it errors with import problems
Copy code
from .logging import init_system, setting_mergers, DEFAULT_SETTINGS, PRIORITY
E   ModuleNotFoundError: No module named 'sportr_app.system_plugins.logging.logging'
If we find out which files it's looking at:
Copy code
-> raise self.CollectError(
(Pdb) import sportr_app
(Pdb) pp sportr_app
<module 'sportr_app' from '/tmp/.tmpOY2Dm4/src/python/sportr_app/__init__.py'>
We've only got a small subset of the files?
Copy code
╰─➤  find /tmp/.tmpOY2Dm4/src/python/sportr_app/ -name "*.py"                                                                                                                                                                              1 ↵
/tmp/.tmpOY2Dm4/src/python/sportr_app/__init__.py
/tmp/.tmpOY2Dm4/src/python/sportr_app/initialization.py
/tmp/.tmpOY2Dm4/src/python/sportr_app/system_plugins/logging/__init__.py
/tmp/.tmpOY2Dm4/src/python/sportr_app/system_plugins/logging/logging_formatter.py
/tmp/.tmpOY2Dm4/src/python/sportr_app/system_plugins/__init__.py
/tmp/.tmpOY2Dm4/src/python/sportr_app/utils.py
/tmp/.tmpOY2Dm4/src/python/sportr_app/app.py
and our BUILD file
Copy code
python_tests(
    name="tests",
    dependencies=[
    ],
    runtime_package_dependencies=[
        "//src/python/sportr_app:sportr_app_dist",
        "./sportr_app_test_package",
    ]
)
h

hundreds-father-404

06/24/2021, 3:50 AM
What do you mean things it depends on?
a

ambitious-actor-36781

06/24/2021, 4:04 AM
So it looks like pants is building the wheel for
sportr_app
fine. It's picking up the right files, it's putting them all in the wheel, and if you install that wheel in a virtualenv it does the importing fine. But when I use
runtime_package_dependencies
in it's tests it doesn't look like all the files from the wheel make it into the test environment
in terms of
still might not work when things it depends on are brought into the fold.
The other things that I'm going to bring into the pants repo depend on this, and make use of the overcomplicated setuptools hooks. But I'll probably just do workarounds for that
Ohhhh. So
runtime_package_dependencies
doesn't actually /install/ the output of
pants package
it just sticks the output in the test-target path. Duh, no wonder it's not working like I expect
p

proud-dentist-22844

06/24/2021, 3:59 PM
I'm not sure how your entrypoints get used, but if they're similar to stevedore extension points (which use setuptools entry points), I wrote a pants plugin to help with that: https://github.com/st2sandbox/st2/tree/pants/pants-plugins/stevedore_extensions Then I make a list of the entry points like in these BUILD files: https://github.com/st2sandbox/st2/blob/pants/contrib/runners/orquesta_runner/BUILD https://github.com/st2sandbox/st2/blob/pants/st2common/BUILD So far, I've only added the ability to depend on those entry points (stevedore_namespaces) in `python_tests`: https://github.com/st2sandbox/st2/blob/pants/st2common/tests/unit/BUILD https://github.com/st2sandbox/st2/blob/pants/st2common/tests/unit/services/BUILD https://github.com/st2sandbox/st2/blob/pants/st2common/tests/integration/BUILD
👌 2