Should setuptools always be present? Because it do...
# general
p
Should setuptools always be present? Because it doesn't seem to be. I'm getting some import errors for
pkg_resources
which is in
setuptools
a dep,
flex
does not declare a dep on
setuptools
(they think its std lib): https://github.com/pipermerriam/flex/blob/master/flex/__init__.py#L6 What are my options for getting pants to include setuptools in this case?
Copy code
✘  ~/p/st2sandbox/st2.git   pants ●  ./pants test st2common/tests/unit/test_logging_middleware.py                                                                                                                                                                      1
03:18:02.08 [WARN] Completed: test - st2common/tests/unit/test_logging_middleware.py:tests failed (exit code 2).
============================= test session starts ==============================
platform linux -- Python 3.6.13, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
benchmark: 3.4.1 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
rootdir: /tmp/process-execution6KNsrk
plugins: cov-2.11.1, icdiff-0.5, benchmark-3.4.1
collected 0 items / 1 error

==================================== ERRORS ====================================
_______ ERROR collecting st2common/tests/unit/test_logging_middleware.py _______
ImportError while importing test module '/tmp/process-execution6KNsrk/st2common/tests/unit/test_logging_middleware.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib64/python3.6/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
st2common/tests/unit/test_logging_middleware.py:21: in <module>
    from st2common.middleware.logging import LoggingMiddleware
st2common/st2common/middleware/logging.py:30: in <module>
    from st2common.router import Request, NotFoundException
st2common/st2common/router.py:25: in <module>
    from flex.core import validate
/home/cognifloyd/.cache/pants/named_caches/pex_root/venvs/short/b40361f1/lib64/python3.6/site-packages/flex/__init__.py:6: in <module>
    import pkg_resources
E   ModuleNotFoundError: No module named 'pkg_resources'
=========================== short test summary info ============================
ERROR st2common/tests/unit/test_logging_middleware.py
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
=============================== 1 error in 0.32s ===============================



𐄂 st2common/tests/unit/test_logging_middleware.py:tests failed.
So, do I have to add setuptools to
python_library(dependencies = ...)
even though it is a transitive dep?
h
Create an inlined python_requirement_library, rather than putting it in requirements.txt. Add to its dependencies field the path to setuptools target, eg 3rdparty/python:setuptools https://www.pantsbuild.org/v2.5/docs/python-third-party-dependencies#inline-requirements
rather than putting it in requirements.txt
It's necessary to remove from requirements.txt so that you don't have two targets referring to the same requirement, which would disable dependency inference for flex because it would be ambiguous which you want to use The generate_constraints.sh script will still do the right thing
p
Ah. Ok. I'll probably leave a comment in the requirements file. Is it better to put that flex python_requirement_library in the top level BUILD or in the file next to where it is used?
h
I'd probably say the BUILD where your requirements.txt is that. That way it's more discoverable if other modules start using it in the future