Skip to content

Commit

Permalink
refactor: reuse the same no match error message everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
aignas committed Aug 1, 2023
1 parent 5d2bca8 commit de2b7e1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 28 deletions.
22 changes: 2 additions & 20 deletions python/pip.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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_<version>`
configuration settings.
To determine the current configuration's Python version, run:
`bazel config <config id>` (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.
Expand Down Expand Up @@ -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,
),
Expand Down
14 changes: 8 additions & 6 deletions python/private/render_pkg_aliases.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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_<version>`
configuration settings.
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_<version>`
configuration settings.
Expand Down

0 comments on commit de2b7e1

Please sign in to comment.