fix: Fix broken logger statement in parse_requirements.bzl (#2017)

parse_requirements.bzl includes a broken logger statement by passing a
string instead of a lambda. The result is that when a hash is no longer
available on pypi (say, due to a release being yanked) that rules_python
causes Bazel to halt. Since we use Bazel to generate requirements files,
this means the only solution is to use non-Bazel tooling to get back to
a functional state before then running Bazel tooling to update the
requirements file -- all down to a faulty log statement.

This PR corrects the faulty log statement. A more thorough fix might be
to update the logger to warn if its invoked with a string instead of a
lambda rather than failing.

An example traceback which led to this discovery:
```
ERROR: Traceback (most recent call last):
	File ".../external/rules_python~/python/private/bzlmod/pip.bzl", line 472, column 52, in _pip_impl
		is_hub_reproducible = _create_whl_repos(module_ctx, pip_attr, hub_whl_map, whl_overrides, hub_group_map, simpleapi_cache)
	File ".../external/rules_python~/python/private/bzlmod/pip.bzl", line 187, column 50, in _create_whl_repos
		requirements_by_platform = parse_requirements(
	File ".../external/rules_python~/python/private/parse_requirements.bzl", line 348, column 37, in parse_requirements
		whls, sdist = _add_dists(
	File ".../external/rules_python~/python/private/parse_requirements.bzl", line 452, column 24, in _add_dists
		logger.warn("Could not find a whl or an sdist with sha256={}".format(sha256))
	File ".../external/rules_python~/python/private/repo_utils.bzl", line 78, column 39, in lambda
		warn = lambda message_cb: _log(0, "WARNING", message_cb),
	File ".../external/rules_python~/python/private/repo_utils.bzl", line 72, column 71, in _log
		print("\nrules_python: {}: ".format(level.upper()), message_cb())  # buildifier: disable=print
Error: 'string' object is not callable
```

---------

Co-authored-by: Richard Levasseur <rlevasseur@google.com>
2 files changed
tree: dadb0b5228972a7b5be06454a68a4c06a36723f4
  1. .bazelci/
  2. .bcr/
  3. .ci/
  4. .github/
  5. docs/
  6. examples/
  7. gazelle/
  8. python/
  9. sphinxdocs/
  10. tests/
  11. third_party/
  12. tools/
  13. .bazelignore
  14. .bazelrc
  15. .bazelversion
  16. .git-blame-ignore-revs
  17. .gitattributes
  18. .gitignore
  19. .pre-commit-config.yaml
  20. .readthedocs.yml
  21. addlicense.sh
  22. AUTHORS
  23. BUILD.bazel
  24. BZLMOD_SUPPORT.md
  25. CHANGELOG.md
  26. CONTRIBUTING.md
  27. CONTRIBUTORS
  28. DEVELOPING.md
  29. internal_deps.bzl
  30. internal_setup.bzl
  31. LICENSE
  32. MODULE.bazel
  33. README.md
  34. renovate.json
  35. version.bzl
  36. WORKSPACE
  37. WORKSPACE.bzlmod
README.md

Python Rules for Bazel

Build status

Overview

This repository is the home of the core Python rules -- py_library, py_binary, py_test, py_proto_library, and related symbols that provide the basis for Python support in Bazel. It also contains package installation rules for integrating with PyPI and other indices.

Documentation for rules_python is at https://rules-python.readthedocs.io and in the Bazel Build Encyclopedia.

Examples live in the examples directory.

The core rules are stable. Their implementation is subject to Bazel's backward compatibility policy. This repository aims to follow semantic versioning.

The Bazel community maintains this repository. Neither Google nor the Bazel team provides support for the code. However, this repository is part of the test suite used to vet new Bazel releases. See How to contribute page for information on our development workflow.

Documentation

For detailed documentation, see https://rules-python.readthedocs.io

Bzlmod support

  • Status: Beta
  • Full Feature Parity: No

See Bzlmod support for more details.