From d37811166eb58da3d30f9fdea91f65fce5152815 Mon Sep 17 00:00:00 2001 From: Douglas Thor Date: Thu, 15 Feb 2024 15:22:23 -0800 Subject: [PATCH 1/5] Use MODULE.bazel --- MODULE.bazel | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 MODULE.bazel diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 0000000..69a0cc5 --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1,38 @@ +# Name the workspace/module +module( + name = "bitwarden-to-keepass", + version = "0.0.0", + compatibility_level = 1, +) + +# Install rules_python, which allows us to define how bazel should work with python files. +# See https://github.com/bazelbuild/rules_python/blob/c6941a8dad4c7a221125fbad7c8bfaac377e00ba/examples/bzlmod/MODULE.bazel +bazel_dep(name = "rules_python", version = "0.31.0") + +# Init the python toolchain using the extension. +# This is similar to the "python_register_toolchains" function in WORKSPACE. +python = use_extension("@rules_python//python/extensions:python.bzl", "python") +python.toolchain( + configure_coverage_tool = True, + # Available versions are listed in @rules_python//python:versions.bzl. + python_version = "3.8" +) + +# Enable pip +pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip") + + +# To fetch pip dependencies, use pip.parse. We can pass in various options, +# but typically we pass requirements and the Python version. The Python +# version must have been configured by a corresponding `python.toolchain()` +# call. +pip.parse( + # This name is what gets used in other BUILD files with `load()`. + hub_name = "pypi", + python_version = "3.8.18", + # python_interpreter_target = interpreter, + requirements_lock = "//:requirements_lock.txt", +) + +# Same as WORKSPACE install_deps() +use_repo(pip, "pypi") From b0b679fd4e7e90c864cd83c69c6557bccb28331a Mon Sep 17 00:00:00 2001 From: Douglas Thor Date: Thu, 15 Feb 2024 15:28:40 -0800 Subject: [PATCH 2/5] Update comments --- MODULE.bazel | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 69a0cc5..ccf7a1f 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -11,28 +11,28 @@ bazel_dep(name = "rules_python", version = "0.31.0") # Init the python toolchain using the extension. # This is similar to the "python_register_toolchains" function in WORKSPACE. +# It creates a hermetic python rather than relying on a system-installed interpreter. python = use_extension("@rules_python//python/extensions:python.bzl", "python") python.toolchain( configure_coverage_tool = True, # Available versions are listed in @rules_python//python:versions.bzl. + # For some reason we can't set 3.8.18 here - it causes pip.parse() to fail. python_version = "3.8" ) # Enable pip pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip") - -# To fetch pip dependencies, use pip.parse. We can pass in various options, -# but typically we pass requirements and the Python version. The Python -# version must have been configured by a corresponding `python.toolchain()` -# call. +# Configure how we fetch python dependencies via pip pip.parse( # This name is what gets used in other BUILD files with `load()`. hub_name = "pypi", python_version = "3.8.18", - # python_interpreter_target = interpreter, + # TODO: what to put here? Using this might resolve the "can't set 3.8.18" + # issue mentioned above. + # python_interpreter_target = python, requirements_lock = "//:requirements_lock.txt", ) -# Same as WORKSPACE install_deps() +# Same as WORKSPACE install_deps() - actually install the python deps. use_repo(pip, "pypi") From 779d83d95965550a8dac6b025d438275f7638ccb Mon Sep 17 00:00:00 2001 From: Douglas Thor Date: Thu, 15 Feb 2024 15:29:09 -0800 Subject: [PATCH 3/5] Remove old WORKSPACE file --- WORKSPACE | 60 ------------------------------------------------------- 1 file changed, 60 deletions(-) delete mode 100644 WORKSPACE diff --git a/WORKSPACE b/WORKSPACE deleted file mode 100644 index 90667d4..0000000 --- a/WORKSPACE +++ /dev/null @@ -1,60 +0,0 @@ -# Name the workspace -workspace(name = "bitwarden-to-keepass") - -# Install rules_python, which allows us to define how bazel should work with python files. -# See https://rules-python.readthedocs.io/en/latest/getting-started.html#using-a-workspace-file -# Note: These "##### START ... #####" comments are just my own - they do not have -# any meaning in bazel. -##### START install rules_python snippet (https://github.com/bazelbuild/rules_python/releases/tag/0.28.0) ##### -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - -http_archive( - name = "rules_python", - sha256 = "d70cd72a7a4880f0000a6346253414825c19cdd40a28289bdf67b8e6480edff8", - strip_prefix = "rules_python-0.28.0", - url = "https://github.com/bazelbuild/rules_python/releases/download/0.28.0/rules_python-0.28.0.tar.gz", -) - -load("@rules_python//python:repositories.bzl", "py_repositories") - -py_repositories() -##### END install rules_python snippet ##### - - -# Use a hermetic python rather than relying on a system-installed interpreter: -# See https://rules-python.readthedocs.io/en/stable/getting-started.html#toolchain-registration -##### START hermetic python snippet ##### -load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains") - -py_repositories() - -python_register_toolchains( - name = "python3_8", - # Available versions are listed in @rules_python//python:versions.bzl. - # We recommend using the same version your team is already standardized on. - python_version = "3.8.18", - # Support coverage. See https://rules-python.readthedocs.io/en/stable/coverage.html - register_coverage_tool = True, -) - -load("@python3_8//:defs.bzl", interpreter = "interpreter") -##### END hermetic python snippet ##### - - -# Install dependencies from PyPI. -# See https://rules-python.readthedocs.io/en/stable/pypi-dependencies.html#using-a-workspace-file -# and https://rules-python.readthedocs.io/en/stable/pip.html -##### START install python dependencies snippet ##### -load("@rules_python//python:pip.bzl", "pip_parse") - -pip_parse( - name = "pypi", - python_interpreter_target = interpreter, # From hermetic python snippet - # TODO: Can requirements come from pyproject.toml? - requirements_lock = "//:requirements_lock.txt", -) - -load("@pypi//:requirements.bzl", "install_deps") - -install_deps() -##### END install python dependencies snippet ##### From e84cf0b0fde25ac8019910cb5e90492d4f24d081 Mon Sep 17 00:00:00 2001 From: Douglas Thor Date: Thu, 15 Feb 2024 21:10:18 -0800 Subject: [PATCH 4/5] Update bazelrc --- .bazelrc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.bazelrc b/.bazelrc index 3ea47bb..1208471 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,5 +1,5 @@ -# Don't use the MODULE.bazel stuff yet. -common --noenable_bzlmod +# Use the MODULE.bazel stuff instead of the old WORKSPACE. +common --enable_bzlmod # Show output if tests fail. test --test_output=errors From b7c3eda2119a4a2d6e81e93dfe55ebff595b6587 Mon Sep 17 00:00:00 2001 From: Douglas Thor Date: Tue, 20 Feb 2024 11:09:01 -0800 Subject: [PATCH 5/5] Update .gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 9f16ff8..eafa672 100644 --- a/.gitignore +++ b/.gitignore @@ -162,3 +162,7 @@ secrets.sh /.clwb/ # End of https://www.toptal.com/developers/gitignore/api/bazel + +# Ignore Bazel's lockfile until usability gets resolved. See +# https://github.com/bazelbuild/bazel/issues/20369 +MODULE.bazel.lock