| single |
pip-requirements-parser - a mostly correct pip requirements parsing library
================================================================================
Copyright (c) nexB Inc. and others.
Copyright (c) The pip developers (see AUTHORS.rst file)
SPDX-License-Identifier: MIT
Homepage: https://github.com/nexB/pip-requirements and
https://www.aboutcode.org/
``pip-requirements-parser`` is a mostly correct pip requirements parsing
library ... because it uses pip's own code!
pip is the package installer for Python that is using "requirements" text
files listing the packages to install.
Per https://pip.pypa.io/en/stable/reference/requirements-file-format/ :
"The requirements file format is closely tied to a number of internal
details of pip (e.g., pip’s command line options). The basic format
is
relatively stable and portable but the full syntax, as described here,
is only intended for consumption by pip, and other tools should take
that into account before using it for their own purposes."
And per
https://pip.pypa.io/en/stable/user_guide/#using-pip-from-your-program :
"[..] pip is a command line program. While it is implemented in Python,
and
so is available from your Python code via import pip, you must not use
pip’s
internal APIs in this way."
"What this means in practice is that everything inside of pip is
considered
an implementation detail. Even the fact that the import name is pip is
subject to change without notice. While we do try not to break things
as
much as possible, all the internal APIs can change at any time, for any
reason. It also means that we generally won’t fix issues that are a
result
of using pip in an unsupported way."
Because of all this, pip requirements are notoriously difficult to parse
right
in all their diversity because:
- pip does not have a public API and therefore cannot be reliably used as a
stable library. Some libraries attempt to do this though. (See
Alternative)
- The pip requirements file syntax is closely aligned with pip's command
line
interface and command line options. In some ways a pip requirements file
is a
list of pip command line options and arguments. Therefore, it is hard to
parse
these short of reproducing the pip command line options parsing. At least
one
other library is using a command line option parser to parse options
correctly.
This ``pip-requirements-parser`` Python library is yet another pip
requirements
files parser, but this time doing it hopefully correctly and doing as well
as
pip does it, because this is using pip's own code.
The ``pip-requirements-parser`` library offers these key advantages:
- Other requirements parsers typically do not work in all the cases that
pip
supports: parsing any requirement as seen in the wild will fail parsing
some
valid pip requirements. Since the ``pip-requirements-parser`` library is
based
on pip's own code, it works **exactly** like pip and will parse all the
requirements files that pip can parse.
- The ``pip-requirements-parser`` library offers a simple and stable code
API
that will not change without notice.
- The ``pip-requirements-parser`` library is designed to work offline
without
making any external network call, while the original pip code needs
network
access.
- The ``pip-requirements-parser`` library is a single file that can easily
be
copied around as needed for easy vendoring. This is useful as
requirements
parsing is often needed to bootstrap in a constrained environment.
- The ``pip-requirements-parser`` library has only one external dependency
on
the common "packaging" package. Otherwise it uses only the standard
library.
The benefits are the same as being a single file: fewer moving parts
|