purple-plastic-57801
07/14/2023, 7:55 PM/openapi
./BUILD
./observatory.yml
/teletom/tom/server
./BUILD
... python
I have these source roots in my toml
[source]
root_patterns = [
"openapi",
"teletom"
]
In openapi I set the yml as a resource then set it as a dependency to the teletom/tom/server python source. When I try to load the resource with
importlib.resources.path("openapi", "observatory.yml")
I am seeing..
ModuleNotFoundError: No module named 'openapi'
Does the src root need to be like openapi/src/openapi?fast-nail-55400
07/14/2023, 8:56 PMpants
invocation?purple-plastic-57801
07/14/2023, 9:16 PMpants run teletom/tom/entry:binaries#server.py
13:22:37.90 [WARN] The `pex_binary` target teletom/tom/entry:binaries#server.py transitively depends on the below `files` targets, but Pants will not include them in the PEX. Filesystem APIs like `open()` are not able to load files within the binary itself; instead, they read from the current working directory.
Instead, use `resources` targets or wrap this `pex_binary` in an `archive`. See <https://www.pantsbuild.org/v2.16/docs/resources>.
Files targets dependencies: ['openapi:config', 'teletom/frontend:build']
13:23:15.34 [INFO] Completed: Building 25 requirements for teletom.tom.entry/server_py.pex from the python-default.lock resolve: adafruit-blinka, adafruit-circuitpython-neopixel, cffi, connexion[swagger-ui], dataclasses-json, flas... (278 characters truncated)
Traceback (most recent call last):
File "/home/geethree/.pyenv/versions/3.9.10/lib/python3.9/runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/home/geethree/.pyenv/versions/3.9.10/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/home/geethree/.pex/unzipped_pexes/d5ce9d1a05de575035c8b552120b12265c3f21d4/__main__.py", line 106, in <module>
bootstrap_pex(__entry_point__, execute=__execute__, venv_dir=__venv_dir__)
File "/home/geethree/.pex/unzipped_pexes/d5ce9d1a05de575035c8b552120b12265c3f21d4/.bootstrap/pex/pex_bootstrapper.py", line 618, in bootstrap_pex
pex.PEX(entry_point).execute()
File "/home/geethree/.pex/unzipped_pexes/d5ce9d1a05de575035c8b552120b12265c3f21d4/.bootstrap/pex/pex.py", line 560, in execute
sys.exit(self._wrap_coverage(self._wrap_profiling, self._execute))
File "/home/geethree/.pex/unzipped_pexes/d5ce9d1a05de575035c8b552120b12265c3f21d4/.bootstrap/pex/pex.py", line 467, in _wrap_coverage
return runner(*args)
File "/home/geethree/.pex/unzipped_pexes/d5ce9d1a05de575035c8b552120b12265c3f21d4/.bootstrap/pex/pex.py", line 498, in _wrap_profiling
return runner(*args)
File "/home/geethree/.pex/unzipped_pexes/d5ce9d1a05de575035c8b552120b12265c3f21d4/.bootstrap/pex/pex.py", line 603, in _execute
return self.execute_entry(
File "/home/geethree/.pex/unzipped_pexes/d5ce9d1a05de575035c8b552120b12265c3f21d4/.bootstrap/pex/pex.py", line 800, in execute_entry
return self.execute_module(entry_point.module)
File "/home/geethree/.pex/unzipped_pexes/d5ce9d1a05de575035c8b552120b12265c3f21d4/.bootstrap/pex/pex.py", line 808, in execute_module
runpy.run_module(module_name, run_name="__main__", alter_sys=True)
File "/home/geethree/.pyenv/versions/3.9.10/lib/python3.9/runpy.py", line 210, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "/home/geethree/.pyenv/versions/3.9.10/lib/python3.9/runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "/home/geethree/.pyenv/versions/3.9.10/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/home/geethree/.pex/unzipped_pexes/d5ce9d1a05de575035c8b552120b12265c3f21d4/tom/entry/server.py", line 12, in <module>
from tom.server.main import make_controller
File "/home/geethree/.pex/unzipped_pexes/d5ce9d1a05de575035c8b552120b12265c3f21d4/tom/server/main.py", line 28, in <module>
OBSERVATORY_CONFIG = importlib.resources.path("openapi", "observatory.yaml")
File "/home/geethree/.pyenv/versions/3.9.10/lib/python3.9/importlib/resources.py", line 161, in path
reader = _get_resource_reader(_get_package(package))
File "/home/geethree/.pyenv/versions/3.9.10/lib/python3.9/importlib/resources.py", line 49, in _get_package
module = _resolve(package)
File "/home/geethree/.pyenv/versions/3.9.10/lib/python3.9/importlib/resources.py", line 40, in _resolve
return import_module(name)
File "/home/geethree/.pyenv/versions/3.9.10/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'openapi'
fast-nail-55400
07/14/2023, 9:21 PM13:22:37.90 [WARN] The `pex_binary` target teletom/tom/entry:binaries#server.py transitively depends on the below `files` targets, but Pants will not include them in the PEX. Filesystem APIs like `open()` are not able to load files within the binary itself; instead, they read from the current working directory.
Instead, use `resources` targets or wrap this `pex_binary` in an `archive`. See <https://www.pantsbuild.org/v2.16/docs/resources>.
fast-nail-55400
07/14/2023, 9:22 PMpurple-plastic-57801
07/14/2023, 9:26 PMresource(
name="resource",
source="observatory.yaml",
)
...server/BUILD
python_sources(
dependencies=[
"//teletom/frontend:build",
"//openapi:resource",
"//.build/requirements:reqs#setuptools",
]
)
purple-plastic-57801
07/14/2023, 9:27 PMfast-nail-55400
07/14/2023, 9:27 PM__init__.py
file ?purple-plastic-57801
07/14/2023, 9:27 PMfast-nail-55400
07/14/2023, 9:28 PMpython_sources
target to let Pants make use of that filepurple-plastic-57801
07/14/2023, 9:43 PMfast-nail-55400
07/14/2023, 10:16 PMopenapi:config
and teletom/frontend:build
file
targets as it mentioned?purple-plastic-57801
07/14/2023, 10:16 PMfast-nail-55400
07/14/2023, 10:17 PMresource
does the warning go away and/or does the error go away?purple-plastic-57801
07/14/2023, 10:17 PMfast-nail-55400
07/14/2023, 10:18 PMopenapi
modules have been packed into the pex?fast-nail-55400
07/14/2023, 10:21 PMModuleNotFoundError: No module named 'openapi'
error implies to me that something is wrong with how the openapi
module is being placed in the pexfast-nail-55400
07/14/2023, 10:22 PMopenapi/observatory.yaml
and the source root openapi
. You would need the file in openapi/openapi/observatory.yaml
in order to import it in the manner you are trying to dopurple-plastic-57801
07/14/2023, 10:23 PMfast-nail-55400
07/14/2023, 10:23 PMfast-nail-55400
07/14/2023, 10:23 PMopenapi/src/openapi
with a source root of openapi/src