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
11 changes: 11 additions & 0 deletions docs/config_settings.md
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Just FYI, I wrote this doc by hand, it's not generated 😅 I couldn't figure out a way to use stardoc to generate docs for a Bazel flag. LMK if there's a preferred way to generate this doc.

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

2 changes: 1 addition & 1 deletion docs/rules.md

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

7 changes: 7 additions & 0 deletions pycross/config_settings/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")

bool_flag(
name = "default_enable_implicit_namespace_packages",
build_setting_default = False,
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions pycross/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ bzl_library(
deps = [
":providers",
"@bazel_skylib//lib:paths",
"@bazel_skylib//rules:common_settings",
"@rules_python//python:py_info_bzl",
],
)
Expand Down
4 changes: 3 additions & 1 deletion pycross/private/tools/wheel_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ def main(args: Any) -> None:
finally:
shutil.rmtree(link_dir, ignore_errors=True)

setup_namespace_pkg_compatibility(lib_dir)
if not args.enable_implicit_namespace_pkgs:
setup_namespace_pkg_compatibility(lib_dir)

apply_patches(lib_dir, args.patches)


Expand Down
16 changes: 12 additions & 4 deletions pycross/private/wheel_library.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Implementation of the pycross_wheel_library rule."""

load("@bazel_skylib//lib:paths.bzl", "paths")
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load("@rules_python//python:py_info.bzl", "PyInfo")
load(":providers.bzl", "PycrossWheelInfo")

Expand All @@ -25,7 +26,10 @@ def _pycross_wheel_library_impl(ctx):
inputs.append(name_file)
args.add("--wheel-name-file", name_file)

if ctx.attr.enable_implicit_namespace_pkgs:
enable_implicit_namespace_pkgs = (
ctx.attr.enable_implicit_namespace_pkgs if enable_implicit_namespace_pkgs == -1 else ctx.attr._default_enable_implicit_namespace_pkgs[BuildSettingInfo].value
)
if enable_implicit_namespace_pkgs:
args.add("--enable-implicit-namespace-pkgs")

for install_exclude_glob in ctx.attr.install_exclude_globs:
Expand Down Expand Up @@ -111,13 +115,14 @@ pycross_wheel_library = rule(
doc = "A list of patches to apply after installation.",
allow_files = True,
),
"enable_implicit_namespace_pkgs": attr.bool(
default = True,
"enable_implicit_namespace_pkgs": attr.int(
default = -1,
Comment on lines +118 to +119
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There are no tests for this option. I'd be happy to add some, but I'm not sure where they should go - in //e2e or //pycross/tests? And if so, should I just check in a dummy wheel file containing a namespace package? Please LMK what you would prefer 🙏

doc = """
If true, disables conversion of native namespace packages into pkg-util style namespace packages. When set all py_binary
and py_test targets must specify either `legacy_create_init=False` or the global Bazel option
`--incompatible_default_to_explicit_init_py` to prevent `__init__.py` being automatically generated in every directory.
This option is required to support some packages which cannot handle the conversion to pkg-util style.
This option is required to support some packages which cannot handle the conversion to pkg-util style. The default is
derived from the flag `@rules_pycross//config_settings:default_enable_implicit_namespace_pkgs`.
""",
),
"python_version": attr.string(
Expand All @@ -129,5 +134,8 @@ This option is required to support some packages which cannot handle the convers
cfg = "exec",
executable = True,
),
"_default_enable_implicit_namespace_pkgs": attr.label(
default = "//config_settings:default_enable_implicit_namespace_pkgs",
),
},
)