Skip to content
Open
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
2 changes: 1 addition & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ common --incompatible_disallow_empty_glob=False
common --define=SOME_VAR=SOME_VALUE

# Set the default virtualenv to 'default'
common --@pypi//venv=default
common --@pypi//venv=aspect_rules_py

common --incompatible_enable_cc_toolchain_resolution
common --@toolchains_llvm_bootstrapped//config:experimental_stub_libgcc_s
Expand Down
20 changes: 9 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
!third_party/**
**/*.whl
**/__pycache__
**/bazel-*
**/target/
.*.venv/
.DS_Store
.agent*
.gemini*
.bazelrc.user
.idea
.ijwb
.*.venv/
**/__pycache__
.DS_Store
**/target/
**/*.whl
.venv/

node_modules/

!third_party/**

# TODO: enable when it is more stable, maybe Bazel 7.1
MODULE.bazel.lock
node_modules/
4 changes: 2 additions & 2 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ load("@gazelle//:def.bzl", "gazelle")
load("@rules_python//python/pip_install:requirements.bzl", "compile_pip_requirements")

# buildifier: disable=bzl-visibility
load("//uv/private/manifest:defs.bzl", "gazelle_python_manifest")
load("//uv/private/gazelle_manifest:defs.bzl", "gazelle_python_manifest")

# gazelle:exclude internal_python_deps.bzl
# gazelle:exclude internal_deps.bzl
Expand All @@ -14,7 +14,7 @@ gazelle_python_manifest(
name = "gazelle_python_manifest",
hub = "pypi",
venvs = [
"default",
"aspect_rules_py",
],
)

Expand Down
21 changes: 11 additions & 10 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -186,19 +186,20 @@ uv = use_extension("//uv/unstable:extension.bzl", "uv", dev_dependency = IS_RELE
uv.declare_hub(
hub_name = "pypi",
)
uv.declare_venv(
hub_name = "pypi",
venv_name = "default",
)
uv.lockfile(
src = "//:uv.lock",
uv.project(
name = "aspect_rules_py",
default_build_dependencies = [
"build",
"setuptools",
"maturin",
],
hub_name = "pypi",
venv_name = "default",
lock = "//:uv.lock",
pyproject = "//:pyproject.toml",
)
uv.unstable_annotate_requirements(
uv.unstable_annotate_packages(
src = "//:annotations.toml",
hub_name = "pypi",
venv_name = "default",
lock = "//:uv.lock",
)
use_repo(uv, "pypi")

Expand Down
31 changes: 10 additions & 21 deletions docs/uv.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,29 +90,16 @@ uv = use_extension("//uv/unstable:extension.bzl", "uv")
uv.declare_hub(
hub_name = "pypi", # Or whatever you wish
)
uv.declare_venv(
uv.project(
hub_name = "pypi", # Must be a declared hub
venv_name = "default", # Or whatever you wish
)
uv.lockfile(
hub_name = "pypi", # Must be a declared hub
venv_name = "default", # Must be a declared venv
src = "//:uv.lock",
pyproject = "//:pyproject.toml",
lock = "//:uv.lock",
)

uv.declare_venv(
hub_name = "pypi",
venv_name = "vendored_say",
)
uv.lockfile(
hub_name = "pypi",
venv_name = "vendored_say",
src = "//:uv.lock",
)
uv.override_requirement(
hub_name = "pypi",
venv_name = "vendored_say",
requirement = "cowsay",
uv.override_package(
lock = "//:uv.lock",
name = "cowsay",
# version = "", Optional but may be required for disambiguation
target = "//third_party/py/cowsay:cowsay",
)

Expand All @@ -121,10 +108,12 @@ use repository(uv, "pypi")
```

We can configure a default virtualenv by setting the venv configuration flag on our hub as part of the `.bazelrc`.
Each `[dependency-group]` of the `pyproject.toml` is registered as a named venv configuration.
If no dependency groups are listed, an implicit default group with the name of the project itself is created.

```
# .bazelrc
common --@pypi//venv=default
common --@pypi//venv=dummy
```

Individual targets can request different venvs if multiple venvs are configured.
Expand Down
2 changes: 1 addition & 1 deletion e2e/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ common --repo_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
common --repo_env=BAZEL_NO_APPLE_CPP_TOOLCHAIN=1

# Configure a default venv
common --@pypi//venv=say
# common --@pypi//venv=say
8 changes: 0 additions & 8 deletions e2e/BUILD.bazel

This file was deleted.

134 changes: 63 additions & 71 deletions e2e/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,11 @@ bazel_dep(name = "toolchains_llvm_bootstrapped", version = "0.3.1")
bazel_dep(name = "rules_oci", version = "2.2.6")
bazel_dep(name = "rules_rust", version = "0.68.1")

oci = use_extension("@rules_oci//oci:extensions.bzl", "oci")
oci.pull(
name = "ubuntu",
digest = "sha256:c35e29c9450151419d9448b0fd75374fec4fff364a27f176fb458d472dfc9e54",
image = "public.ecr.aws/docker/library/ubuntu",
platforms = [
"linux/arm64/v8",
"linux/amd64",
],
tag = "latest",
)
use_repo(oci, "ubuntu", "ubuntu_linux_amd64", "ubuntu_linux_arm64_v8")

bazel_dep(name = "container_structure_test", version = "1.19.1")
git_override(
module_name = "container_structure_test",
commit = "63ee63e15fae64f00b1c1ace1eb5cc99251b9e02",
remote = "https://github.com/GoogleContainerTools/container-structure-test.git",
)

local_path_override(
module_name = "aspect_rules_py",
path = "..",
)

# FIXME: Can we clean this up now that sdist builds don't use tar
bazel_lib_toolchains = use_extension("@tar.bzl//tar:extensions.bzl", "toolchains", dev_dependency = True)
use_repo(bazel_lib_toolchains, "bsd_tar_toolchains")

python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(
configure_coverage_tool = True,
Expand All @@ -62,36 +38,34 @@ python.toolchain(
python_version = "3.13",
)

# TODO: Swap in our pip
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
hub_name = "pip",
python_version = "3.9",
requirements_lock = "//:requirements.txt",
)
pip.parse(
hub_name = "pip",
python_version = "3.10",
requirements_lock = "//:requirements.txt",
)
pip.parse(
hub_name = "pip",
python_version = "3.11",
requirements_lock = "//:requirements.txt",
)
pip.parse(
hub_name = "pip",
python_version = "3.12",
requirements_lock = "//:requirements.txt",
# For the OCI tests
# {{{
oci = use_extension("@rules_oci//oci:extensions.bzl", "oci")
oci.pull(
name = "ubuntu",
digest = "sha256:c35e29c9450151419d9448b0fd75374fec4fff364a27f176fb458d472dfc9e54",
image = "public.ecr.aws/docker/library/ubuntu",
platforms = [
"linux/arm64/v8",
"linux/amd64",
],
tag = "latest",
)
pip.parse(
hub_name = "pip",
python_version = "3.13",
requirements_lock = "//:requirements.txt",
use_repo(oci, "ubuntu", "ubuntu_linux_amd64", "ubuntu_linux_arm64_v8")

bazel_dep(name = "container_structure_test", version = "1.19.1")
git_override(
module_name = "container_structure_test",
commit = "63ee63e15fae64f00b1c1ace1eb5cc99251b9e02",
remote = "https://github.com/GoogleContainerTools/container-structure-test.git",
)
use_repo(pip, "pip")

bazel_lib_toolchains = use_extension("@tar.bzl//tar:extensions.bzl", "toolchains", dev_dependency = True)
use_repo(bazel_lib_toolchains, "bsd_tar_toolchains")
# }}}

# For cases/cross-repo-610
# {{{
local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository")

local_repository(
Expand All @@ -103,45 +77,63 @@ local_repository(
name = "subrepo_b",
path = "./cases/cross-repo-610/subrepo_b",
)
# }}}

# For cases/repository-rule-deps-299
# {{{
importer = use_extension("//cases/repository-rule-deps-299/rules:import.bzl", "importer")
use_repo(importer, "myrepo")
# }}}

# For cases/uv-deps-650
# {{{
uv = use_extension("@aspect_rules_py//uv/unstable:extension.bzl", "uv")
uv.declare_hub(hub_name = "pypi")
uv.declare_venv(
uv.project(
hub_name = "pypi",
venv_name = "say",
lock = "//cases/uv-deps-650/say:uv.lock",
pyproject = "//cases/uv-deps-650/say:pyproject.toml",
)
uv.lockfile(
src = "//cases/uv-deps-650/say:uv.lock",
hub_name = "pypi",
venv_name = "say",
)
uv.override_requirement(
hub_name = "pypi",
requirement = "cowsay",
uv.override_package(
name = "cowsay",
lock = "//cases/uv-deps-650/say:uv.lock",
# FIXME: Version annotation may be required for disambiguation
target = "//cases/uv-deps-650/third_party/cowsay",
venv_name = "say",
)
uv.declare_venv(
uv.project(
hub_name = "pypi",
venv_name = "airflow",
lock = "//cases/uv-deps-650/airflow:uv.lock",
pyproject = "//cases/uv-deps-650/airflow:pyproject.toml",
)
uv.lockfile(
src = "//cases/uv-deps-650/airflow:uv.lock",
uv.project(
hub_name = "pypi",
venv_name = "airflow",
lock = "//cases/uv-deps-650/crossbuild:uv.lock",
pyproject = "//cases/uv-deps-650/crossbuild:pyproject.toml",
)
uv.declare_venv(
uv.project(
hub_name = "pypi",
venv_name = "psql",
lock = "//cases/uv-deps-650/extras:uv.lock",
pyproject = "//cases/uv-deps-650/extras:pyproject.toml",
)
uv.lockfile(
src = "//cases/uv-deps-650/crossbuild:uv.lock",
# }}}

# For cases/uv-workspace-789
# {{{
uv.project(
hub_name = "pypi",
venv_name = "psql",
lock = "//cases/uv-workspace-789:uv.lock",
pyproject = "//cases/uv-workspace-789:pyproject.toml",
)
uv.override_package(
name = "foo",
lock = "//cases/uv-workspace-789:uv.lock",
target = "//cases/uv-workspace-789/packages/foo",
)
uv.override_package(
name = "pi",
lock = "//cases/uv-workspace-789:uv.lock",
target = "//cases/uv-workspace-789/packages/pi",
)
# }}}

use_repo(uv, "pypi")
3 changes: 2 additions & 1 deletion e2e/cases/cross-repo-610/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ py_venv_test(
".",
],
main = "test.py",
venv = "say",
deps = [
"@pip//cowsay",
"@pypi//cowsay",
"@subrepo_a//:foo",
],
)
1 change: 1 addition & 0 deletions e2e/cases/oci/py_image_layer/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ platform(
py_binary(
name = "my_app_bin",
srcs = ["__main__.py"],
venv = "images",
deps = [
"//cases/oci/py_image_layer/branding",
"@aspect_rules_py//py/tests/internal-deps/adder",
Expand Down
9 changes: 9 additions & 0 deletions e2e/cases/oci/py_image_layer/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[project]
name = "images"
version = "0.0.0"
authors = []
dependencies = [
"colorama",
"setuptools",
"build",
]
Loading