Skip to content

Commit

Permalink
fix: allow symlink collision error to be downgraded
Browse files Browse the repository at this point in the history
  • Loading branch information
mattem committed Jul 18, 2024
1 parent 9730638 commit 364b3b8
Show file tree
Hide file tree
Showing 21 changed files with 435 additions and 361 deletions.
422 changes: 166 additions & 256 deletions Cargo.Bazel.lock

Large diffs are not rendered by default.

86 changes: 45 additions & 41 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ members = [
"py/tools/unpack_bin",
]


[workspace.package]
version = "0.1.0"
categories = ["development-tools"]
Expand All @@ -17,5 +16,8 @@ edition = "2021"
readme = "README.md"
rust-version = "1.74.1"

[workspace.dependencies]
miette = { version = "7.2", features = ["fancy"] }

[profile.release]
strip = true
8 changes: 6 additions & 2 deletions docs/rules.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion examples/pytest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ py_test(
],
imports = ["../.."],
main = ":__test__.py",
package_collisions = "warning",
deps = [
":__test__",
"@pypi_pytest//:pkg",
"@pypi_ftfy//:pkg",
"@pypi_neptune//:pkg",
"@pypi_pytest//:pkg",
],
)
4 changes: 4 additions & 0 deletions py/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ def _py_binary_or_test(name, rule, srcs, main, deps = [], resolutions = {}, **kw
**propagate_common_rule_attributes(kwargs)
)

package_collisions = kwargs.pop("package_collisions", None)

rule(
name = name,
srcs = srcs,
main = main_target,
deps = deps,
resolutions = resolutions,
package_collisions = package_collisions,
**kwargs
)

Expand All @@ -44,6 +47,7 @@ def _py_binary_or_test(name, rule, srcs, main, deps = [], resolutions = {}, **kw
deps = deps,
imports = kwargs.get("imports"),
resolutions = resolutions,
package_collisions = package_collisions,
tags = ["manual"],
testonly = kwargs.get("testonly", False),
)
Expand Down
20 changes: 16 additions & 4 deletions py/private/py_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def _py_binary_rule_impl(ctx):
"{{BASH_RLOCATION_FN}}": BASH_RLOCATION_FUNCTION,
"{{INTERPRETER_FLAGS}}": " ".join(py_toolchain.flags),
"{{VENV_TOOL}}": to_rlocation_path(ctx, venv_toolchain.bin),
"{{ARG_COLLISION_STRATEGY}}": ctx.attr.package_collisions,
"{{ARG_PYTHON}}": to_rlocation_path(ctx, py_toolchain.python) if py_toolchain.runfiles_interpreter else py_toolchain.python.path,
"{{ARG_VENV_NAME}}": ".{}.venv".format(ctx.attr.name),
"{{ARG_VENV_PYTHON_VERSION}}": "{}.{}.{}".format(
Expand Down Expand Up @@ -172,7 +173,18 @@ python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(python_version = "3.8.12", is_default = False)
python.toolchain(python_version = "3.9", is_default = True)
```
"""
""",
),
"package_collisions": attr.string(
doc = """The action that should be taken when a symlink collision is encountered when creating the venv.
A collision can occour when multiple packages providing the same file are installed into the venv. The possible values are:
* "error": When conflicting symlinks are found, an error is reported and venv creation halts.
* "warning": When conflicting symlinks are found, an warning is reported, however venv creation continues.
* "ignore": When conflicting symlinks are found, no message is reported and venv creation continues.
""",
default = "error",
values = ["error", "warning", "ignore"],
),
"_run_tmpl": attr.label(
allow_single_file = True,
Expand Down Expand Up @@ -211,7 +223,7 @@ py_base = struct(
PY_TOOLCHAIN,
VENV_TOOLCHAIN,
],
cfg = _python_version_transition
cfg = _python_version_transition,
)

py_binary = rule(
Expand All @@ -220,7 +232,7 @@ py_binary = rule(
attrs = py_base.attrs,
toolchains = py_base.toolchains,
executable = True,
cfg = py_base.cfg
cfg = py_base.cfg,
)

py_test = rule(
Expand All @@ -229,5 +241,5 @@ py_test = rule(
attrs = py_base.attrs,
toolchains = py_base.toolchains,
test = True,
cfg = py_base.cfg
cfg = py_base.cfg,
)
12 changes: 12 additions & 0 deletions py/private/py_venv.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def _py_venv_rule_imp(ctx):
"{{INTERPRETER_FLAGS}}": " ".join(py_toolchain.flags),
"{{VENV_TOOL}}": to_rlocation_path(ctx, venv_toolchain.bin),
"{{ARG_PYTHON}}": to_rlocation_path(ctx, py_toolchain.python) if py_toolchain.runfiles_interpreter else py_toolchain.python.path,
"{{ARG_COLLISION_STRATEGY}}": ctx.attr.package_collisions,
"{{ARG_VENV_LOCATION}}": paths.join(ctx.attr.location, ctx.attr.venv_name),
"{{ARG_VENV_PYTHON_VERSION}}": "{}.{}.{}".format(
py_toolchain.interpreter_version_info.major,
Expand Down Expand Up @@ -108,6 +109,17 @@ _py_venv = rule(
"resolutions": attr.label_keyed_string_dict(
doc = "FIXME",
),
"package_collisions": attr.string(
doc = """The action that should be taken when a symlink collision is encountered when creating the venv.
A collision can occour when multiple packages providing the same file are installed into the venv. The possible values are:
* "error": When conflicting symlinks are found, an error is reported and venv creation halts.
* "warning": When conflicting symlinks are found, an warning is reported, however venv creation continues.
* "ignore": When conflicting symlinks are found, no message is reported and venv creation continues.
""",
default = "error",
values = ["error", "warning", "ignore"],
),
"_venv_tmpl": attr.label(
allow_single_file = True,
default = "//py/private:venv.tmpl.sh",
Expand Down
3 changes: 2 additions & 1 deletion py/private/run.tmpl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export VIRTUAL_ENV
--location "${VIRTUAL_ENV}" \
--python "$(python_location)" \
--python-version "{{ARG_VENV_PYTHON_VERSION}}" \
--pth-file "$(rlocation {{ARG_PTH_FILE}})"
--pth-file "$(rlocation {{ARG_PTH_FILE}})" \
--collision-strategy "{{ARG_COLLISION_STRATEGY}}"

PATH="${VIRTUAL_ENV}/bin:${PATH}"
export PATH
Expand Down
3 changes: 2 additions & 1 deletion py/private/venv.tmpl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ VIRTUAL_ENV="$(alocation "${VENV_ROOT}/{{ARG_VENV_LOCATION}}")"
--python "$(alocation $(rlocation {{ARG_PYTHON}}))" \
--python-version "{{ARG_VENV_PYTHON_VERSION}}" \
--pth-file "$(rlocation {{ARG_PTH_FILE}})" \
--pth-entry-prefix "${RUNFILES_DIR}"
--pth-entry-prefix "${RUNFILES_DIR}" \
--collision-strategy "{{ARG_COLLISION_STRATEGY}}"
1 change: 1 addition & 0 deletions py/tests/virtual/django/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ py_library(
py_binary(
name = "manage",
srcs = ["proj/manage.py"],
package_collisions = "warning",
# Resolve django to the "standard" one from our requirements.txt
resolutions = django_resolutions,
deps = [
Expand Down
3 changes: 2 additions & 1 deletion py/tests/virtual/django/requirements.in
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
django==4.2.7
django==4.2.7
PyQt6==6.6.1
Loading

0 comments on commit 364b3b8

Please sign in to comment.