8000 Support for PEP 440 local version identifiers is broken · Issue #883 · bazel-contrib/rules_python · GitHub
[go: up one dir, main page]

Skip to content
Support for PEP 440 local version identifiers is broken #883
Closed
@vonschultz

Description

@vonschultz

🐞 bug report

Affected Rule

The issue is caused by the rule: py_wheel.

Is this a regression?

Yes, the previous version in which this bug was not present was: 0.3.0

Description

Support for PEP 440 local version identifiers is broken. While a version number such as 1.0.0+local is correctly reflected in the *.dist-info/METADATA file, it is not correctly reflected in commands such as pip list, pip show or pip freeze, which show this version number as 1.0.0-local, with - instead of +.

🔬 Minimal Reproduction

load("@rules_python//python:packaging.bzl", "py_wheel")

py_wheel(
    name = "testwheel",
    distribution = "test",
    version = "1.0.0+local",
    visibility = ["//visibility:public"],
) 

and a WORKSPACE.bazel file according to version 0.3.0 (works), version 0.4.0 (exhibits problem) or version 0.13.0 (exhibits problem).

Build the wheel, install in a venv, run pip list, see the correct version 1.0.0+local (in case of rules_python 0.3.0) or incorrect version 1.0.0-local (in newer versions).

🔥 Exception or Error

If used with a package index and a requirements.txt file, you'll find that the - version number raises pip._vendor.packaging.version.InvalidVersion or has inconsistent version (depending on pip version), and the + version number produces Could not find a version that satisfies the requirement.

Using pip 22.3.1 (you may need to pip install --upgrade pip):

$ pip install test==1.0.0+local -f rules_python-0.13.0/bazel-bin/
Looking in links: rules_python-0.13.0/bazel-bin/
ERROR: Could not find a version that satisfies the requirement test==1.0.0+local (from versions: 1.0.0-local)
ERROR: No matching distribution found for test==1.0.0+local
$ pip install test==1.0.0-local -f rules_python-0.13.0/bazel-bin/
Looking in links: rules_python-0.13.0/bazel-bin/
Processing /home/von/.cache/bazel/_bazel_von/709d76476fbc87d51d99291df73a3511/execroot/__main__/bazel-out/k8-fastbuild/bin/test-1.0.0_local-py3-none-any.whl
Discarding file:///home/von/.cache/bazel/_bazel_von/709d76476fbc87d51d99291df73a3511/execroot/__main__/bazel-out/k8-fastbuild/bin/test-1.0.0_local-py3-none-any.whl: Requested test==1.0.0-local from file:///home/von/.cache/bazel/_bazel_von/709d76476fbc87d51d99291df73a3511/execroot/__main__/bazel-out/k8-fastbuild/bin/test-1.0.0_local-py3-none-any.whl has inconsistent version: expected '1.0.0-local', but metadata has '1.0.0+local'
ERROR: Could not find a version that satisfies the requirement test==1.0.0-local (from versions: 1.0.0-local)
ERROR: No matching distribution found for test==1.0.0-local

🌍 Your Environment

Operating System:

Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.5 LTS
Release:	20.04
Codename:	focal

Output of bazel version:

Bazelisk version: v1.9.0
Build label: 5.3.2
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Wed Oct 19 18:22:12 2022 (1666203732)
Build timestamp: 1666203732
Build timestamp as int: 1666203732

Rules_python version:

0.13.0

🔍 Anything else relevant?

You may also compare with the corresponding setuptools project:

from setuptools import setup, find_packages

setup(
    name='test',
    version='1.0.0+local',
    packages=find_packages(),
)

This does not exhibit the problem. Analyzing the contents of the .whl files seems to indicate that the problem is the name of the *.dist-info directory, which in all the working examples uses a + in the version number part. The broken versions use _ instead of + in the name of the *.dist-info directory, and renaming the *.dist-info directory inside the venv to use + instead of _ fixes the bug.

It seems probable to me that the problem was introduced in pull request #518, which was supposed to escape characters in the wheel file name according to PEP 427. That's all fine when it comes to the name of the wheel file itself, but nothing in PEP 427 says to do that to the dist-info directory, and I think doing so causes the observed breakage.

I believe, in other words, that escape_filename_segment() should be removed from tools/wheelmaker.py.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0