diff --git a/news/pypackaging-bzl.changed.md b/news/pypackaging-bzl.changed.md index 25405ce6e7..0a322f4e4c 100644 --- a/news/pypackaging-bzl.changed.md +++ b/news/pypackaging-bzl.changed.md @@ -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 +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`. diff --git a/python/private/pypi/BUILD.bazel b/python/private/pypi/BUILD.bazel index 61f0c9f004..7a96dc7bb2 100644 --- a/python/private/pypi/BUILD.bazel +++ b/python/private/pypi/BUILD.bazel @@ -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", ], ) @@ -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( @@ -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", ], ) diff --git a/python/private/pypi/hub_builder.bzl b/python/private/pypi/hub_builder.bzl index df0c48794e..7632698321 100644 --- a/python/private/pypi/hub_builder.bzl +++ b/python/private/pypi/hub_builder.bzl @@ -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") @@ -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( @@ -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. @@ -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_): diff --git a/python/private/pypi/pep508_env.bzl b/python/private/pypi/pep508_env.bzl index 95a9679300..14b8b6a975 100644 --- a/python/private/pypi/pep508_env.bzl +++ b/python/private/pypi/pep508_env.bzl @@ -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" @@ -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 diff --git a/python/private/pypi/pip_repository.bzl b/python/private/pypi/pip_repository.bzl index d02c62eae1..efeb205d75 100644 --- a/python/private/pypi/pip_repository.bzl +++ b/python/private/pypi/pip_repository.bzl @@ -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") @@ -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,