Skip to content
Closed
Show file tree
Hide file tree
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
16 changes: 16 additions & 0 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,22 @@ tasks:
working_directory: examples/build_file_generation
platform: windows

mytorch_ubuntu:
<<: *reusable_build_test_all
name: "examples/mytorch: Ubuntu, bzlmod"
platform: ubuntu2204
working_directory: examples/mytorch
mytorch_osx:
<<: *reusable_build_test_all
name: "examples/mytorch: OSX aarch64, bzlmod"
platform: macos_arm64
working_directory: examples/mytorch
mytorch_windows:
<<: *reusable_build_test_all
name: "examples/mytorch: Windows, bzlmod"
platform: windows
working_directory: examples/mytorch

integration_test_bzlmod_ubuntu_min:
<<: *minimum_supported_version
<<: *reusable_build_test_all
Expand Down
1 change: 1 addition & 0 deletions .bazelrc.deleted_packages
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ common --deleted_packages=examples/bzlmod/whl_mods
common --deleted_packages=examples/multi_python_versions/libs/my_lib
common --deleted_packages=examples/multi_python_versions/requirements
common --deleted_packages=examples/multi_python_versions/tests
common --deleted_packages=examples/mytorch
common --deleted_packages=examples/pip_parse
common --deleted_packages=examples/pip_parse_vendored
common --deleted_packages=examples/pip_repository_annotations
Expand Down
6 changes: 2 additions & 4 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ uv = use_extension("//python/uv:uv.bzl", "uv")
uv.default(
base_url = "https://github.com/astral-sh/uv/releases/download",
manifest_filename = "dist-manifest.json",
version = "0.6.3",
version = "0.9.10",
)
uv.default(
compatible_with = [
Expand Down Expand Up @@ -457,6 +457,4 @@ uv_dev = use_extension(
"uv",
dev_dependency = True,
)
uv_dev.configure(
version = "0.6.2",
)
uv_dev.configure(version = "0.9.10")
16 changes: 16 additions & 0 deletions examples/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,19 @@ lock(
],
python_version = "3.11",
)

lock(
name = "mytorch_requirements",
srcs = ["mytorch/requirements.in"],
out = "mytorch/requirements_lock.txt",
args = [
"--emit-index-url",
"--universal",
# This means that the lowest supported version in the requirements file will
# be 3.12
"--python-version=3.12",
],
# Means that we will pass the available 3.12 interpreter to the locking rule irrespective
# of what we have in rules_python as the default toolchain.
python_version = "3.12",
)
11 changes: 11 additions & 0 deletions examples/mytorch/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
common --enable_bzlmod
common --lockfile_mode=update

coverage --java_runtime_version=remotejdk_11

test --test_output=errors --enable_runfiles

# Windows requires these for multi-python support:
build --enable_runfiles

common --repo_env RULES_PYTHON_ENABLE_PIPSTAR=1
1 change: 1 addition & 0 deletions examples/mytorch/.bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8.x
1 change: 1 addition & 0 deletions examples/mytorch/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bazel-*
1 change: 1 addition & 0 deletions examples/mytorch/.python_version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.14
41 changes: 41 additions & 0 deletions examples/mytorch/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
load("@rules_python//python:py_test.bzl", "py_test")

py_test(
name = "torch_test_py_312",
srcs = ["torch_test.py"],
main = "torch_test.py",
python_version = "3.12",
deps = ["@pip//torch"],
)

py_test(
name = "torch_test_default",
srcs = ["torch_test.py"],
main = "torch_test.py",
deps = ["@pip//torch"],
)

py_test(
name = "torch_test_default_downloader",
srcs = ["torch_test.py"],
main = "torch_test.py",
deps = ["@pip_next//torch"],
)

py_test(
name = "torch_test_py312_downloader",
srcs = ["torch_test.py"],
main = "torch_test.py",
python_version = "3.12",
deps = ["@pip_next//torch"],
)

py_test(
name = "torch_test_downloader_freethreaded",
srcs = ["torch_test.py"],
config_settings = {
"@rules_python//python/config_settings:py_freethreaded": "yes",
},
main = "torch_test.py",
deps = ["@pip_next//torch"],
)
55 changes: 55 additions & 0 deletions examples/mytorch/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
module(
name = "example_torch",
version = "0.0.0",
compatibility_level = 1,
)

bazel_dep(name = "rules_python", version = "0.0.0")
local_path_override(
module_name = "rules_python",
path = "../..",
)

# Initialize the python extension
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.defaults(
# Use python.defaults if you have defined multiple toolchain versions.
python_version = "3.14",
python_version_env = "BAZEL_PYTHON_VERSION",
)
python.toolchain(
configure_coverage_tool = True,
python_version = "3.12",
)
python.toolchain(
configure_coverage_tool = True,
python_version = "3.14",
)

# Add the pip deps
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
hub_name = "pip",
python_version = "3.12",
requirements_lock = "requirements_lock.txt",
)
pip.parse(
hub_name = "pip",
python_version = "3.14",
requirements_lock = "requirements_lock.txt",
)
pip.parse(
envsubst = ["PIP_INDEX_URL"],
experimental_index_url = "${PIP_INDEX_URL:-https://pypi.org/simple}",
hub_name = "pip_next",
python_version = "3.12",
requirements_lock = "requirements_lock.txt",
)
pip.parse(
envsubst = ["PIP_INDEX_URL"],
experimental_index_url = "${PIP_INDEX_URL:-https://pypi.org/simple}",
hub_name = "pip_next",
python_version = "3.14",
requirements_lock = "requirements_lock.txt",
)
use_repo(pip, "pip", "pip_next")
36 changes: 36 additions & 0 deletions examples/mytorch/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# NB: short workspace name is required to workaround PATH length limitation, see
# https://github.com/bazelbuild/bazel/issues/18683#issuecomment-1843857373
workspace(name = "p")

# The following local_path_override is only needed to run this example as part of our CI.
local_repository(
name = "rules_python",
path = "../..",
)

# When not using this example in the rules_python git repo you would load the python
# rules using http_archive(), as documented in the release notes.

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

# We install the rules_python dependencies using the function below.
py_repositories()

python_register_toolchains(
name = "python39",
python_version = "3.9",
)

# Then we need to setup dependencies in order to use py_proto_library
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "com_google_protobuf",
sha256 = "4fc5ff1b2c339fb86cd3a25f0b5311478ab081e65ad258c6789359cd84d421f8",
strip_prefix = "protobuf-26.1",
urls = ["https://github.com/protocolbuffers/protobuf/archive/v26.1.tar.gz"],
)

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()
2 changes: 2 additions & 0 deletions examples/mytorch/requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
torch==2.8.0; python_version < "3.13"
torch==2.9.1; python_version >= "3.13"
Loading