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
get_link_from_line
(line)[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.
- link is an instance of
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.
-
is_direct_url
¶
-
is_local
¶
-
is_remote_artifact
¶
-
line_part
¶
-
link
¶ 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
¶
-
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
¶
-
link
¶
-
metadata
¶
-
name
¶
-
name_and_specifier
¶
-
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
-
parsed_setup_cfg
¶
-
parsed_setup_py
¶
-
parsed_url
¶
-
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
¶
-
subdirectory
¶
-
url
¶
-
vcsrepo
¶
-
wheel_kwargs
¶
-
-
class
requirementslib.models.requirements.
LinkInfo
(vcs_type, prefer, relpath, path, uri, link)¶ Bases:
tuple
-
link
¶ 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
¶
-
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
-
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.
-
build_backend
¶
-
commit_hash
¶
-
constraint_line
¶
-
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
]
-
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:
-
hashes_as_pip
¶
-
ireq
¶
-
is_direct_url
¶
-
is_file_or_url
¶
-
is_named
¶
-
is_vcs
¶
-
is_wheel
¶
-
line_instance
¶
-
markers_as_pip
¶
-
name
¶
-
normalized_name
¶
-
pipfile_entry
¶
-
requirement
¶
-
specifiers
¶
-
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
-
line_part
¶ requirements.txt compatible line part sans-extras.
-
link
¶
-
name
¶
-
path
¶ path to the repository, if it’s local
-
pipfile_part
¶
-
ref
¶ vcs reference name (branch / commit / tag)
-
repo
¶
-
req
¶
-
setup_info
¶
-
uri
¶ URI for the repository
-
url
¶
-
vcs
¶ vcs type, i.e. git/hg/svn
-
vcs_uri
¶
-