https://pantsbuild.org/ logo
#general
Title
# general
a

able-shampoo-44547

07/08/2022, 12:56 PM
I'm trying to figure out an import error, I'm having problems importing a module during a test.
Copy code
tests/test_hyperspec.py F                                                [100%]

=================================== FAILURES ===================================
_________________________________ test_import __________________________________

    def test_import():
>       import sphinxcontrib.hyperspec
E       ModuleNotFoundError: No module named 'sphinxcontrib.hyperspec'

tests/test_hyperspec.py:19: ModuleNotFoundError
- generated xml file: /tmp/process-execution1Z9sbF/tests.test_hyperspec.py.tests0.xml -
=========================== short test summary info ============================
FAILED tests/test_hyperspec.py::test_import - ModuleNotFoundError: No module ...
============================== 1 failed in 0.08s ===============================
I can see the files there, but i can't seem to actually import the module
Copy code
$ find sphinxcontrib tests 
sphinxcontrib
sphinxcontrib/cldomain.lisp
sphinxcontrib/cldomain.py
sphinxcontrib/test.lisp
sphinxcontrib/__init__.py
sphinxcontrib/package.lisp
sphinxcontrib/hyperspec.py
sphinxcontrib/version.lisp-expr
tests
tests/test_cldomain.py
tests/__init__.py
tests/__pycache__
tests/__pycache__/__init__.cpython-38.pyc
tests/__pycache__/test_cldomain.cpython-38-pytest-7.1.2.pyc
I went into the directory directly and tested with a local python and with the sandbox python, but the cached one can't import stuff? I commented out the contents of the files completely, to make sure it wasn't an issue with loading them
Copy code
$ cd /tmp/.tmpDGxM5D 
$ python
Python 3.8.5 (default, Aug 13 2020, 15:51:26) 
[GCC 10.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sphinxcontrib
>>> import sphinxcontrib.cldomain
>>> 
 
$ /home/russell/.cache/pants/named_caches/pex_root/venvs/s/a67a3153/venv/bin/python3.8
Python 3.8.5 (default, Aug 13 2020, 15:51:26) 
[GCC 10.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sphinxcontrib
>>> import sphinxcontrib.cldomain
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'sphinxcontrib.cldomain'
>>>
any idea what could be going on? i'm on pants 2.12.0
1
n

narrow-vegetable-37489

07/08/2022, 1:00 PM
Does it show up if you run
./pants dependencies tests/test_hyperspec.py
?
a

able-shampoo-44547

07/08/2022, 1:02 PM
yeah i get
Copy code
$ ./pants dependencies tests/test_hyperspec.py
15:02:26.55 [INFO] Initializing scheduler...
15:02:26.75 [INFO] Scheduler initialized.
//:sphinxcontrib-cldomain
sphinxcontrib/__init__.py:lib
sphinxcontrib/cldomain.py:lib
sphinxcontrib/hyperspec.py:lib
omg, i just got it to work
i added them because i was having problems with dependencise not being detected from the python package i'm trying to tset
that is some weird behavior. i wonder if the setuptools version had something to do with it
c

curved-television-6568

07/08/2022, 1:08 PM
I’m not sure, but I think it could be due to that you had put more than one distribution in the requirements field. The
python_requirement
target is meant for a single dist per target only. https://www.pantsbuild.org/docs/reference-python_requirement#coderequirementscode
It’s a list to support selecting different versions based on various env markers etc, I think.
a

able-shampoo-44547

07/08/2022, 1:17 PM
ah ok, good to know
c

curved-television-6568

07/08/2022, 1:18 PM
python_requirements
are usually used to source a
requirements.txt
file into corresponding
python_requirement
targets, which is preferable if you have more than a few 3rdparty dependencies.
e

enough-analyst-54434

07/08/2022, 2:23 PM
Isn't this all just down to the name of the
python_requirement
being the name used for dep inference? IOW you could also correct by adding module mappings for all requirements. Not that you'd want to do this, just to avoid misunderstanding what was going on there (the assumption being
sphinxcontrib
was using
pkg_resources
to effect a namespace package).
a

able-shampoo-44547

07/08/2022, 2:50 PM
if i'm using
python_requirements
to declare my library dependencies, do i also need to declare them in the
setup.cfg
? or does it propagate through?
something is up with
sphinx
if it's in the requires in any way, it breaks importing. i have restructured my library and that seems to have helped
3 Views