Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,47 @@ http_archive(
url = "https://github.com/google/googletest/archive/refs/tags/v1.17.0.zip",
)


# ---------------------------------------------------------------------------
# rules_python — hermetic Python toolchain + pip dependencies
# ---------------------------------------------------------------------------

http_archive(
name = "rules_python",
sha256 = "4a02240a4a6a8b04077a7e49921949d2e6879d6f047be1e870d222de6709c7d1",
strip_prefix = "rules_python-1.4.1",
url = "https://github.com/bazelbuild/rules_python/releases/download/v1.4.1/rules_python-v1.4.1.tar.gz",
)

load("@rules_python//python:repositories.bzl", "py_repositories")
py_repositories()

# Register a hermetic Python interpreter (3.11 in this example; pick what qsim supports)
load("@rules_python//python:versions.bzl", "MINOR_MAPPING")
load("@rules_python//python:repositories.bzl", "python_register_toolchains")

python_register_toolchains(
name = "python_3_11",
python_version = "3.11",
)

load("@python_3_11//:defs.bzl", "interpreter")

# Parse locked requirements.
# pip_parse needs a lockfile, not a bare requirements.txt.
# We'll generate the lockfile in step 2.
load("@rules_python//python:pip.bzl", "pip_parse")

pip_parse(
name = "pip",
python_interpreter_target = interpreter,
requirements_lock = "//:requirements_lock.txt",
)
Comment on lines +59 to +70

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The repository @python_3_11 is a toolchain repository and does not contain a defs.bzl file or expose an interpreter target. Attempting to load from @python_3_11//:defs.bzl will cause a critical Bazel loading phase error, preventing any Bazel commands from running.

Instead, you should reference the hermetic interpreter target directly using @python_3_11_host//:python as the python_interpreter_target in pip_parse.

# Parse locked requirements.
# pip_parse needs a lockfile, not a bare requirements.txt.
# We'll generate the lockfile in step 2.
load("@rules_python//python:pip.bzl", "pip_parse")

pip_parse(
    name = "pip",
    python_interpreter_target = "@python_3_11_host//:python",
    requirements_lock = "//:requirements_lock.txt",
)


load("@pip//:requirements.bzl", "install_deps")
install_deps()


# Required for testing compatibility with TF Quantum:
# https://github.com/tensorflow/quantum
http_archive(
Expand Down
Loading