Skip to content

Consider removing duplicate code in PyPI package name normalization #1330

Closed
@aignas

Description

@aignas

This is a followup to @chrislovecnm comment in #1329.

If #1329 lands, then there are the following parts where we have name sanitisation and normalization.

First are the requirement, whl_requirement, data_requirement, dist_info_requirement and entry_point macros are using a vendored copy of the function named _clean_name. We could just use the function introduced in #1329 most of the time, but we have to expose it either in //python/pip_install:normalize_name.bzl or somewhere else because as it is right now, it's invisible from the pip_parse hub repos.

Second is the Python implementation in //python/pip_install/tools/lib:bazel.py has a copy and we cannot remove it that easily. The only (semi) sensible way would be to change the implementation of the whl_library:

  • Starlark implementation declares a metadata.json output file that gets written by the wheel_installer.py script.
  • The script extracts or builds the wheel and outputs the metadata to the metadata.json file as opposed to creating a BUILD.bazel file.
  • Starlark implementation reads the metadata.json file and then constructs the BUILD.bazel file.

The benefit of the whl_library refactor would be that it would make the wheel installer a single purpose tool and we could pass the extra BUILD.bazel content or do patching within the starlark context and it would make annotation handling easier. The whole argument parsing for the wheel_installer.py is likely to also become simpler.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions