Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursive loops in requirements files not detected #12653

Open
1 task done
freakboy3742 opened this issue Apr 26, 2024 · 0 comments
Open
1 task done

Recursive loops in requirements files not detected #12653

freakboy3742 opened this issue Apr 26, 2024 · 0 comments
Labels
S: needs triage Issues/PRs that need to be triaged type: bug A confirmed bug or unintended behavior

Comments

@freakboy3742
Copy link
Contributor

Description

If a requirements file references itself (directly or indirectly), an RecursionError is raised.

Expected behavior

The RecursionError isn't strictly wrong, but the cause of the error may not be obvious as it results in a hard interpreter crash. It would be desirable to detect the recursion, and report the source of the problem rather than crashing the Python interpreter.

pip version

24.0

Python version

3.10 (but should affect any version)

OS

macOS (but should affect any OS)

How to Reproduce

  1. Construct a requirements.txt that contains:
-r requirements.txt
  1. Run pip install -r requirements.txt

This is the simplest case; other loops (such as requirements files that include each other, and cycles of 3 or more requirements files) also cause the problem.

Output

ERROR: Exception:
Traceback (most recent call last):
  File "/Users/rkm/beeware/toga/venv3.10/lib/python3.10/site-packages/pip/_internal/cli/base_command.py", line 180, in exc_logging_wrapper
    status = run_func(*args)
  File "/Users/rkm/beeware/toga/venv3.10/lib/python3.10/site-packages/pip/_internal/cli/req_command.py", line 245, in wrapper
    return func(self, options, args)
  File "/Users/rkm/beeware/toga/venv3.10/lib/python3.10/site-packages/pip/_internal/commands/install.py", line 342, in run
    reqs = self.get_requirements(args, options, finder, session)
  File "/Users/rkm/beeware/toga/venv3.10/lib/python3.10/site-packages/pip/_internal/cli/req_command.py", line 433, in get_requirements
    for parsed_req in parse_requirements(
  File "/Users/rkm/beeware/toga/venv3.10/lib/python3.10/site-packages/pip/_internal/req/req_file.py", line 156, in parse_requirements
    for parsed_line in parser.parse(filename, constraint):
  File "/Users/rkm/beeware/toga/venv3.10/lib/python3.10/site-packages/pip/_internal/req/req_file.py", line 337, in parse
    yield from self._parse_and_recurse(filename, constraint)
  File "/Users/rkm/beeware/toga/venv3.10/lib/python3.10/site-packages/pip/_internal/req/req_file.py", line 366, in _parse_and_recurse
    yield from self._parse_and_recurse(req_path, nested_constraint)
  File "/Users/rkm/beeware/toga/venv3.10/lib/python3.10/site-packages/pip/_internal/req/req_file.py", line 366, in _parse_and_recurse
    yield from self._parse_and_recurse(req_path, nested_constraint)
  File "/Users/rkm/beeware/toga/venv3.10/lib/python3.10/site-packages/pip/_internal/req/req_file.py", line 366, in _parse_and_recurse
    yield from self._parse_and_recurse(req_path, nested_constraint)
  [Previous line repeated 972 more times]
  File "/Users/rkm/beeware/toga/venv3.10/lib/python3.10/site-packages/pip/_internal/req/req_file.py", line 342, in _parse_and_recurse
    for line in self._parse_file(filename, constraint):
  File "/Users/rkm/beeware/toga/venv3.10/lib/python3.10/site-packages/pip/_internal/req/req_file.py", line 379, in _parse_file
    args_str, opts = self._line_parser(line)
  File "/Users/rkm/beeware/toga/venv3.10/lib/python3.10/site-packages/pip/_internal/req/req_file.py", line 398, in parse_line
    parser = build_parser()
  File "/Users/rkm/beeware/toga/venv3.10/lib/python3.10/site-packages/pip/_internal/req/req_file.py", line 444, in build_parser
    parser = optparse.OptionParser(add_help_option=False)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/optparse.py", line 1191, in __init__
    self.set_usage(usage)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/optparse.py", line 1266, in set_usage
    self.usage = _("%prog [options]")
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/gettext.py", line 742, in gettext
    return dgettext(_current_domain, message)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/gettext.py", line 666, in dgettext
    t = translation(domain, _localedirs.get(domain, None))
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/gettext.py", line 587, in translation
    mofiles = find(domain, localedir, languages, all=True)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/gettext.py", line 558, in find
    for nelang in _expand_lang(lang):
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/gettext.py", line 213, in _expand_lang
    loc = locale.normalize(loc)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/locale.py", line 461, in normalize
    return _replace_encoding(code, encoding)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/locale.py", line 368, in _replace_encoding
    norm_encoding = encodings.normalize_encoding(encoding)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/encodings/__init__.py", line 55, in normalize_encoding
    if isinstance(encoding, bytes):
RecursionError: maximum recursion depth exceeded while calling a Python object

Code of Conduct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S: needs triage Issues/PRs that need to be triaged type: bug A confirmed bug or unintended behavior
Projects
None yet
Development

No branches or pull requests

1 participant