Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: (WIP) Add pypi_install() rule #1728

Draft
wants to merge 114 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
10af2a3
Get started on new pypi_install repo rule
philsc Jun 10, 2023
cf28cb6
Actually generate an installation report
philsc Jun 14, 2023
5bb472f
skeleton pypi_install
philsc Jun 14, 2023
f5b53dd
Generate crude intermediate format
philsc Jun 14, 2023
e1026c9
Generate http_file calls for all files
philsc Jun 14, 2023
b6a7f0c
Generate an intermediate representation
philsc Jul 3, 2023
f9a9fa2
Parse the report in user space
philsc Jul 3, 2023
327ba26
Combine the intermediate files
philsc Jul 3, 2023
050d338
Start generating aliases
philsc Jul 3, 2023
1f43e70
Aliases are working
philsc Jul 4, 2023
97718eb
Wheel are now extracted
philsc Jul 4, 2023
99e4924
Add support for deps
philsc Jul 10, 2023
39e2a7c
regenerate intermediate file
philsc Jul 10, 2023
cd2325e
fix issues with version
philsc Jul 10, 2023
317be76
Merge remote-tracking branch 'origin/main' into HEAD
philsc Jul 30, 2023
9074c6c
Resolve merge conflict
philsc Jul 30, 2023
8fcf5cc
Import some wheels to get transitive deps with extras working.
philsc Jul 30, 2023
4dfd766
Make dependencies' deps work properly
philsc Jul 30, 2023
b0c9d33
Add a basic test
philsc Jul 30, 2023
9438672
fix test
philsc Aug 6, 2023
5639057
Merge remote-tracking branch 'origin/main' into HEAD
philsc Aug 6, 2023
93ac73c
fix distribution for integration tests.
philsc Aug 6, 2023
09e030f
clean up a bit
philsc Aug 6, 2023
14150de
clean up more
philsc Aug 6, 2023
9c72809
rename file
philsc Aug 7, 2023
98c0416
clean up more
philsc Aug 7, 2023
b346789
more cleanup
philsc Aug 7, 2023
356c067
Re-organize the logic a bit
philsc Aug 20, 2023
77a08d9
Merge remote-tracking branch 'origin/main' into HEAD
philsc Aug 20, 2023
614b434
Start working on patching support
philsc Aug 20, 2023
34412f0
add missing files
philsc Aug 20, 2023
c58db28
Start moving patch support into user space
philsc Aug 20, 2023
34ff1c8
Actually pass patch args through
philsc Aug 24, 2023
fd3f40a
Merge remote-tracking branch 'origin/main' into HEAD
philsc Aug 24, 2023
00e83b4
Switch to BUILD.bazel
philsc Aug 24, 2023
831559e
Fix deps
philsc Aug 27, 2023
35bbf8e
make patches actually work.
philsc Aug 27, 2023
b8536ba
Merge remote-tracking branch 'origin/main' into HEAD
philsc Aug 27, 2023
d77b997
Make patches work with `patch_dir`
philsc Aug 27, 2023
6d85b4f
fix a couple of things.
philsc Sep 4, 2023
4dd5f28
Merge remote-tracking branch 'origin/main' into HEAD
philsc Sep 4, 2023
32cc710
Merge remote-tracking branch 'origin/main' into HEAD
philsc Sep 8, 2023
36d0b85
Make wrapped_py_wheel_library work for multiple configs
philsc Sep 8, 2023
4b1c56d
maybe switch to transitive dep accumulation?
philsc Sep 8, 2023
d40c04b
Fix circular dependencies maybe?
philsc Sep 8, 2023
d2158f2
Introduce circular dependency
philsc Sep 13, 2023
f5e73de
Give up on finding a package with a circular dependency for now.
philsc Sep 13, 2023
1890412
Merge remote-tracking branch 'origin/main' into HEAD
philsc Sep 13, 2023
04776dd
normalize name
philsc Sep 13, 2023
a75d69e
clean up
philsc Sep 13, 2023
8cb7e29
add comment on circular dependencies.
philsc Sep 13, 2023
bdfd1d0
Rename `pycross_wheel_library` to `py_wheel_library` and make it work
philsc Sep 13, 2023
bc3dcb0
Merge remote-tracking branch 'origin/main' into HEAD
philsc Sep 25, 2023
dd2f722
Move test to //tests/pycross
philsc Sep 25, 2023
e8386f1
fix one more call site
philsc Sep 25, 2023
a066006
remove one more superfluous reference
philsc Sep 25, 2023
ea9f5be
Suppress buildifier warning
philsc Sep 25, 2023
b4e94d3
Merge remote-tracking branch 'philsc/make-py-wheel-library-work' into…
philsc Sep 25, 2023
e1775c3
port changes to vendored version on main.
philsc Sep 25, 2023
35c80ac
run buildifier.
philsc Sep 25, 2023
c451b9f
switch to third_party version of pycross
philsc Sep 25, 2023
37ed85b
add comment
philsc Sep 25, 2023
dd84feb
pycross: Add patching support to py_wheel_library
philsc Sep 28, 2023
bb46f2e
Compile GNU patch
philsc Oct 10, 2023
91c0a30
Make it work for Windows maybe?
philsc Oct 19, 2023
7f4b344
add missing file
philsc Oct 19, 2023
c456eff
clean up a bit
philsc Oct 19, 2023
88d679e
fix buildifier warning
philsc Oct 19, 2023
8fb9c6d
clean up deps
philsc Oct 19, 2023
0a6b206
Merge remote-tracking branch 'origin/main' into HEAD
philsc Oct 19, 2023
b8ef501
fix merge conflicts
philsc Oct 19, 2023
2b0cdaf
Clean up some more.
philsc Oct 19, 2023
7855521
buildifier
philsc Oct 19, 2023
03d5b57
black
philsc Oct 19, 2023
6bd11b4
Merge remote-tracking branch 'origin/main' into HEAD
philsc Nov 1, 2023
1d4f48a
Go back to using host patch
philsc Nov 1, 2023
13d59d3
buildifier
philsc Nov 1, 2023
50b4739
black
philsc Nov 1, 2023
7619780
fail if user doesn't provide a patch tool.
philsc Nov 1, 2023
a4c5c69
add missing file
philsc Nov 1, 2023
322e295
fix typo
philsc Nov 3, 2023
651ffff
Merge remote-tracking branch 'origin/main' into HEAD
philsc Nov 3, 2023
a099bda
import pypiserver
philsc Nov 3, 2023
b2b9fd7
Run compile_pip_requirements against a pypiserver
philsc Nov 3, 2023
5b1e539
minor edits
philsc Dec 3, 2023
93d3edc
Split test cases to avoid unix_patcher.py
philsc Dec 3, 2023
7353010
Merge remote-tracking branch 'origin/main' into HEAD
philsc Dec 3, 2023
05f47a6
fix arg type
philsc Dec 3, 2023
a4a2c71
add warning about non-hermeticity.
philsc Dec 3, 2023
97c0378
buildifier
philsc Dec 3, 2023
3997242
Merge remote-tracking branch 'philsc/add-patch-support-to-py-wheel-li…
philsc Dec 4, 2023
acc5112
fix merge conflict
philsc Dec 4, 2023
915aadc
Merge remote-tracking branch 'philsc/pypiserver-test' into HEAD
philsc Dec 4, 2023
6926142
start exposing some custom wheels
philsc Dec 4, 2023
d52e57b
Switch over to use pypiserver more.
philsc Dec 5, 2023
a8c12de
Fix a few more bugs
philsc Dec 5, 2023
4ac70e6
Add genquery tests for circular dependencies
philsc Dec 5, 2023
8adf080
Merge remote-tracking branch 'upstream/main' into HEAD
philsc Jan 29, 2024
991e835
delete some stuff I'm not working on anymore
philsc Jan 29, 2024
92aae04
re-enable integration test
philsc Jan 29, 2024
bbc79ec
fix up a few things.
philsc Jan 29, 2024
9dc8623
Get //examples:pypi_install_bazel_self working
philsc Jan 29, 2024
e29aba2
Tried and failed to adapt test based on bazel version.
philsc Jan 29, 2024
ad75959
Generate an aarch64 intermediate file
philsc Jan 29, 2024
7144829
add new package, update isn't working yet.
philsc Jan 29, 2024
2bda97f
Get multi-arch intermediate file update working.
philsc Jan 29, 2024
6c818b4
get the basic example working.
philsc Jan 29, 2024
d41f491
disable bzlmod for now
philsc Jan 29, 2024
33cdcb3
Add a better test for arch-dependent package
philsc Feb 11, 2024
45247be
Merge remote-tracking branch 'origin/main' into HEAD
philsc Feb 11, 2024
fd477fc
Try it out with multiple Python versions.
philsc Feb 12, 2024
93f9df3
Clean up naming.
philsc Feb 12, 2024
4bd6443
fix up tests
philsc Feb 12, 2024
1582943
add version-specific package
philsc Feb 12, 2024
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
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ examples/multi_python_versions/bazel-multi_python_versions
examples/pip_parse/bazel-pip_parse
examples/pip_parse_vendored/bazel-pip_parse_vendored
examples/py_proto_library/bazel-py_proto_library
examples/pypi_install/bazel-pypi_install
tests/integration/compile_pip_requirements/bazel-compile_pip_requirements
tests/integration/ignore_root_user_error/bazel-ignore_root_user_error
tests/integration/pip_repository_entry_points/bazel-pip_repository_entry_points
4 changes: 2 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# (Note, we cannot use `common --deleted_packages` because the bazel version command doesn't support it)
# To update these lines, execute
# `bazel run @rules_bazel_integration_test//tools:update_deleted_packages`
build --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/dupe_requirements,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/pythonconfig,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/pip_repository_entry_points,tests/integration/py_cc_toolchain_registered
query --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/dupe_requirements,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/pythonconfig,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/pip_repository_entry_points,tests/integration/py_cc_toolchain_registered
build --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/dupe_requirements,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/pypi_install,examples/pypi_install/third_party,examples/pypi_install/wheels,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/pythonconfig,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/pip_repository_entry_points,tests/integration/py_cc_toolchain_registered
query --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/dupe_requirements,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/pypi_install,examples/pypi_install/third_party,examples/pypi_install/wheels,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/pythonconfig,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/pip_repository_entry_points,tests/integration/py_cc_toolchain_registered

test --test_output=errors

Expand Down
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ filegroup(
"version.bzl",
"//python:distribution",
"//python/pip_install:distribution",
"//third_party/rules_pycross/pycross/private:distribution",
"//tools:distribution",
"@rules_python_gazelle_plugin//:distribution",
],
Expand Down
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use_repo(
"pypi__pep517",
"pypi__pip",
"pypi__pip_tools",
"pypi__pypiserver",
"pypi__pyproject_hooks",
"pypi__setuptools",
"pypi__tomli",
Expand Down
7 changes: 7 additions & 0 deletions examples/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("//tests/integration:integration_test.bzl", "rules_python_integration_test")

licenses(["notice"]) # Apache 2.0

rules_python_integration_test(
name = "pypi_install",
bzlmod = False,
)
8 changes: 8 additions & 0 deletions examples/pypi_install/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# https://docs.bazel.build/versions/main/best-practices.html#using-the-bazelrc-file
try-import %workspace%/user.bazelrc
test --test_output=errors

common --noenable_bzlmod

build:py310 --@rules_python//python/config_settings:python_version=3.10
build:py311 --@rules_python//python/config_settings:python_version=3.11
4 changes: 4 additions & 0 deletions examples/pypi_install/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# git ignore patterns

/bazel-*
user.bazelrc
122 changes: 122 additions & 0 deletions examples/pypi_install/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
load("@rules_python//python:defs.bzl", "py_binary", "py_test")
load("@rules_python//python:pip.bzl", "compile_pip_requirements")
load("@bazel_skylib//lib:versions.bzl", "versions")
load("@bazel_skylib//lib:selects.bzl", "selects")
load("@bazel_skylib//rules:diff_test.bzl", "diff_test")

py_binary(
name = "main",
srcs = ["main.py"],
deps = [
"@pypi//pkg_a",
],
)

py_test(
name = "test",
srcs = ["test.py"],
deps = [":main"],
)

# This rule adds a convenient way to update the requirements file.
compile_pip_requirements(
name = "requirements",
intermediate_file = {
"@//:py310_linux_aarch64": "intermediate_file_py310_linux_aarch64.json",
"@//:py310_linux_x86_64": "intermediate_file_py310_linux_x86_64.json",
"@//:py311_linux_aarch64": "intermediate_file_py311_linux_aarch64.json",
"@//:py311_linux_x86_64": "intermediate_file_py311_linux_x86_64.json",
},
# That binary will let users modify the intermediate file. Then they can:
# - Inject dependencies.
# - Remove dependencies.
# - Drop whole packages (is there such a use case?).
# - Add patches.
# - Override/create aliases (support needed).
intermediate_file_patcher = "//:intermediate_file_patcher",
requirements_in = "requirements.in",
# Pass in a select-like value that lets the macro decide what to do with
# the file. Having these values as dictionaries allows us to do some
# validation before the underlying targets get instantiated.
requirements_txt = {
"@//:py310_linux_aarch64": "requirements_lock_py310_linux_aarch64.txt",
"@//:py310_linux_x86_64": "requirements_lock_py310_linux_x86_64.txt",
"@//:py311_linux_aarch64": "requirements_lock_py311_linux_aarch64.txt",
"@//:py311_linux_x86_64": "requirements_lock_py311_linux_x86_64.txt",
},
extra_args = [
# Since we may frequently tweak the wheels for development, we can't
# really rely on consistent hashes.
"--no-reuse-hashes",
# Point at the server run via:
# bazel run //wheels:pypiserver_runner
"--index-url",
"http://localhost:8989/simple/",
],
)

py_binary(
name = "intermediate_file_patcher",
srcs = ["intermediate_file_patcher.py"],
)

config_setting(
name = "linux_aarch64",
constraint_values = [
"@platforms//cpu:aarch64",
"@platforms//os:linux",
],
)

config_setting(
name = "linux_x86_64",
constraint_values = [
"@platforms//cpu:x86_64",
"@platforms//os:linux",
],
)

[selects.config_setting_group(
name = "py{}_{}".format(py_version.replace(".", ""), platform),
match_all = [
"@rules_python//python/config_settings:is_python_{}".format(py_version),
":{}".format(platform),
],
) for py_version in (
"3.10",
"3.11",
) for platform in (
"linux_aarch64",
"linux_x86_64",
)]

genquery(
name = "pkg_a_deps",
expression = """filter(@pypi//, kind(".* rule", deps(@pypi//pkg_a)))""",
opts = ["--notool_deps"],
scope = ["@pypi//pkg_a"],
)

# TODO(phil): This doesn't work. Find a way to make this work.
#IS_BAZEL_6 = versions.parse(versions.get())[0] < 7

diff_test(
name = "pkg_a_deps_test",
file1 = ":pkg_a_deps",
#file2 = "pkg_a_deps_bazel_6.txt" if IS_BAZEL_6 else "pkg_a_deps.txt",
file2 = "pkg_a_deps.txt",
)

genquery(
name = "pkg_d_deps",
expression = """filter(@pypi//, kind(".* rule", deps(@pypi//pkg_d)))""",
opts = ["--notool_deps"],
scope = ["@pypi//pkg_d"],
)

diff_test(
name = "pkg_d_deps_test",
file1 = ":pkg_d_deps",
#file2 = "pkg_d_deps_bazel_6.txt" if IS_BAZEL_6 else "pkg_d_deps.txt",
file2 = "pkg_d_deps.txt",
)
6 changes: 6 additions & 0 deletions examples/pypi_install/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
###############################################################################
# Bazel now uses Bzlmod by default to manage external dependencies.
# Please consider migrating your external dependencies from WORKSPACE to MODULE.bazel.
#
# For more details, please check https://github.com/bazelbuild/bazel/issues/18958
###############################################################################
49 changes: 49 additions & 0 deletions examples/pypi_install/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
workspace(name = "rules_python_pypi_install_example")

local_repository(
name = "rules_python",
path = "../..",
)

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

py_repositories()

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

pip_install_dependencies()

python_register_multi_toolchains(
name = "python",
default_version = "3.10",
python_versions = [
"3.10",
"3.11",
],
)

load("@rules_python//python:pypi.bzl", "pypi_install")

pypi_install(
name = "pypi_install",
# Use fully resolved labels so that they're not accidentally interpreted as
# repo-relative.
# TODO(phil): Add test to make sure that the config settings are mutually
# exclusive.
pip_installation_report = [
"//:intermediate_file_py310_linux_x86_64.json",
"//:intermediate_file_py310_linux_aarch64.json",
"//:intermediate_file_py311_linux_x86_64.json",
"//:intermediate_file_py311_linux_aarch64.json",
],
)

load("@pypi_install//:packages.bzl", "load_pypi_packages")

load_pypi_packages(
name = "pypi",
)

register_toolchains(
"//cc:linux_toolchain_definition",
)
29 changes: 29 additions & 0 deletions examples/pypi_install/cc/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
load(":fake_cc_toolchain_config.bzl", "fake_cc_toolchain_config")

filegroup(name = "empty")

fake_cc_toolchain_config(
name = "linux_toolchain_config",
target_cpu = "k8",
toolchain_identifier = "linux-toolchain",
)

cc_toolchain(
name = "linux_toolchain",
all_files = ":empty",
compiler_files = ":empty",
dwp_files = ":empty",
linker_files = ":empty",
objcopy_files = ":empty",
strip_files = ":empty",
supports_param_files = 0,
toolchain_config = ":linux_toolchain_config",
toolchain_identifier = "linux-toolchain",
)

toolchain(
name = "linux_toolchain_definition",
target_compatible_with = ["@platforms//os:linux"],
toolchain = ":linux_toolchain",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)
23 changes: 23 additions & 0 deletions examples/pypi_install/cc/fake_cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""Fake for providing CcToolchainConfigInfo."""

def _impl(ctx):
return cc_common.create_cc_toolchain_config_info(
ctx = ctx,
toolchain_identifier = ctx.attr.toolchain_identifier,
host_system_name = "local",
target_system_name = "local",
target_cpu = ctx.attr.target_cpu,
target_libc = "unknown",
compiler = "clang",
abi_version = "unknown",
abi_libc_version = "unknown",
)

fake_cc_toolchain_config = rule(
implementation = _impl,
attrs = {
"target_cpu": attr.string(),
"toolchain_identifier": attr.string(),
},
provides = [CcToolchainConfigInfo],
)
35 changes: 35 additions & 0 deletions examples/pypi_install/intermediate_file_patcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import json
import sys
from pathlib import Path

UPDATES = {
"requests": {
"patches": [
"@//third_party:requests/0001-Add-a-dummy-patch-for-requests.patch",
],
"patch_args": [
"-p1",
],
},
}

def patch_intermediate_file(content):
for package, info_per_config in content.items():
for config, info in info_per_config.items():
if package in UPDATES:
info.update(UPDATES[package])

def main(argv):
intermediate_file = Path(argv[1])

with intermediate_file.open("r") as file:
content = json.load(file)

patch_intermediate_file(content)

with intermediate_file.open("w") as file:
json.dump(content, file, indent=4)
file.write("\n")

if __name__ == "__main__":
sys.exit(main(sys.argv))
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"pkg-a": {
"@//:py310_linux_aarch64": {
"url": "http://localhost:8989/packages/pkg_a-1.0-py3-none-any.whl",
"sha256": "a0d9f8c13927e9a2b11260c7add67c827921d9727242247f31c605704bff5ff4",
"deps": [
"pkg-b"
]
}
},
"pkg-b": {
"@//:py310_linux_aarch64": {
"url": "http://localhost:8989/packages/pkg_b-1.1-py3-none-any.whl",
"sha256": "05cd20f93e030fcb81b83190bb9926590954d94a3552f0f0567232743e9e8c23",
"deps": [
"pkg-c",
"pkg-d",
"pkg-e"
]
}
},
"pkg-c": {
"@//:py310_linux_aarch64": {
"url": "http://localhost:8989/packages/pkg_c-2.0-py3-none-any.whl",
"sha256": "1fd7e8c2c3a8bfb045b365f4c805d40986f1b7a164537458164d82ffc6aed636",
"deps": []
}
},
"pkg-d": {
"@//:py310_linux_aarch64": {
"url": "http://localhost:8989/packages/pkg_d-3.0-py3-none-any.whl",
"sha256": "de78d858ac71ffe1a5f9c7ddc58a8b26938e62f6583f1143fde0957389d3986f",
"deps": [
"pkg-b"
]
}
},
"pkg-e": {
"@//:py310_linux_aarch64": {
"url": "http://localhost:8989/packages/pkg_e-4.0-py3-none-any.whl",
"sha256": "9d2fcec39f4f7e8b4e0d0d9bc8f1b06ee582af6dea8db258d031aa64089ca363",
"deps": []
}
}
}
Loading
Loading