diff --git a/.bazelrc b/.bazelrc index 363bb2a..8537a66 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1 +1,2 @@ build --//:mypy=//third_party:mypy +common --enable_bzlmod diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index e2282ae..241f2c4 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -13,6 +13,14 @@ jobs: fail-fast: false matrix: bzlmodEnabled: [true, false] + folder: [".", "examples"] + exclude: + # No point keeping the root workspace compatible with --noenable_bzlmod + - folder: "." + bzlmodEnabled: false + defaults: + run: + working-directory: ${{ matrix.folder }} steps: # Checks-out the repository under $GITHUB_WORKSPACE, so the job can access it @@ -22,5 +30,10 @@ jobs: bazelrc: common --announce_rc --color=yes --enable_bzlmod=${{ matrix.bzlmodEnabled }} - name: Run tests run: bazel test //... + + integration-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 - name: Run integration tests run: ./test.sh diff --git a/.gitignore b/.gitignore index d7d7bd5..59bdffc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# Remove after the lockfile format is more stable +MODULE.bazel.lock + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 0000000..69f0949 --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1,28 @@ +"Bazel dependencies under bzlmod" + +module( + name = "mypy_integration", + # Replaced with the tag during BCR publishing + version = "0.0.0", + compatibility_level = 1, +) + +# Lower-bound dependency versions. +# Only increase these when needed, otherwise users get warnings from Bazel about how the selected +# version is greater than the one they specified. +bazel_dep(name = "rules_python", version = "0.27.1") +bazel_dep(name = "bazel_skylib", version = "1.5.0") + +bazel_dep(name = "buildifier_prebuilt", version = "6.4.0", dev_dependency = True) + +python = use_extension("@rules_python//python/extensions:python.bzl", "python", dev_dependency = True) +python.toolchain(python_version = "3.8") + +pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip", dev_dependency = True) +pip.parse( + hub_name = "pypi", + python_version = "3.8", + requirements_lock = "//third_party:requirements.txt", +) + +use_repo(pip, "pypi") \ No newline at end of file diff --git a/WORKSPACE b/WORKSPACE index 4d193ce..01c1741 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,63 +1,2 @@ -workspace(name = "bazel_mypy_integration") - -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -load("//repositories:repositories.bzl", mypy_integration_repositories = "repositories") - -mypy_integration_repositories() - -load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains") - -py_repositories() - -python_register_toolchains( - name = "python3_8", - python_version = "3.8", -) - -load("@python3_8//:defs.bzl", python_interpreter = "interpreter") -load("@rules_python//python:pip.bzl", "pip_parse") - -pip_parse( - name = "mypy_integration_pip_deps", - python_interpreter_target = python_interpreter, - requirements_lock = "//third_party:requirements.txt", -) - -load("@mypy_integration_pip_deps//:requirements.bzl", install_mypy_deps = "install_deps") - -install_mypy_deps() - -http_archive( - name = "buildifier_prebuilt", - sha256 = "8ada9d88e51ebf5a1fdff37d75ed41d51f5e677cdbeafb0a22dda54747d6e07e", - strip_prefix = "buildifier-prebuilt-6.4.0", - urls = [ - "http://github.com/keith/buildifier-prebuilt/archive/6.4.0.tar.gz", - ], -) - -load("@buildifier_prebuilt//:deps.bzl", "buildifier_prebuilt_deps") - -buildifier_prebuilt_deps() - -load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") - -bazel_skylib_workspace() - -load("@buildifier_prebuilt//:defs.bzl", "buildifier_prebuilt_register_toolchains") - -buildifier_prebuilt_register_toolchains() - -http_archive( - name = "com_google_protobuf", - sha256 = "d19643d265b978383352b3143f04c0641eea75a75235c111cc01a1350173180e", - strip_prefix = "protobuf-25.3", - urls = [ - "https://mirror.bazel.build/github.com/protocolbuffers/protobuf/archive/v25.3.tar.gz", - "https://github.com/protocolbuffers/protobuf/archive/v25.3.tar.gz", - ], -) - -load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") - -protobuf_deps() +# Marker file that this is the root of a Bazel workspace. +# Dependencies appear in MODULE.bazel diff --git a/examples/.bazelrc b/examples/.bazelrc index ec101f4..3bafb4f 100644 --- a/examples/.bazelrc +++ b/examples/.bazelrc @@ -1 +1,2 @@ build --@mypy_integration//:mypy=//tools/typing:mypy +common --java_runtime_version=remotejdk_11 diff --git a/examples/MODULE.bazel b/examples/MODULE.bazel new file mode 100644 index 0000000..8c75af6 --- /dev/null +++ b/examples/MODULE.bazel @@ -0,0 +1,32 @@ +"Bazel dependencies, used under --enable_bzlmod" + +module( + name = "mypy-integration-examples", + version = "0.0.0", + compatibility_level = 1, +) + +bazel_dep(name = "mypy_integration", version = "0.0.0") +bazel_dep(name = "rules_java", version = "7.4.0") +bazel_dep(name = "rules_python", version = "0.27.1") + +local_path_override( + module_name = "mypy_integration", + path = "..", +) + +python = use_extension("@rules_python//python/extensions:python.bzl", "python") +python.toolchain(python_version = "3.8") + +pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip") +pip.parse( + hub_name = "my_deps", + python_version = "3.8", + requirements_lock = "//third_party:requirements.txt", +) +pip.parse( + hub_name = "my_mypy_deps", + python_version = "3.8", + requirements_lock = "//tools/typing:mypy_requirements.txt", +) +use_repo(pip, "my_deps", "my_mypy_deps") diff --git a/examples/WORKSPACE.bzlmod b/examples/WORKSPACE.bzlmod new file mode 100644 index 0000000..3224613 --- /dev/null +++ b/examples/WORKSPACE.bzlmod @@ -0,0 +1 @@ +# Under --enable_bzlmod, this file shadows WORKSPACE diff --git a/third_party/BUILD b/third_party/BUILD index abd553c..eb13ad6 100644 --- a/third_party/BUILD +++ b/third_party/BUILD @@ -1,4 +1,4 @@ -load("@mypy_integration_pip_deps//:requirements.bzl", "requirement") +load("@pypi//:requirements.bzl", "requirement") load("@rules_python//python:pip.bzl", "compile_pip_requirements") alias(