Skip to content

Commit 2d5d753

Browse files
author
Tim 'mithro' Ansell
authored
Merge pull request #197 from ericastor/update_rules_python
Update `rules_python`, and vendor requirements.bzl
2 parents f5ea82c + 03f9804 commit 2d5d753

File tree

7 files changed

+433
-16
lines changed

7 files changed

+433
-16
lines changed

WORKSPACE

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ llvm_toolchain(
9393
maybe(
9494
http_archive,
9595
name = "rules_python",
96-
sha256 = "b6d46438523a3ec0f3cead544190ee13223a52f6a6765a29eae7b7cc24cc83a0",
97-
url = "https://github.com/bazelbuild/rules_python/releases/download/0.1.0/rules_python-0.1.0.tar.gz",
96+
sha256 = "5868e73107a8e85d8f323806e60cad7283f34b32163ea6ff1020cf27abef6036",
97+
strip_prefix = "rules_python-0.25.0",
98+
url = "https://github.com/bazelbuild/rules_python/releases/download/0.25.0/rules_python-0.25.0.tar.gz",
9899
)
99100

100101
maybe(

dependency_support/BUILD.bazel

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2020 Google LLC
1+
# Copyright 2023 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -11,3 +11,48 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
15+
load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
16+
load("@bazel_skylib//rules:write_file.bzl", "write_file")
17+
load("@rules_python//python:pip.bzl", "compile_pip_requirements")
18+
19+
compile_pip_requirements(name = "pip_requirements")
20+
21+
genrule(
22+
name = "clean_requirements",
23+
srcs = ["@rules_hdl_pip_deps//:requirements.bzl"],
24+
outs = ["requirements.clean.bzl"],
25+
cmd = " | ".join([
26+
"cat $<",
27+
# Replace the bazel 6.0.0 specific comment with something that bazel 5.4.0 would produce.
28+
# This enables this example to be run as a test under bazel 5.4.0.
29+
"""sed -e 's#@rules_hdl//#@//#'""",
30+
]) + " >$@",
31+
)
32+
33+
write_file(
34+
name = "gen_update",
35+
out = "update.sh",
36+
content = [
37+
# This depends on bash, would need tweaks for Windows
38+
"#!/usr/bin/env bash",
39+
# Bazel gives us a way to access the source folder!
40+
"cd $BUILD_WORKSPACE_DIRECTORY",
41+
"cp -fv bazel-bin/dependency_support/requirements.clean.bzl dependency_support/requirements.bzl",
42+
],
43+
)
44+
45+
sh_binary(
46+
name = "vendor_requirements",
47+
srcs = ["update.sh"],
48+
data = [":clean_requirements"],
49+
)
50+
51+
# Similarly ensures that the requirements.bzl file is updated
52+
# based on the requirements.txt lockfile.
53+
diff_test(
54+
name = "test_vendored",
55+
failure_message = "Please run: bazel run //dependency_support:vendor_requirements",
56+
file1 = "requirements.bzl",
57+
file2 = ":clean_requirements",
58+
)

dependency_support/org_theopenroadproject/org_theopenroadproject.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ def org_theopenroadproject():
3131
patch_args = [
3232
"-p1",
3333
],
34-
shallow_since = "1649354925 -0300",
34+
shallow_since = "1659478013 -0700"
3535
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
dataclasses-json==0.5.7
2+
jwt==1.3.1
3+
requests==2.28.2
4+
absl-py==1.4.0
5+
cocotb==1.8.0
6+
klayout==0.28.8

dependency_support/pip_requirements.txt

Lines changed: 305 additions & 6 deletions
Large diffs are not rendered by default.

dependency_support/requirements.bzl

Lines changed: 54 additions & 0 deletions
Large diffs are not rendered by default.

init.bzl

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
""" initializes the bazel_rules_hdl workspace """
1616

1717
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
18-
load("@rules_python//python:pip.bzl", "pip_install")
18+
load("@rules_python//python:pip.bzl", "pip_parse")
19+
load("//dependency_support:requirements.bzl", install_pip_deps = "install_deps")
1920
load("//dependency_support/boost:init_boost.bzl", "init_boost")
2021
load("//dependency_support/pybind11:init_pybind11.bzl", "init_pybind11")
2122

@@ -26,26 +27,37 @@ def init(python_interpreter = None, python_interpreter_target = None):
2627
must call `init` to allow @bazel_rules_hdl to set itself up.
2728
2829
`python_interpreter` and `python_interpreter_target` are passed to
29-
@bazel_rules_hdl's instance of `pip_install`. They can normally be set to
30+
@bazel_rules_hdl's instance of `pip_parse`. They can normally be set to
3031
the default None value, but if the outside workspace has a custom Python
3132
toolchain configured, these must be set, otherwise @bazel_rules_hdl will
3233
not use the right Python toolchain when installing pip dependencies.
3334
35+
If either is set, the outside workspace must also include:
36+
37+
load(
38+
"@rules_hdl_pip_deps//:requirements.bzl",
39+
rules_hdl_install_pip_deps = "install_deps",
40+
)
41+
rules_hdl_install_pip_deps()
42+
3443
Args:
3544
python_interpreter: Path to external Python interpreter to use with
36-
`pip_install`. This can be an absolute path or relative to the host's
45+
`pip_parse`. This can be an absolute path or relative to the host's
3746
`PATH` environment variable.
3847
python_interpreter_target: Bazel target of a Python interpreter to build
39-
to use with `pip_install`. Using `python_interpreter_target` makes it
48+
to use with `pip_parse`. Using `python_interpreter_target` makes it
4049
possible to have a hermetic Python toolchain. `python_interpreter_target`
4150
takes precedence over `python_interpreter` if both are set.
4251
"""
43-
pip_install(
52+
# Used only by the rules that vendor requirements.bzl
53+
pip_parse(
4454
name = "rules_hdl_pip_deps",
45-
requirements = "@rules_hdl//dependency_support:pip_requirements.txt",
55+
requirements_lock = "@rules_hdl//dependency_support:pip_requirements.txt",
4656
python_interpreter = python_interpreter,
4757
python_interpreter_target = python_interpreter_target,
4858
)
59+
if (not python_interpreter) or (python_interpreter_target != "@rules_hdl_cpython//:install/bin/python3"):
60+
install_pip_deps()
4961

5062
init_boost()
5163
init_pybind11()

0 commit comments

Comments
 (0)