- ✅ Makes development of Python code easier inside Bazel
- ✅ Provides a Python virtualenv target
- ✅ Provides S-CORE wide defaults for linting and formatting
- ✅ Provides pytest with S-CORE wide defaults for pytest
In the consuming Bazel project, in your MODULE.bazel import the python basics
bazel_dep(name = "score_tooling", version = "1.0.4")The score_virtualenv rule creates a virtualenv for your IDE (syntax highlighting, formatting, linting etc).
load("@score_tooling//:defs.bzl", "score_virtualenv")
score_virtualenv(
# optional: change target name
name = "ide_support",
# optional: change generated venv name
venv_name = ".venv",
# optional: add your own requirements
# e.g. all_requirements comming from your pip installation via '@pip...
reqs = []
)You can create the virtualenv via the name you have defined above, e.g. bazel run //:ide_support.
The score_py_pytest rule creates a pytest target.
Note: the pytest version is determined by the score_python_basics module. It is intentionally not possible to overwrite it.
load("@score_tooling//:defs.bzl", "score_py_pytest")
score_py_pytest(
name = "test_my_first_check",
srcs = [
"test_my_first_check.py"
],
plugins = [
# Optionally specify pytest plugins, that will register their fixtures
],
args = [
# Specify optional arguments, ex:
"--basetemp=/tmp/pytest",
],
# Optionally provide config file that will override the default one
# pytest.ini / pytest.toml / pyproject.toml are accepted
pytest_config = "//my_pytest:my_pytest_ini",
# Optionally provide tags the test should have, in order to allow for execution grouping
tags = [
"integration",
#...
]
)Basedpyright provides enhanced type checking and Pylance features for Python development. It's included as part of the score_python_basics package.
Note: The basedpyright version is determined by the score_python_basics module's dependencies (see requirements.txt).
To enable Basedpyright in your VS Code editor:
-
Ensure the virtual environment is active: Make sure you have created and selected the Python interpreter from the virtual environment generated by
score_virtualenv(see Python Virtualenv section and Development setup). -
Install the extension: Add the
detachhead.basedpyrightextension to your.vscode/extensions.jsonfile:{ "recommendations": [ // ... other extensions "detachhead.basedpyright" ] } -
Define a root
pyproject.tomlthat includes:[tool.basedpyright] extends = "bazel-bin/ide_support.runfiles/score_python_basics~/pyproject.toml" exclude = [ "**/__pycache__", "**/.*", "**/bazel-*", ]
-
Reload VS Code: Reload the window to activate the extension. Basedpyright will automatically use the selected Python interpreter from your virtual environment for type checking.
To set up the development environment, you need to create a python virtual environment:
bazel run private:ide_supportNote: for now the virtualenv is created in the python_basics directory. VS
Code will not detect it automatically. You need to set the interpreter
(python_basics/.venv/bin/python) manually via ctrl+shift+p and "Python: Select
Interpreter".
It uses the dependencies from requirements.txt.
If you have added new dependencies, make sure to update the requirements.txt file like so:
# Add new dependencies:
bazel run //private:requirements.update
# Upgrade all dependencies:
bazel run //private:requirements.update -- --upgradeTo run the tests of the pytest module use:
bazel test //...