requirementslib.models.requirements module

class requirementslib.models.requirements.FileRequirement(setup_path=None, path=None, editable=False, extras=NOTHING, uri_scheme=None, uri=NOTHING, link=NOTHING, pyproject_requires=NOTHING, pyproject_backend=None, pyproject_path=None, subdirectory=None, setup_info=None, has_hashed_name=False, parsed_line=None, name=NOTHING, req=NOTHING)[source]

Bases: object

File requirements for tar.gz installable files or wheels or setup.py containing directories.

dependencies
editable

Whether the package is editable

extras

Extras if applicable

formatted_path
classmethod from_line(line, editable=None, extras=None, parsed_line=None)[source]
classmethod from_pipfile(name, pipfile)[source]

Parse link information from given requirement line.

Return a 6-tuple:

  • vcs_type indicates the VCS to use (e.g. “git”), or None.
  • prefer is either “file”, “path” or “uri”, indicating how the
    information should be used in later stages.
  • relpath is the relative path to use when recording the dependency,
    instead of the absolute path/URI used to perform installation. This can be None (to prefer the absolute path or URI).
  • path is the absolute file path to the package. This will always use
    forward slashes. Can be None if the line is a remote URI.
  • uri is the absolute URI to the package. Can be None if the line is
    not a URI.
  • link is an instance of pip._internal.index.Link,
    representing a URI parse result based on the value of uri.

This function is provided to deal with edge cases concerning URIs without a valid netloc. Those URIs are problematic to a straight urlsplit` call because they cannot be reliably reconstructed with ``urlunsplit due to a bug in the standard library:

>>> from urllib.parse import urlsplit, urlunsplit
>>> urlunsplit(urlsplit('git+file:///this/breaks'))
'git+file:/this/breaks'
>>> urlunsplit(urlsplit('file:///this/works'))
'file:///this/works'

See https://bugs.python.org/issue23505#msg277350.

get_name()[source]
get_requirement()[source]
get_uri()[source]
is_direct_url
is_local
is_remote_artifact
line_part

Link object representing the package to clone

name

Package name

parsed_line
path

path to hit - without any of the VCS prefixes (like git+ / http+ / etc)

pipfile_part
pyproject_backend

PyProject Build System

pyproject_path

PyProject Path

pyproject_requires

PyProject Requirements

req

A Requirement instance

setup_info
setup_path

Path to the relevant setup.py location

setup_py_dir
subdirectory
uri

URI of the package

class requirementslib.models.requirements.Line(line, extras=None)[source]

Bases: object

base_path
get_ireq()[source]
get_line(with_prefix=False, with_markers=False, with_hashes=True, as_list=False)[source]
classmethod get_requirement_specs(specifierset)[source]
get_setup_info()[source]
get_url()[source]

Sets self.name if given a PEP-508 style URL.

ireq
is_artifact
is_direct_url
is_file
is_file_url
is_installable
is_named
is_path
is_remote_url
is_url
is_vcs
is_wheel
line_for_ireq
line_is_installable

This is a safeguard against decoy requirements when a user installs a package whose name coincides with the name of a folder in the cwd, e.g. install alembic when there is a folder called alembic in the working directory.

In this case we first need to check that the given requirement is a valid URL, VCS requirement, or installable filesystem path before deciding to treat it as a file requirement over a named requirement.

line_with_prefix
metadata
name
name_and_specifier
parse()[source]
parse_extras()[source]

Parse extras from self.line and set them on the current object :returns: self :rtype: Line

parse_hashes()[source]

Parse hashes from self.line and set them on the current object.

Returns:Self
Return type::class:~Line
parse_ireq()[source]
parse_markers()[source]
parse_name()[source]
parse_requirement()[source]
parsed_setup_cfg
parsed_setup_py
parsed_url
populate_setup_paths()[source]
pyproject_backend
pyproject_requires
pyproject_toml
ref
requirement
requirement_info

Generates a 3-tuple of the requisite name, extras and url to generate a Requirement out of.

Returns:A Tuple of an optional name, a Tuple of extras, and an optional URL.
Return type:Tuple[Optional[S], Tuple[Optional[S], ..], Optional[S]]
setup_cfg
setup_info
setup_py
specifier
specifiers
classmethod split_hashes(line)[source]
subdirectory
url
vcsrepo
wheel_kwargs
class requirementslib.models.requirements.LinkInfo(vcs_type, prefer, relpath, path, uri, link)

Bases: tuple

Alias for field number 5

path

Alias for field number 3

prefer

Alias for field number 1

relpath

Alias for field number 2

uri

Alias for field number 4

vcs_type

Alias for field number 0

class requirementslib.models.requirements.NamedRequirement(name, version, req=NOTHING, extras=NOTHING, editable=False, parsed_line=None)[source]

Bases: object

editable
extras
classmethod from_line(line, parsed_line=None)[source]
classmethod from_pipfile(name, pipfile)[source]
get_requirement()[source]
line_part
name
parsed_line
pipfile_part
req
version
class requirementslib.models.requirements.Requirement(name=NOTHING, vcs=None, req=None, markers=None, specifiers=NOTHING, index=None, editable=None, hashes=NOTHING, extras=NOTHING, abstract_dep=None, line_instance=None, ireq=None)[source]

Bases: object

add_hashes(hashes)[source]
as_ireq()[source]
as_line(sources=None, include_hashes=True, include_extras=True, include_markers=True, as_list=False)[source]

Format this requirement as a line in requirements.txt.

If sources provided, it should be an sequence of mappings, containing all possible sources to be used for this requirement.

If sources is omitted or falsy, no index information will be included in the requirement line.

as_pipfile()[source]
build_backend
commit_hash
constraint_line
copy()[source]
extras_as_pip
find_all_matches(sources=None, finder=None)[source]

Find all matching candidates for the current requirement.

Consults a finder to find all matching candidates.

Parameters:
  • sources – Pipfile-formatted sources, defaults to None
  • sources – list[dict], optional
  • finder (PackageFinder) – A PackageFinder instance from pip’s repository implementation
Returns:

A list of Installation Candidates

Return type:

list[ InstallationCandidate ]

classmethod from_ireq(ireq)[source]
classmethod from_line(line)[source]
classmethod from_metadata(name, version, extras, markers)[source]
classmethod from_pipfile(name, pipfile)[source]
get_abstract_dependencies(sources=None)[source]

Retrieve the abstract dependencies of this requirement.

Returns the abstract dependencies of the current requirement in order to resolve.

Parameters:
  • sources – A list of sources (pipfile format), defaults to None
  • sources – list, optional
Returns:

A list of abstract (unpinned) dependencies

Return type:

list[ AbstractDependency ]

get_dependencies(sources=None)[source]

Retrieve the dependencies of the current requirement.

Retrieves dependencies of the current requirement. This only works on pinned requirements.

Parameters:
  • sources – Pipfile-formatted sources, defaults to None
  • sources – list[dict], optional
Returns:

A set of requirement strings of the dependencies of this requirement.

Return type:

set(str)

get_hashes_as_pip(as_list=False)[source]
get_line_instance()[source]
get_markers()[source]
get_name()[source]
get_requirement()[source]
get_specifier()[source]
get_specifiers()[source]
get_version()[source]
hashes_as_pip
ireq
is_direct_url
is_file_or_url
is_named
is_vcs
is_wheel
line_instance
markers_as_pip
merge_markers(markers)[source]
name
normalized_name
pipfile_entry
requirement
run_requires(sources=None, finder=None)[source]
specifiers
update_name_from_path(path)[source]
uses_pep517
class requirementslib.models.requirements.VCSRequirement(setup_path=None, extras=NOTHING, uri_scheme=None, pyproject_requires=NOTHING, pyproject_backend=None, pyproject_path=None, subdirectory=None, setup_info=None, has_hashed_name=False, parsed_line=None, editable=None, uri=None, path=None, vcs=None, ref=None, repo=None, base_line=None, name=NOTHING, link=NOTHING, req=NOTHING)[source]

Bases: requirementslib.models.requirements.FileRequirement

editable

Whether the repository is editable

classmethod from_line(line, editable=None, extras=None, parsed_line=None)[source]
classmethod from_pipfile(name, pipfile)[source]
get_checkout_dir(src_dir=None)[source]
get_commit_hash()[source]
get_name()[source]
get_requirement()[source]
get_vcs_repo(src_dir=None, checkout_dir=None)[source]
line_part

requirements.txt compatible line part sans-extras.

locked_vcs_repo(src_dir=None)[source]
name
path

path to the repository, if it’s local

pipfile_part
ref

vcs reference name (branch / commit / tag)

repo
req
setup_info
update_repo(src_dir=None, ref=None)[source]
uri

URI for the repository

url
vcs

vcs type, i.e. git/hg/svn

vcs_uri
requirementslib.models.requirements.file_req_from_parsed_line(parsed_line)[source]
requirementslib.models.requirements.named_req_from_parsed_line(parsed_line)[source]
requirementslib.models.requirements.vcs_req_from_parsed_line(parsed_line)[source]