Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ module(

bazel_dep(name = "bazel_features", version = "1.21.0")
bazel_dep(name = "bazel_skylib", version = "1.8.2")
bazel_dep(name = "rules_cc", version = "0.1.5")
bazel_dep(name = "package_metadata", version = "0.0.6")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

0.0.7 is out now

bazel_dep(name = "platforms", version = "0.0.11")
bazel_dep(name = "rules_cc", version = "0.1.5")

# Those are loaded only when using py_proto_library
# Use py_proto_library directly from protobuf repository
Expand Down
13 changes: 12 additions & 1 deletion python/private/pypi/generate_whl_library_build_bazel.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ _TEMPLATE = """\

package(default_visibility = ["//visibility:public"])

package_metadata(
name = "package_metadata",
purl = {purl},
visibility = ["//:__subpackages__"],
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why limited visibility when the rest is public?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ah... but I wonder if they did it right :-)

Usually, tools pick up the metadata by aspect traversal, so visibility is not needed.
But... we are building out an override system that lets you apply alternate metadata for a package. People will certainly do things like splice in license and copyright declarations when they have researched it and the wheel doesn't contain it. I could make a case that those overrides should point to the label of the the thing the aspect will find. But we could do string of the target.

@Yannic: you did the go thing. Why limited visiblity?

)

{fn}(
{kwargs}
)
Expand All @@ -50,6 +56,7 @@ def generate_whl_library_build_bazel(
*,
annotation = None,
default_python_version = None,
purl = None,
**kwargs):
"""Generate a BUILD file for an unzipped Wheel

Expand All @@ -63,7 +70,10 @@ def generate_whl_library_build_bazel(
A complete BUILD file as a string
"""

loads = []
loads = [
"""load("@package_metadata//rules:package_metadata.bzl", "package_metadata")""",
]

if kwargs.get("tags"):
fn = "whl_library_targets"

Expand Down Expand Up @@ -132,6 +142,7 @@ def generate_whl_library_build_bazel(
"{} = {},".format(k, _RENDER.get(k, repr)(v))
for k, v in sorted(kwargs.items())
])),
purl = repr(purl),
),
] + additional_content,
)
Expand Down
14 changes: 13 additions & 1 deletion python/private/pypi/whl_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,11 @@ def _whl_library_impl(rctx):
entry_points[entry_point_without_py] = entry_point_script_name

namespace_package_files = pypi_repo_utils.find_namespace_package_files(rctx, rctx.path("site-packages"))
purl = "pkg:pypi/{}@{}".format(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What happens if we have private packages in here? Is pkg:pypi/{}@{} only a type of registry or the actual public PyPI?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

IIUC registry information is not yet present in the metadata object, right? IIUC the most common approach is to have an --index-url instruction in the requirements_lock file. DO you know where I can fish out this information from within the rules?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yes, the --index-url may be present in the extra_pip_args attribute of whl_library but if we know the URL to download the wheel from, we don't pass the extra_pip_args.

Given that sometimes people chose to use a fall-through cache mirror (Artifactory, et all) for public PyPI packages, I feel like the purl should be still pointing to the public PyPI and only for things not found on PyPI we should point to a particular registry.

What is the spec here that you are implementing against?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

# https://github.com/package-url/purl-spec/blob/main/types-doc/pypi-definition.md#name-definition
metadata["name"].replace("_", "-").lower(),
metadata["version"],
)

build_file_contents = generate_whl_library_build_bazel(
name = whl_path.basename,
Expand All @@ -526,14 +531,21 @@ def _whl_library_impl(rctx):
"pypi_version={}".format(metadata["version"]),
],
namespace_package_files = namespace_package_files,
purl = purl,
Comment thread
stevebarrau marked this conversation as resolved.
Outdated
)

# Delete these in case the wheel had them. They generally don't cause
# a problem, but let's avoid the chance of that happening.
rctx.file("WORKSPACE")
rctx.file("WORKSPACE.bazel")
rctx.file("MODULE.bazel")
rctx.file("REPO.bazel")
rctx.file("REPO.bazel", """\
repo(
default_package_metadata = [
"//:package_metadata",
],
)
""")

paths = list(rctx.path(".").readdir())
for _ in range(10000000):
Expand Down