diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b43c3ec..36f9532 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,8 +9,11 @@ jobs: - name: Checkout repository uses: actions/checkout@v4.2.2 - name: Run python_basics integration tests + # Have to create the virtualenv as it's a run command. Otherwise basic_venv is just build and won't be able + # To execute what we need in the simple-tests. run: | cd python_basics/integration_tests + bazel run //simple-tests:basic_venv bazel test //... - name: Run starpls integration tests run: | diff --git a/.yamlfmt b/.yamlfmt new file mode 100644 index 0000000..e9d24f9 --- /dev/null +++ b/.yamlfmt @@ -0,0 +1,3 @@ +formatter: + type: basic + retain_line_breaks: true diff --git a/MODULE.bazel b/MODULE.bazel index e6c032d..dc747f5 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -94,7 +94,7 @@ multitool.hub( ) use_repo(multitool, "yamlfmt_hub") -bazel_dep(name = "score_docs_as_code", version = "3.0.1", dev_dependency = True) +bazel_dep(name = "score_docs_as_code", version = "3.0.1") # bazel_dep(name = "score_platform", version = "0.5.0") bazel_dep(name = "score_process", version = "1.3.2") diff --git a/python_basics/integration_tests/MODULE.bazel b/python_basics/integration_tests/MODULE.bazel index 901c253..1a2959f 100644 --- a/python_basics/integration_tests/MODULE.bazel +++ b/python_basics/integration_tests/MODULE.bazel @@ -16,7 +16,7 @@ # Python version & Pip # ############################################################################### -bazel_dep(name = "rules_python", version = "1.4.1") +bazel_dep(name = "rules_python", version = "1.8.4") PYTHON_VERSION = "3.12" @@ -45,7 +45,7 @@ use_repo(pip, "pip_score_venv_test") # Generic linting and formatting rules # ############################################################################### -bazel_dep(name = "aspect_rules_py", version = "1.4.0") +bazel_dep(name = "aspect_rules_py", version = "1.6.6") bazel_dep(name = "bazel_skylib", version = "1.7.1", dev_dependency = True) diff --git a/python_basics/integration_tests/simple-tests/BUILD b/python_basics/integration_tests/simple-tests/BUILD index cb3db11..0554737 100644 --- a/python_basics/integration_tests/simple-tests/BUILD +++ b/python_basics/integration_tests/simple-tests/BUILD @@ -21,6 +21,7 @@ score_py_pytest( name = "venv_ok_test", srcs = ["test_venv_ok.py"], data = [":basic_venv"], + deps = ["@rules_python//python/runfiles"], ) score_py_pytest( diff --git a/python_basics/integration_tests/simple-tests/test_venv_ok.py b/python_basics/integration_tests/simple-tests/test_venv_ok.py index 92d6dcc..ae9de27 100644 --- a/python_basics/integration_tests/simple-tests/test_venv_ok.py +++ b/python_basics/integration_tests/simple-tests/test_venv_ok.py @@ -13,10 +13,16 @@ import os import subprocess from pathlib import Path +from python.runfiles import Runfiles def test_venv_ok(): - runfiles = os.getenv("RUNFILES_DIR") + """ + This test checks if the pytest module is available in the runfiles and if it can be used without + installing pytest explicitly inside the virtualenv + """ + if (r := Runfiles.Create()) and (rd := r.EnvVars().get("RUNFILES_DIR")): + runfiles = Path(rd) assert runfiles, "runfiles could not be found, RUNFILES_DIR is not set" packages = os.listdir(runfiles) assert any(x.endswith("pytest") for x in packages), ( @@ -26,7 +32,6 @@ def test_venv_ok(): import pytest # type ignore python_venv_folder = [x for x in packages if "python_3_12_" in x][0] - # Trying to actually use pytest module and collect current test & file proc = subprocess.run( [ diff --git a/python_basics/integration_tests/venv-with-extra-requirements/test_extra_requirements_ok.py b/python_basics/integration_tests/venv-with-extra-requirements/test_extra_requirements_ok.py index f479e87..752c1c5 100644 --- a/python_basics/integration_tests/venv-with-extra-requirements/test_extra_requirements_ok.py +++ b/python_basics/integration_tests/venv-with-extra-requirements/test_extra_requirements_ok.py @@ -11,10 +11,13 @@ # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* import os +from python.runfiles import Runfiles +from pathlib import Path def test_venv_ok(): - runfiles = os.getenv("RUNFILES_DIR") + if (r := Runfiles.Create()) and (rd := r.EnvVars().get("RUNFILES_DIR")): + runfiles = Path(rd) packages = os.listdir(runfiles) assert any(x.endswith("requests") for x in packages), ( f"'Request not found in runfiles: {runfiles}"