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

polite-journalist-87208

12/06/2022, 10:11 PM
does pants run support periods (‘.’) in folders? If i have src/foo/bar.py with a python_source target in src/foo/BUILD, things work of course but if I change foo to ‘foo.d’, i get
ImportError: Error while finding module specification for 'foo.d.bar' (ModuleNotFoundError: No module named 'foo')
full traceback here
Copy code
>> ./pants run src/foo.d/bar.py
14:07:26.83 [INFO] Completed: Building foo.d.pex
Traceback (most recent call last):
  File "/Users/taresh/.pyenv/versions/3.9.10/lib/python3.9/runpy.py", line 130, in _get_module_details
    spec = importlib.util.find_spec(mod_name)
  File "/Users/taresh/.pyenv/versions/3.9.10/lib/python3.9/importlib/util.py", line 94, in find_spec
    parent = __import__(parent_name, fromlist=['__path__'])
ModuleNotFoundError: No module named 'foo'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/taresh/.cache/pants/named_caches/pex_root/venvs/bf64290e98f45ccc125a4d62d33d0395b9387122/47e617753a41ccfadc734a273dae6b19d2268155/pex", line 236, in <module>
    runpy.run_module(module_name, run_name="__main__", alter_sys=True)
  File "/Users/taresh/.pyenv/versions/3.9.10/lib/python3.9/runpy.py", line 206, in run_module
    mod_name, mod_spec, code = _get_module_details(mod_name)
  File "/Users/taresh/.pyenv/versions/3.9.10/lib/python3.9/runpy.py", line 139, in _get_module_details
    raise error(msg.format(mod_name, type(ex).__name__, ex)) from ex
ImportError: Error while finding module specification for 'foo.d.bar' (ModuleNotFoundError: No module named 'foo')
wondering if there is a workaround?
e

enough-analyst-54434

12/06/2022, 10:22 PM
I mean, Python does not support that!:
Copy code
$ mkdir spam.eggs
$ touch spam.eggs/oh_my.py
$ python -c 'from spam.eggs import oh_my'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'spam'
So clearly Pants can't either.
f

flat-zoo-31952

12/06/2022, 10:24 PM
I mean... python doesn't really support that as a module name (it kinda does, in the since that you could override an import hook to support it, but it doesn't work out of the box, and you would need to use
importlib
to get at it since the syntax doesn't support it). You probably want to set up
src/foo.d
as a source root https://www.pantsbuild.org/docs/source-roots
p

polite-journalist-87208

12/06/2022, 10:53 PM
oh i see thanks!
5 Views