Look at the import requests
line in your __main__.py
file. In your editor, it probably appears with some yellow squiggle underscores, indicating that we won’t have features like auto-complete, jump-to-definition, docs-on-hover, and so on.
Let’s fix that.
Python tooling expects a Virtual Environment (”virtualenv”) which is a specially-constructed folder with a linked Python interpreter, and packages installed in a site-packages
subfolder. Since our repository gets the py_binary
from aspect_rules_py
, it includes a venv
target which produces this.
Run bazel query --output=label_kind app:all
to see what targets are available.
py_library rule //app:__test__
_py_pytest_main rule //app:__test___template
determine_main rule //app:_app_bin.find_main
determine_main rule //app:_app_test.find_main
py_binary rule //app:app_bin
py_venv_rule rule //app:app_bin.venv
py_test rule //app:app_test
py_venv_rule rule //app:app_test.venv
Here we see app:app_bin.env
is an option, so let’s run that:
% bazel run app:app_bin.venv
Once this has run, the editor should see that a virtualenv now exists in the source folder, and offer to use it to resolve dependencies. Here’s Visual Studio Code with the standard Python extension, for example:
Once we activate this virtualenv, he yellow squiggles should disappear, and you should be able to navigate through the import statement to the requests package.