Skip to content
Open
14 changes: 7 additions & 7 deletions news/pypackaging-bzl.changed.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(pypi) Invalid PEP 508 requirements and environment markers now fail instead of
being silently accepted, as they are now parsed by
[`pypackaging.bzl`](https://github.com/jvolkman/pypackaging.bzl) (a Starlark
port of [`packaging`](https://github.com/pypa/packaging)). The markers are
evaluated like `packaging` does it, e.g. `platform_release` is compared as a
version and the ordered comparisons of strings are always false. `WORKSPACE`
users get `pypackaging.bzl` from {obj}`py_repositories`.
(pypi) Invalid versions, version specifiers, PEP 508 requirements and

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.

too much detail in the news. reduce to essential changed behavior relevant to users without the implementation details

environment markers now fail instead of being silently accepted, as they are
now parsed by [`pypackaging.bzl`](https://github.com/jvolkman/pypackaging.bzl)
(a Starlark port of [`packaging`](https://github.com/pypa/packaging)). The
markers are evaluated like `packaging` does it, e.g. `platform_release` is
compared as a version and the ordered comparisons of strings are always false.
`WORKSPACE` users get `pypackaging.bzl` from {obj}`py_repositories`.
6 changes: 3 additions & 3 deletions python/private/pypi/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ bzl_library(
"//python/private:normalize_name",
"//python/private:repo_utils",
"//python/private:text_util",
"//python/private:version",
"//python/private:version_label",
"@pypackaging.bzl//:pypackaging",
],
)

Expand Down Expand Up @@ -293,7 +293,7 @@ bzl_library(
bzl_library(
name = "pep508_env",
srcs = ["pep508_env.bzl"],
deps = ["//python/private:version"],
deps = ["@pypackaging.bzl//:pypackaging"],
)

bzl_library(
Expand Down Expand Up @@ -341,8 +341,8 @@ bzl_library(
"//python/private:normalize_name",
"//python/private:repo_utils",
"//python/private:text_util",
"//python/private:version",
"@bazel_skylib//lib:sets",
"@pypackaging.bzl//:pypackaging",
"@toml.bzl//:toml",
],
)
Expand Down
11 changes: 4 additions & 7 deletions python/private/pypi/hub_builder.bzl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""A hub repository builder for incrementally building the hub configuration."""

load("@pypackaging.bzl", "pypackaging")
load("//python/private:envsubst.bzl", "envsubst")
load("//python/private:full_version.bzl", "full_version")
load("//python/private:normalize_name.bzl", "normalize_name")
load("//python/private:repo_utils.bzl", "repo_utils")
load("//python/private:text_util.bzl", "render")
load("//python/private:version.bzl", "version")
load("//python/private:version_label.bzl", "version_label")
load(":attrs.bzl", "use_isolated")
load(":hash.bzl", "hash")
Expand All @@ -18,7 +18,7 @@ load(":whl_config_setting.bzl", "whl_config_setting")
load(":whl_repo_name.bzl", "pypi_repo_name", "whl_repo_name")

def _major_minor_version(version_str):
ver = version.parse(version_str)
ver = pypackaging.version.parse(version_str)
return "{}.{}".format(ver.release[0], ver.release[1])

def hub_builder(
Expand Down Expand Up @@ -483,10 +483,7 @@ def _detect_interpreter(self, pip_attr, python_version, full_python_version):

def _platforms(module_ctx, *, python_version, config, target_platforms):
platforms = {}
python_version = version.parse(
python_version,
strict = True,
)
python_version = pypackaging.version.parse(python_version)

if "*" in target_platforms:
# All of the configured platforms.
Expand Down Expand Up @@ -518,7 +515,7 @@ def _platforms(module_ctx, *, python_version, config, target_platforms):
env = values.env,
os = values.os_name,
arch = values.arch_name,
python_version = python_version.string,
python_version = pypackaging.version.to_string(python_version),
)

if values.marker and not evaluate(values.marker, env = env_):
Expand Down
4 changes: 2 additions & 2 deletions python/private/pypi/pep508_env.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"""This module is for implementing PEP508 environment definition.
"""

load("//python/private:version.bzl", "version")
load("@pypackaging.bzl", "pypackaging")

_DEFAULT = "//conditions:default"

Expand Down Expand Up @@ -179,7 +179,7 @@ def env(*, env = None, os, arch, python_version = "", extra = None):
env["extra"] = extra

if python_version:
v = version.parse(python_version)
v = pypackaging.version.parse(python_version)
major = v.release[0]
minor = v.release[1]
micro = v.release[2] if len(v.release) > 2 else 0
Expand Down
4 changes: 2 additions & 2 deletions python/private/pypi/pip_repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
""

load("@bazel_skylib//lib:sets.bzl", "sets")
load("@pypackaging.bzl", "pypackaging")
load("@toml.bzl", "toml")
load("//python/private:normalize_name.bzl", "normalize_name")
load("//python/private:repo_utils.bzl", "REPO_DEBUG_ENV_VAR", "repo_utils")
load("//python/private:text_util.bzl", "render")
load("//python/private:version.bzl", "version")
load(":default_platforms.bzl", "default_platforms")
load(":hash.bzl", "hash")
load(":parse_requirements.bzl", "host_platform", "parse_requirements", "select_requirement")
Expand Down Expand Up @@ -114,7 +114,7 @@ def _pip_repository_impl(rctx):
]

marker_env = env(os = rctx.os.name, arch = rctx.os.arch, python_version = python_version)
parsed_python_version = version.parse(python_version, strict = True)
parsed_python_version = pypackaging.version.parse(python_version)
platform_defaults = default_platforms()
requirements_by_platform = parse_requirements(
rctx,
Expand Down
Loading