Skip to content

feat: parse requirements.txt with private pypi repository #318

Closed

Description

@llamahunter

We have a private pypi repository, and so our requirements.txt file (per https://pip.pypa.io/en/stable/reference/requirements-file-format/) has a --index-url pointing to our private index.
This worked fine with older versions of cyclonedx-python, but newer versions (notably 3.0.0) now fails with a runtime exception.

long stack trace
Traceback (most recent call last):
  File "/Users/rdlee/Documents/tivo-research/git/poetry_test_lib/build/poetry-test-lib-lx3mW_5N-py3.10/lib/python3.10/site-packages/pkg_resources/_vendor/packaging/requirements.py", line 102, in __init__
    req = REQUIREMENT.parseString(requirement_string)
  File "/Users/rdlee/Documents/tivo-research/git/poetry_test_lib/build/poetry-test-lib-lx3mW_5N-py3.10/lib/python3.10/site-packages/pkg_resources/_vendor/pyparsing.py", line 1654, in parseString
    raise exc
  File "/Users/rdlee/Documents/tivo-research/git/poetry_test_lib/build/poetry-test-lib-lx3mW_5N-py3.10/lib/python3.10/site-packages/pkg_resources/_vendor/pyparsing.py", line 1644, in parseString
    loc, tokens = self._parse( instring, 0 )
  File "/Users/rdlee/Documents/tivo-research/git/poetry_test_lib/build/poetry-test-lib-lx3mW_5N-py3.10/lib/python3.10/site-packages/pkg_resources/_vendor/pyparsing.py", line 1402, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/Users/rdlee/Documents/tivo-research/git/poetry_test_lib/build/poetry-test-lib-lx3mW_5N-py3.10/lib/python3.10/site-packages/pkg_resources/_vendor/pyparsing.py", line 3417, in parseImpl
    loc, exprtokens = e._parse( instring, loc, doActions )
  File "/Users/rdlee/Documents/tivo-research/git/poetry_test_lib/build/poetry-test-lib-lx3mW_5N-py3.10/lib/python3.10/site-packages/pkg_resources/_vendor/pyparsing.py", line 1402, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/Users/rdlee/Documents/tivo-research/git/poetry_test_lib/build/poetry-test-lib-lx3mW_5N-py3.10/lib/python3.10/site-packages/pkg_resources/_vendor/pyparsing.py", line 3739, in parseImpl
    return self.expr._parse( instring, loc, doActions, callPreParse=False )
  File "/Users/rdlee/Documents/tivo-research/git/poetry_test_lib/build/poetry-test-lib-lx3mW_5N-py3.10/lib/python3.10/site-packages/pkg_resources/_vendor/pyparsing.py", line 1402, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/Users/rdlee/Documents/tivo-research/git/poetry_test_lib/build/poetry-test-lib-lx3mW_5N-py3.10/lib/python3.10/site-packages/pkg_resources/_vendor/pyparsing.py", line 3400, in parseImpl
    loc, resultlist = self.exprs[0]._parse( instring, loc, doActions, callPreParse=False )
  File "/Users/rdlee/Documents/tivo-research/git/poetry_test_lib/build/poetry-test-lib-lx3mW_5N-py3.10/lib/python3.10/site-packages/pkg_resources/_vendor/pyparsing.py", line 1406, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/Users/rdlee/Documents/tivo-research/git/poetry_test_lib/build/poetry-test-lib-lx3mW_5N-py3.10/lib/python3.10/site-packages/pkg_resources/_vendor/pyparsing.py", line 2711, in parseImpl
    raise ParseException(instring, loc, self.errmsg, self)
pkg_resources._vendor.pyparsing.ParseException: Expected W:(abcd...) (at char 0), (line:1, col:1)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/rdlee/Documents/tivo-research/git/poetry_test_lib/build/poetry-test-lib-lx3mW_5N-py3.10/bin/cyclonedx-py", line 8, in <module>
    sys.exit(main())
  File "/Users/rdlee/Documents/tivo-research/git/poetry_test_lib/build/poetry-test-lib-lx3mW_5N-py3.10/lib/python3.10/site-packages/cyclonedx_py/client.py", line 260, in main
    CycloneDxCmd(args).execute()
  File "/Users/rdlee/Documents/tivo-research/git/poetry_test_lib/build/poetry-test-lib-lx3mW_5N-py3.10/lib/python3.10/site-packages/cyclonedx_py/client.py", line 113, in execute
    output = self.get_output()
  File "/Users/rdlee/Documents/tivo-research/git/poetry_test_lib/build/poetry-test-lib-lx3mW_5N-py3.10/lib/python3.10/site-packages/cyclonedx_py/client.py", line 63, in get_output
    parser = self._get_input_parser()
  File "/Users/rdlee/Documents/tivo-research/git/poetry_test_lib/build/poetry-test-lib-lx3mW_5N-py3.10/lib/python3.10/site-packages/cyclonedx_py/client.py", line 252, in _get_input_parser
    return RequirementsParser(requirements_content=input_data)
  File "/Users/rdlee/Documents/tivo-research/git/poetry_test_lib/build/poetry-test-lib-lx3mW_5N-py3.10/lib/python3.10/site-packages/cyclonedx_py/parser/requirements.py", line 33, in __init__
    for requirement in requirements:
  File "/Users/rdlee/Documents/tivo-research/git/poetry_test_lib/build/poetry-test-lib-lx3mW_5N-py3.10/lib/python3.10/site-packages/pkg_resources/__init__.py", line 3159, in __init__
    super(Requirement, self).__init__(requirement_string)
  File "/Users/rdlee/Documents/tivo-research/git/poetry_test_lib/build/poetry-test-lib-lx3mW_5N-py3.10/lib/python3.10/site-packages/pkg_resources/_vendor/packaging/requirements.py", line 104, in __init__
    raise InvalidRequirement(
pkg_resources.extern.packaging.requirements.InvalidRequirement: Parse error at "'--index-'": Expected W:(abcd...)

It appears that cyclonedx_bom is using pkg_resources to parse a requirement.txt file? I don't think that library is quite up to the task, as it doesn't appear to have support for the full syntax of pip, and is just implementing a subset of the support for PEP 508. Perhaps you should use the requirements-parser library instead?

Activity

  1. jkowalleck commented on Feb 23, 2022

    @jkowalleck
    Member

    @madpah i dont see an actual urge for this feature, and i dont see it as a bug.
    relative paths private repositories* are not to be expected to be output of pip freeze

    but it is a convenient feature, no doubt.

    * edited

  2. added
    enhancement
    on Feb 23, 2022
  3. changed the title [-]passing a requirements.txt file to -r fails when using private pypi repository.[/-] [+]passing a `requirements.txt` file with **private pypi repository**[/+] on Feb 23, 2022
  4. changed the title [-]passing a `requirements.txt` file with **private pypi repository**[/-] [+]feat: `requirements.txt` file with **private pypi repository**[/+] on Feb 23, 2022
  5. changed the title [-]feat: `requirements.txt` file with **private pypi repository**[/-] [+]feat: `requirements.txt` file with private pypi repository[/+] on Feb 23, 2022
  6. changed the title [-]feat: `requirements.txt` file with private pypi repository[/-] [+]feat: parse `requirements.txt` with private pypi repository[/+] on Feb 23, 2022
  7. llamahunter commented on Feb 23, 2022

    @llamahunter
    ContributorAuthor

    @madpah i dont see an actual urge for this feature, and i dont see it as a bug.

    relative paths are not to be expected to be output of pip freeze

    but it is a convenient feature, no doubt.

    This is not about "relative paths", it is about private pypi repos.

  8. jkowalleck commented on Feb 23, 2022

    @jkowalleck
    Member

    re: #318 (comment)
    you are right.

    nevertheless:

    i do not see an actual urge for this feature, and i do not see it as a bug.
    private repositories are not to be expected to be output of pip freeze.

    but it is a convenient feature, no doubt.

  9. jkowalleck commented on Feb 23, 2022

    @jkowalleck
    Member

    another discussion, that proposes to switch to another requirements-parser:
    #315 (comment)

  10. jkowalleck commented on Feb 23, 2022

    @jkowalleck
    Member

    for discussions, feel free to switch to #319

  11. llamahunter commented on Mar 1, 2022

    @llamahunter
    ContributorAuthor

    Note that the documentation for cyclone-dx doesn't say 'the output of pip freeze', it says a 'requirements.txt' file. The documentation for that is here:
    https://pip.pypa.io/en/stable/reference/requirements-file-format/
    Note that it does include -i for specifying private pypi repo indices.

  12. llamahunter commented on Mar 1, 2022

    @llamahunter
    ContributorAuthor

    This is a pretty urgent feature, as when we updated to the latest python cyclondx-bom version, our builds all broke.

  13. jkowalleck commented on Mar 1, 2022

    @jkowalleck
    Member

    Note that the documentation for cyclone-dx doesn't say 'the output of pip freeze', it says a 'requirements.txt' file.

    see the original documentation: https://github.com/CycloneDX/cyclonedx-python/tree/v1.5.3#requirements
    this is not the place for OT discussions

    PS: the mentioned docus, that explain the usage with pip freeze can be found here:

  14. llamahunter commented on Mar 1, 2022

    @llamahunter
    ContributorAuthor

    this is not the place for OT discussions

    It's hardly off topic to discuss the tool having broken in recent updates for files it previously supported.

  15. linked a pull request that will close this issuefeat: Change requirements parser #327on Mar 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions