diff --git a/python_basics/README.md b/python_basics/README.md index 775d19d..583f3de 100644 --- a/python_basics/README.md +++ b/python_basics/README.md @@ -10,14 +10,15 @@ In the consuming Bazel project, in your `MODULE.bazel` import the python basics ```python -bazel_dep(name = "score_python_basics", version = "0.3.0") +bazel_dep(name = "score_tooling", version = "1.0.4") ``` ## Python Virtualenv + The `score_virtualenv` rule creates a virtualenv for your IDE (syntax highlighting, formatting, linting etc). ```python -load("@score_python_basics//:defs.bzl", "score_virtualenv") +load("@score_tooling//:defs.bzl", "score_virtualenv") score_virtualenv( # optional: change target name @@ -42,7 +43,7 @@ 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.* ```python -load("@score_python_basics//:defs.bzl", "score_py_pytest") +load("@score_tooling//:defs.bzl", "score_py_pytest") score_py_pytest( name = "test_my_first_check", @@ -54,13 +55,17 @@ score_py_pytest( ], args = [ # Specify optional arguments, ex: - "--basetemp /tmp/pytest", + "--basetemp=/tmp/pytest", ], - # Optionally provide pytest.ini file, that will override the default one - pytest_ini = "//my_pytest:my_pytest_ini", + # 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", #...] + tags = [ + "integration", + #... + ] ) ``` @@ -74,9 +79,9 @@ Basedpyright provides enhanced type checking and Pylance features for Python dev To enable Basedpyright in your VS Code editor: -1. **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](#python-virtualenv) section and [Development setup](#setting-up-the-development-environment)). +1. **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](#python-virtualenv) section and [Development setup](#setting-up-the-development-environment)). -2. **Install the extension:** Add the `detachhead.basedpyright` extension to your `.vscode/extensions.json` file: +2. **Install the extension:** Add the `detachhead.basedpyright` extension to your `.vscode/extensions.json` file: ```json { @@ -87,11 +92,12 @@ To enable Basedpyright in your VS Code editor: } ``` -3. Define a root `pyproject.toml` that includes: +3. Define a root `pyproject.toml` that includes: + ```toml [tool.basedpyright] extends = "bazel-bin/ide_support.runfiles/score_python_basics~/pyproject.toml" - + exclude = [ "**/__pycache__", "**/.*", @@ -99,13 +105,15 @@ To enable Basedpyright in your VS Code editor: ] ``` -4. **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. +4. **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. ## Development of score_python_basics ### Setting up the development environment + To set up the development environment, you need to create a python virtual environment: + ```bash bazel run private:ide_support ``` @@ -115,11 +123,12 @@ 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".* - ### Updating pytest in score_python_basics -It uses the dependencies from `requirements.txt`. -If you have added new dependencies, make sure to update the *requirements.txt* file like so: -``` + +It uses the dependencies from `requirements.txt`. +If you have added new dependencies, make sure to update the *requirements.txt* file like so: + +```bash # Add new dependencies: bazel run //private:requirements.update @@ -128,7 +137,9 @@ bazel run //private:requirements.update -- --upgrade ``` ### Running tests + To run the tests of the pytest module use: -``` -$ bazel test //... + +```bash +bazel test //... ``` diff --git a/python_basics/integration_tests/simple-tests/pytest_ok.py b/python_basics/integration_tests/simple-tests/pytest_ok.py index 4d0eaa3..465f4e8 100644 --- a/python_basics/integration_tests/simple-tests/pytest_ok.py +++ b/python_basics/integration_tests/simple-tests/pytest_ok.py @@ -14,4 +14,4 @@ def test_pytest_works(): - assert pytest.__version__ >= "8.3.4" + assert pytest.__version__ >= "9.0.1" diff --git a/python_basics/requirements.txt b/python_basics/requirements.txt index 016ad1a..fcfba3f 100644 --- a/python_basics/requirements.txt +++ b/python_basics/requirements.txt @@ -4,24 +4,24 @@ # # bazel run //private:requirements.update # -basedpyright==1.29.2 \ - --hash=sha256:12c49186003b9f69a028615da883ef97035ea2119a9e3f93a00091b3a27088a6 \ - --hash=sha256:f389e2997de33d038c5065fd85bff351fbdc62fa6d6371c7b947fc3bce8d437d +basedpyright==1.35.0 \ + --hash=sha256:2a7e0bd476623d48499e2b18ff6ed19dc28c51909cf9e1152ad355b5809049ad \ + --hash=sha256:4f4f84023df5a0cd4ee154916ba698596682ac98bacfa22c941ed6aaf07bba4e # via -r requirements.in -iniconfig==2.1.0 \ - --hash=sha256:3abbd2e30b36733fee78f9c7f7308f2d0050e88f0087fd25c2645f63c773e1c7 \ - --hash=sha256:9deba5723312380e77435581c6bf4935c94cbfab9b1ed33ef8d238ea168eb760 +iniconfig==2.3.0 \ + --hash=sha256:c76315c77db068650d49c5b56314774a7804df16fee4402c1f19d6d15d8c4730 \ + --hash=sha256:f631c04d2c48c52b84d0d0549c99ff3859c98df65b3101406327ecc7d53fbf12 # via pytest -nodejs-wheel-binaries==22.16.0 \ - --hash=sha256:2728972d336d436d39ee45988978d8b5d963509e06f063e80fe41b203ee80b28 \ - --hash=sha256:2fffb4bf1066fb5f660da20819d754f1b424bca1b234ba0f4fa901c52e3975fb \ - --hash=sha256:447ad796850eb52ca20356ad39b2d296ed8fef3f214921f84a1ccdad49f2eba1 \ - --hash=sha256:4ae3cf22138891cb44c3ee952862a257ce082b098b29024d7175684a9a77b0c0 \ - --hash=sha256:71f2de4dc0b64ae43e146897ce811f80ac4f9acfbae6ccf814226282bf4ef174 \ - --hash=sha256:7f526ca6a132b0caf633566a2a78c6985fe92857e7bfdb37380f76205a10b808 \ - --hash=sha256:986b715a96ed703f8ce0c15712f76fc42895cf09067d72b6ef29e8b334eccf64 \ - --hash=sha256:d695832f026df3a0cf9a089d222225939de9d1b67f8f0a353b79f015aabbe7e2 \ - --hash=sha256:dbfccbcd558d2f142ccf66d8c3a098022bf4436db9525b5b8d32169ce185d99e +nodejs-wheel-binaries==24.11.1 \ + --hash=sha256:0e14874c3579def458245cdbc3239e37610702b0aa0975c1dc55e2cb80e42102 \ + --hash=sha256:10197b1c9c04d79403501766f76508b0dac101ab34371ef8a46fcf51773497d0 \ + --hash=sha256:376b9ea1c4bc1207878975dfeb604f7aa5668c260c6154dcd2af9d42f7734116 \ + --hash=sha256:413dfffeadfb91edb4d8256545dea797c237bba9b3faefea973cde92d96bb922 \ + --hash=sha256:5ef598101b0fb1c2bf643abb76dfbf6f76f1686198ed17ae46009049ee83c546 \ + --hash=sha256:78bc5bb889313b565df8969bb7423849a9c7fc218bf735ff0ce176b56b3e96f0 \ + --hash=sha256:c2741525c9874b69b3e5a6d6c9179a6fe484ea0c3d5e7b7c01121c8e5d78b7e2 \ + --hash=sha256:c79a7e43869ccecab1cae8183778249cceb14ca2de67b5650b223385682c6239 \ + --hash=sha256:cde41d5e4705266688a8d8071debf4f8a6fcea264c61292782672ee75a6905f9 # via basedpyright packaging==25.0 \ --hash=sha256:29572ef2b1f17581046b3a2227d5c611fb25ec70ca1ba8554b24b0e69331a484 \ @@ -31,7 +31,11 @@ pluggy==1.6.0 \ --hash=sha256:7dcc130b76258d33b90f61b658791dede3486c3e6bfb003ee5c9bfb396dd22f3 \ --hash=sha256:e920276dd6813095e9377c0bc5566d94c932c33b27a3e3945d8389c374dd4746 # via pytest -pytest==8.3.5 \ - --hash=sha256:c69214aa47deac29fad6c2a4f590b9c4a9fdb16a403176fe154b79c0b4d4d820 \ - --hash=sha256:f4efe70cc14e511565ac476b57c279e12a855b11f48f212af1080ef2263d3845 +pygments==2.19.2 \ + --hash=sha256:636cb2477cec7f8952536970bc533bc43743542f70392ae026374600add5b887 \ + --hash=sha256:86540386c03d588bb81d44bc3928634ff26449851e99741617ecb9037ee5ec0b + # via pytest +pytest==9.0.1 \ + --hash=sha256:3e9c069ea73583e255c3b21cf46b8d3c56f6e3a1a8f6da94ccb0fcf57b9d73c8 \ + --hash=sha256:67be0030d194df2dfa7b556f2e56fb3c3315bd5c8822c6951162b92b32ce7dad # via -r requirements.in diff --git a/python_basics/score_pytest/py_pytest.bzl b/python_basics/score_pytest/py_pytest.bzl index 0cc7bab..dd9f3ff 100644 --- a/python_basics/score_pytest/py_pytest.bzl +++ b/python_basics/score_pytest/py_pytest.bzl @@ -15,12 +15,12 @@ load("@pip_tooling//:requirements.bzl", "all_requirements") load("@rules_python//python:defs.bzl", "py_test") -def score_py_pytest(name, srcs, args = [], data = [], deps = [], env = {}, plugins = [], pytest_ini = None, **kwargs): +def score_py_pytest(name, srcs, args = [], data = [], deps = [], env = {}, plugins = [], pytest_config = None, **kwargs): pytest_bootstrap = Label("@score_tooling//python_basics/score_pytest:main.py") - if not pytest_ini: - pytest_ini = Label("@score_tooling//python_basics/score_pytest:pytest.ini") - #fail("$(location %s)" % pytest_ini) + if not pytest_config: + pytest_config = Label("@score_tooling//python_basics/score_pytest:pytest.ini") + #fail("$(location %s)" % pytest_config) if not srcs: fail("No source files provided for %s! (Is your glob empty?)" % name) @@ -34,7 +34,7 @@ def score_py_pytest(name, srcs, args = [], data = [], deps = [], env = {}, plugi ] + srcs, main = pytest_bootstrap, args = [ - "-c $(location %s)" % pytest_ini, + "-c $(location %s)" % pytest_config, "-p no:cacheprovider", # XML_OUTPUT_FILE: Location to which test actions should write a test @@ -48,7 +48,7 @@ def score_py_pytest(name, srcs, args = [], data = [], deps = [], env = {}, plugi ["$(location %s)" % x for x in srcs], deps = ["@score_tooling//python_basics/score_pytest:attribute_plugin"] + all_requirements + deps, data = [ - pytest_ini, + pytest_config, ] + data, env = env | { "PYTHONDONOTWRITEBYTECODE": "1",