Skip to content

pip.parse crashes with StopIteration if platform restriction prevents package from install #1868

@sin-ack

Description

@sin-ack

🐞 bug report

Affected Rule

The issue is caused by the pip.parse extension.

Is this a regression?

No.

Description

If the given requirement has a platform restriction like platform_system == "Windows" and pip refuses to download the requirements, then Bazel will crash.

🔬 Minimal Reproduction

https://github.com/sin-ack/rules_python-repro

🔥 Exception or Error



INFO: Repository rules_python~~pip~pip_311_colorama instantiated at:
  : in 
Repository rule whl_library defined at:
  /home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~/python/pip_install/pip_repository.bzl:932:30: in 
ERROR: An error occurred during the fetch of repository 'rules_python~~pip~pip_311_colorama':
   Traceback (most recent call last):
	File "/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~/python/pip_install/pip_repository.bzl", line 763, column 31, in _whl_library_impl
		repo_utils.execute_checked(
	File "/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~/python/private/repo_utils.bzl", line 145, column 29, in _execute_checked
		return _execute_internal(fail_on_error = True, *args, **kwargs)
	File "/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~/python/private/repo_utils.bzl", line 86, column 13, in _execute_internal
		fail((
Error in fail: repo.execute: whl_library.ResolveRequirement(rules_python~~pip~pip_311_colorama, colorama==0.4.6 ; python_version >= "3.11" and python_version < "4.0" and platform_system == "Windows"     --hash=sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44     --hash=sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6): end: failure:
  command: /home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~python~python_3_11_host/python -m python.pip_install.tools.wheel_installer.wheel_installer --requirement "colorama==0.4.6 ; python_version >= \"3.11\" and python_version < \"4.0\" and platform_system == \"Windows\"     --hash=sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44     --hash=sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6" --isolated --extra_pip_args "{\"arg\":[]}" --pip_data_exclude "{\"arg\":[]}" --environment "{\"arg\":{}}"
  return code: 1
  working dir: 
  timeout: 600
  environment:
PYTHONPATH="/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__build:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__click:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__colorama:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__importlib_metadata:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__installer:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__more_itertools:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__packaging:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__pep517:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__pip:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__pip_tools:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__pyproject_hooks:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__setuptools:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__tomli:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__wheel:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__zipp"
CPPFLAGS="-isystem /home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~python~python_3_11_host/include/python3.11"
===== stdout start =====
Ignoring colorama: markers 'python_version >= "3.11" and python_version < "4.0" and platform_system == "Windows"' don't match your environment
===== stdout end =====
===== stderr start =====
Traceback (most recent call last):
  File "", line 198, in _run_module_as_main
  File "", line 88, in _run_code
  File "/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~/python/pip_install/tools/wheel_installer/wheel_installer.py", line 205, in 
    main()
  File "/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~/python/pip_install/tools/wheel_installer/wheel_installer.py", line 198, in main
    whl = Path(next(iter(glob.glob("*.whl"))))
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
StopIteration
===== stderr end =====
ERROR: : fetching whl_library rule //:rules_python~~pip~pip_311_colorama: Traceback (most recent call last):
	File "/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~/python/pip_install/pip_repository.bzl", line 763, column 31, in _whl_library_impl
		repo_utils.execute_checked(
	File "/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~/python/private/repo_utils.bzl", line 145, column 29, in _execute_checked
		return _execute_internal(fail_on_error = True, *args, **kwargs)
	File "/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~/python/private/repo_utils.bzl", line 86, column 13, in _execute_internal
		fail((
Error in fail: repo.execute: whl_library.ResolveRequirement(rules_python~~pip~pip_311_colorama, colorama==0.4.6 ; python_version >= "3.11" and python_version < "4.0" and platform_system == "Windows"     --hash=sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44     --hash=sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6): end: failure:
  command: /home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~python~python_3_11_host/python -m python.pip_install.tools.wheel_installer.wheel_installer --requirement "colorama==0.4.6 ; python_version >= \"3.11\" and python_version < \"4.0\" and platform_system == \"Windows\"     --hash=sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44     --hash=sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6" --isolated --extra_pip_args "{\"arg\":[]}" --pip_data_exclude "{\"arg\":[]}" --environment "{\"arg\":{}}"
  return code: 1
  working dir: 
  timeout: 600
  environment:
PYTHONPATH="/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__build:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__click:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__colorama:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__importlib_metadata:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__installer:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__more_itertools:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__packaging:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__pep517:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__pip:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__pip_tools:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__pyproject_hooks:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__setuptools:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__tomli:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__wheel:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__zipp"
CPPFLAGS="-isystem /home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~python~python_3_11_host/include/python3.11"
===== stdout start =====
Ignoring colorama: markers 'python_version >= "3.11" and python_version < "4.0" and platform_system == "Windows"' don't match your environment
===== stdout end =====
===== stderr start =====
Traceback (most recent call last):
  File "", line 198, in _run_module_as_main
  File "", line 88, in _run_code
  File "/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~/python/pip_install/tools/wheel_installer/wheel_installer.py", line 205, in 
    main()
  File "/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~/python/pip_install/tools/wheel_installer/wheel_installer.py", line 198, in main
    whl = Path(next(iter(glob.glob("*.whl"))))
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
StopIteration
===== stderr end =====
ERROR: no such package '@@rules_python~~pip~pip_311_colorama//': repo.execute: whl_library.ResolveRequirement(rules_python~~pip~pip_311_colorama, colorama==0.4.6 ; python_version >= "3.11" and python_version < "4.0" and platform_system == "Windows"     --hash=sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44     --hash=sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6): end: failure:
  command: /home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~python~python_3_11_host/python -m python.pip_install.tools.wheel_installer.wheel_installer --requirement "colorama==0.4.6 ; python_version >= \"3.11\" and python_version < \"4.0\" and platform_system == \"Windows\"     --hash=sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44     --hash=sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6" --isolated --extra_pip_args "{\"arg\":[]}" --pip_data_exclude "{\"arg\":[]}" --environment "{\"arg\":{}}"
  return code: 1
  working dir: 
  timeout: 600
  environment:
PYTHONPATH="/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__build:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__click:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__colorama:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__importlib_metadata:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__installer:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__more_itertools:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__packaging:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__pep517:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__pip:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__pip_tools:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__pyproject_hooks:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__setuptools:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__tomli:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__wheel:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__zipp"
CPPFLAGS="-isystem /home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~python~python_3_11_host/include/python3.11"
===== stdout start =====
Ignoring colorama: markers 'python_version >= "3.11" and python_version < "4.0" and platform_system == "Windows"' don't match your environment
===== stdout end =====
===== stderr start =====
Traceback (most recent call last):
  File "", line 198, in _run_module_as_main
  File "", line 88, in _run_code
  File "/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~/python/pip_install/tools/wheel_installer/wheel_installer.py", line 205, in 
    main()
  File "/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~/python/pip_install/tools/wheel_installer/wheel_installer.py", line 198, in main
    whl = Path(next(iter(glob.glob("*.whl"))))
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
StopIteration
===== stderr end =====
ERROR: /home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~pip~pip/colorama/BUILD.bazel:8:6: @@rules_python~~pip~pip//colorama:pkg depends on @@rules_python~~pip~pip_311_colorama//:pkg in repository @@rules_python~~pip~pip_311_colorama which failed to fetch. no such package '@@rules_python~~pip~pip_311_colorama//': repo.execute: whl_library.ResolveRequirement(rules_python~~pip~pip_311_colorama, colorama==0.4.6 ; python_version >= "3.11" and python_version < "4.0" and platform_system == "Windows"     --hash=sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44     --hash=sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6): end: failure:
  command: /home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~python~python_3_11_host/python -m python.pip_install.tools.wheel_installer.wheel_installer --requirement "colorama==0.4.6 ; python_version >= \"3.11\" and python_version < \"4.0\" and platform_system == \"Windows\"     --hash=sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44     --hash=sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6" --isolated --extra_pip_args "{\"arg\":[]}" --pip_data_exclude "{\"arg\":[]}" --environment "{\"arg\":{}}"
  return code: 1
  working dir: 
  timeout: 600
  environment:
PYTHONPATH="/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__build:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__click:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__colorama:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__importlib_metadata:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__installer:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__more_itertools:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__packaging:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__pep517:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__pip:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__pip_tools:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__pyproject_hooks:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__setuptools:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__tomli:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__wheel:/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~internal_deps~pypi__zipp"
CPPFLAGS="-isystem /home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~~python~python_3_11_host/include/python3.11"
===== stdout start =====
Ignoring colorama: markers 'python_version >= "3.11" and python_version < "4.0" and platform_system == "Windows"' don't match your environment
===== stdout end =====
===== stderr start =====
Traceback (most recent call last):
  File "", line 198, in _run_module_as_main
  File "", line 88, in _run_code
  File "/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~/python/pip_install/tools/wheel_installer/wheel_installer.py", line 205, in 
    main()
  File "/home/agni/.cache/bazel/_bazel_agni/ba6071a1d8c8e24a5f08c6b275a4cff8/external/rules_python~/python/pip_install/tools/wheel_installer/wheel_installer.py", line 198, in main
    whl = Path(next(iter(glob.glob("*.whl"))))
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
StopIteration
===== stderr end =====
ERROR: Analysis of target '//:repro' failed; build aborted: Analysis failed
INFO: Elapsed time: 2.031s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
ERROR: Build did NOT complete successfully

🌍 Your Environment

Operating System:

  
Gentoo Linux 23.0
  

Output of bazel version:

  
Bazelisk version: development
Build label: 7.1.1
Build target: @@//src/main/java/com/google/devtools/build/lib/bazel:BazelServer
Build time: Thu Mar 21 18:08:37 2024 (1711044517)
Build timestamp: 1711044517
Build timestamp as int: 1711044517
  

Rules_python version:

  
0.31.0
  

Anything else relevant?

I'm using rules_python_poetry, which generates that verbose requirement line.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions