Skip to content

Commit

Permalink
Update rules_python, and vendor our requirements.bzl
Browse files Browse the repository at this point in the history
  • Loading branch information
ericastor authored and mithro committed Oct 4, 2023
1 parent 1235399 commit 653bd51
Show file tree
Hide file tree
Showing 7 changed files with 432 additions and 16 deletions.
5 changes: 3 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ llvm_toolchain(
maybe(
http_archive,
name = "rules_python",
sha256 = "b6d46438523a3ec0f3cead544190ee13223a52f6a6765a29eae7b7cc24cc83a0",
url = "https://github.com/bazelbuild/rules_python/releases/download/0.1.0/rules_python-0.1.0.tar.gz",
sha256 = "5868e73107a8e85d8f323806e60cad7283f34b32163ea6ff1020cf27abef6036",
strip_prefix = "rules_python-0.25.0",
url = "https://github.com/bazelbuild/rules_python/releases/download/0.25.0/rules_python-0.25.0.tar.gz",
)

maybe(
Expand Down
44 changes: 43 additions & 1 deletion dependency_support/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 Google LLC
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -11,3 +11,45 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@rules_python//python:pip.bzl", "compile_pip_requirements")

compile_pip_requirements(name = "pip_requirements")

genrule(
name = "clean_requirements",
srcs = ["@rules_hdl_pip_deps//:requirements.bzl"],
outs = ["requirements.clean.bzl"],
cmd = " | ".join([
"cat $<",
]) + " >$@",
)

write_file(
name = "gen_update",
out = "update.sh",
content = [
# This depends on bash, would need tweaks for Windows
"#!/usr/bin/env bash",
# Bazel gives us a way to access the source folder!
"cd $BUILD_WORKSPACE_DIRECTORY",
"cp -fv bazel-bin/dependency_support/requirements.clean.bzl dependency_support/requirements.bzl",
],
)

sh_binary(
name = "vendor_requirements",
srcs = ["update.sh"],
data = [":clean_requirements"],
)

# Similarly ensures that the requirements.bzl file is updated
# based on the requirements.txt lockfile.
diff_test(
name = "test_vendored",
failure_message = "Please run: bazel run //dependency_support:vendor_requirements",
file1 = "requirements.bzl",
file2 = ":clean_requirements",
)
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ def org_theopenroadproject():
patch_args = [
"-p1",
],
shallow_since = "1649354925 -0300",
shallow_since = "1659478013 -0700"
)
7 changes: 7 additions & 0 deletions dependency_support/pip_requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dataclasses-json==0.5.7
marshmallow<4.0.0,>=3.3.0
jwt==1.3.1
requests==2.28.2
absl-py==1.4.0
cocotb==1.8.0
klayout==0.28.8
312 changes: 306 additions & 6 deletions dependency_support/pip_requirements.txt

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletions dependency_support/requirements.bzl

Large diffs are not rendered by default.

24 changes: 18 additions & 6 deletions init.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
""" initializes the bazel_rules_hdl workspace """

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
load("@rules_python//python:pip.bzl", "pip_install")
load("@rules_python//python:pip.bzl", "pip_parse")
load("//dependency_support:requirements.bzl", install_pip_deps = "install_deps")
load("//dependency_support/boost:init_boost.bzl", "init_boost")
load("//dependency_support/pybind11:init_pybind11.bzl", "init_pybind11")

Expand All @@ -26,26 +27,37 @@ def init(python_interpreter = None, python_interpreter_target = None):
must call `init` to allow @bazel_rules_hdl to set itself up.
`python_interpreter` and `python_interpreter_target` are passed to
@bazel_rules_hdl's instance of `pip_install`. They can normally be set to
@bazel_rules_hdl's instance of `pip_parse`. They can normally be set to
the default None value, but if the outside workspace has a custom Python
toolchain configured, these must be set, otherwise @bazel_rules_hdl will
not use the right Python toolchain when installing pip dependencies.
If either is set, the outside workspace must also include:
load(
"@rules_hdl_pip_deps//:requirements.bzl",
rules_hdl_install_pip_deps = "install_deps",
)
rules_hdl_install_pip_deps()
Args:
python_interpreter: Path to external Python interpreter to use with
`pip_install`. This can be an absolute path or relative to the host's
`pip_parse`. This can be an absolute path or relative to the host's
`PATH` environment variable.
python_interpreter_target: Bazel target of a Python interpreter to build
to use with `pip_install`. Using `python_interpreter_target` makes it
to use with `pip_parse`. Using `python_interpreter_target` makes it
possible to have a hermetic Python toolchain. `python_interpreter_target`
takes precedence over `python_interpreter` if both are set.
"""
pip_install(
# Used only by the rules that vendor requirements.bzl
pip_parse(
name = "rules_hdl_pip_deps",
requirements = "@rules_hdl//dependency_support:pip_requirements.txt",
requirements_lock = "@rules_hdl//dependency_support:pip_requirements.txt",
python_interpreter = python_interpreter,
python_interpreter_target = python_interpreter_target,
)
if (not python_interpreter) or (python_interpreter_target != "@rules_hdl_cpython//:install/bin/python3"):
install_pip_deps()

init_boost()
init_pybind11()
Expand Down

0 comments on commit 653bd51

Please sign in to comment.