diff --git a/python/pip.bzl b/python/pip.bzl index 708cd6ba62..0c6e90f577 100644 --- a/python/pip.bzl +++ b/python/pip.bzl @@ -17,30 +17,12 @@ load("//python/pip_install:pip_repository.bzl", "pip_repository", _package_annot load("//python/pip_install:repositories.bzl", "pip_install_dependencies") load("//python/pip_install:requirements.bzl", _compile_pip_requirements = "compile_pip_requirements") load("//python/private:bzlmod_enabled.bzl", "BZLMOD_ENABLED") +load("//python/private:render_pkg_aliases.bzl", "NO_MATCH_ERROR_MESSAGE_TEMPLATE") load(":versions.bzl", "MINOR_MAPPING") compile_pip_requirements = _compile_pip_requirements package_annotation = _package_annotation -_NO_MATCH_ERROR_MESSAGE_TEMPLATE = """\ -No matching wheel for current configuration's Python version. - -The current build configuration's Python version doesn't match any of the Python -versions available for this wheel. This wheel supports the following Python versions: - {supported_versions} - -As matched by the `@{rules_python}//python/config_settings:is_python_` -configuration settings. - -To determine the current configuration's Python version, run: - `bazel config ` (shown further below) -and look for - {rules_python}//python/config_settings:python_version - -If the value is missing, then the "default" Python version is being used, -which has a "null" version value and will not match version constraints. -""" - def pip_install(requirements = None, name = "pip", **kwargs): """Accepts a locked/compiled requirements file and installs the dependencies listed within. @@ -335,7 +317,7 @@ alias( if not default_repo_prefix: supported_versions = sorted([python_version for python_version, _ in version_map]) alias.append(' no_match_error="""{}""",'.format( - _NO_MATCH_ERROR_MESSAGE_TEMPLATE.format( + NO_MATCH_ERROR_MESSAGE_TEMPLATE.format( supported_versions = ", ".join(supported_versions), rules_python = rules_python, ), diff --git a/python/private/render_pkg_aliases.bzl b/python/private/render_pkg_aliases.bzl index 7286175abb..bcbfc8c674 100644 --- a/python/private/render_pkg_aliases.bzl +++ b/python/private/render_pkg_aliases.bzl @@ -20,13 +20,12 @@ load("//python/private:normalize_name.bzl", "normalize_name") load(":text_util.bzl", "render") load(":version_label.bzl", "version_label") -_NO_MATCH_ERROR_MESSAGE_TEMPLATE = """\ -_NO_MATCH_ERROR = \"\"\"\\ +NO_MATCH_ERROR_MESSAGE_TEMPLATE = """\ No matching wheel for current configuration's Python version. The current build configuration's Python version doesn't match any of the Python versions available for this wheel. This wheel supports the following Python versions: -{supported_versions} + {supported_versions} As matched by the `@{rules_python}//python/config_settings:is_python_` configuration settings. @@ -38,7 +37,6 @@ and look for If the value is missing, then the "default" Python version is being used, which has a "null" version value and will not match version constraints. -\"\"\"\ """ def _render_whl_library_alias( @@ -112,9 +110,13 @@ def _render_common_aliases(repo_name, name, versions = None, default_version = N versions = sorted(versions) if versions and not default_version: - lines.append(_NO_MATCH_ERROR_MESSAGE_TEMPLATE.format( - supported_versions = render.indent("\n".join(versions)), + error_msg = NO_MATCH_ERROR_MESSAGE_TEMPLATE.format( + supported_versions = ", ".join(versions), rules_python = rules_python, + ) + + lines.append("_NO_MATCH_ERROR = \"\"\"\\\n{error_msg}\"\"\"".format( + error_msg = error_msg, )) lines.append( diff --git a/tests/pip_hub_repository/render_pkg_aliases/render_pkg_aliases_test.bzl b/tests/pip_hub_repository/render_pkg_aliases/render_pkg_aliases_test.bzl index 512046ff88..28d95ff2dd 100644 --- a/tests/pip_hub_repository/render_pkg_aliases/render_pkg_aliases_test.bzl +++ b/tests/pip_hub_repository/render_pkg_aliases/render_pkg_aliases_test.bzl @@ -154,8 +154,7 @@ No matching wheel for current configuration's Python version. The current build configuration's Python version doesn't match any of the Python versions available for this wheel. This wheel supports the following Python versions: - 3.1.3 - 3.2.3 + 3.1.3, 3.2.3 As matched by the `@rules_python//python/config_settings:is_python_` configuration settings.