Skip to content

Commit

Permalink
Use reST docstring formatting where appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
chrysle committed May 12, 2024
1 parent ec43859 commit ec56341
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
42 changes: 29 additions & 13 deletions piptools/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ class BaseResolver(metaclass=ABCMeta):

@abstractmethod
def resolve(self, max_rounds: int) -> set[InstallRequirement]:
"""
r"""
Find concrete package versions for all the given InstallRequirements
and their recursive dependencies and return a set of pinned
``InstallRequirement``'s.
and their recursive dependencies.
:returns: a set of pinned ``InstallRequirement``\ s.
"""

def resolve_hashes(
Expand Down Expand Up @@ -199,9 +199,24 @@ def __init__(
allow_unsafe: bool = False,
unsafe_packages: set[str] | None = None,
) -> None:
"""
Make sure the legacy resolver is enabled and no backtracking resolver
is present.
"""Initialize LegacyResolver.
:param constraints: the constraints given
:type constraints: Iterable[InstallRequirement]
:param existing_constraints: constraints already present
:param repository: the repository to get the constraints from
:type repository: BaseRepository
:param cache: the cache to be used
:param prereleases: whether prereleases should be taken into account when resolving
(default is :py:data:`False`)
:param clear_caches: whether to clear repository and dependency caches before resolving
(default is :py:data:`False`)
:param allow_unsafe: whether unsafe packages should be allowed in the resulting requirements
(default is :py:data:`False`)
:param unsafe_packages: packages to be considered as unsafe
(default is :py:data:`None`)
:type unsafe_packages: set[str]
:raises: ``PipToolsError`` if the legacy resolver is not enabled
"""
self.our_constraints = set(constraints)
self.their_constraints: set[InstallRequirement] = set()
Expand Down Expand Up @@ -230,13 +245,14 @@ def constraints(self) -> set[InstallRequirement]:

def resolve(self, max_rounds: int = 10) -> set[InstallRequirement]:
r"""
Find concrete package versions for all the given InstallRequirements
Find concrete package versions for all the given ``InstallRequirement``\ s
and their recursive dependencies and return a set of pinned
``InstallRequirement``\ s.
Resolves constraints one round at a time, until they don't change
anymore. Protects against infinite loops by breaking out after a max
number rounds.
anymore.
:param max_rounds: break out of resolution process after the given number of rounds
to prevent infinite loops (default is 10)
"""
if self.clear_caches:
self.dependency_cache.clear()
Expand Down Expand Up @@ -324,7 +340,7 @@ def _resolve_one_round(self) -> tuple[bool, set[InstallRequirement]]:
package versions. Some of these constraints may be new
or updated.
Returns whether new constraints appeared in this round. If no
:returns: whether new constraints appeared in this round. If no
constraints were added or changed, this indicates a stable
configuration.
"""
Expand Down Expand Up @@ -536,8 +552,8 @@ def resolve(self, max_rounds: int = 10) -> set[InstallRequirement]:
Resolve given ireqs.
Find concrete package versions for all the given InstallRequirements
and their recursive dependencies and return a set of pinned
``InstallRequirement``\ s.
and their recursive dependencies.
:returns: a set of pinned ``InstallRequirement``\ s.
"""
with update_env_context_manager(
PIP_EXISTS_ACTION="i"
Expand Down Expand Up @@ -644,7 +660,7 @@ def _do_resolve(
"""
Resolve dependencies based on resolvelib ``Resolver``.
Return :py:data:`True` on successful resolution, otherwise remove problematic
:returns: :py:data:`True` on successful resolution, otherwise remove problematic
requirements from existing constraints and return false.
"""
try:
Expand Down
7 changes: 4 additions & 3 deletions piptools/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@
def dependency_tree(
installed_keys: Mapping[str, Distribution], root_key: str
) -> set[str]:
"""Calculate the dependency tree for a package
"""Calculate the dependency tree for a package.
Return a collection of all of the package's dependencies.
Uses a DFS traversal algorithm.
``installed_keys`` should be a {key: requirement} mapping, e.g.
{'django': from_line('django==1.8')}
``root_key`` should be the key to return the dependency tree for.
:param root_key: the key to return the dependency tree for
:type root_key: str
"""
dependencies = set()
queue: Deque[Distribution] = collections.deque()
Expand Down Expand Up @@ -127,7 +128,7 @@ def diff_key_from_ireq(ireq: InstallRequirement) -> str:
For URL requirements, only provide a useful key if the url includes
a hash, e.g. #sha1=..., in any of the supported hash algorithms.
Otherwise return ireq.link so the key will not match and the package will
Otherwise return ``ireq.link`` so the key will not match and the package will
reinstall. Reinstall is necessary to ensure that packages will reinstall
if the contents at the URL have changed but the version has not.
"""
Expand Down
2 changes: 1 addition & 1 deletion piptools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ def override_defaults_from_config_file(
file, returning the ``pathlib.Path`` of that config file if specified or
discovered.
Return :py:data:`None` if no such file is found.
:returns: :py:data:`None` if no such file is found.
``pip-tools`` will use the first config file found, searching in this order:
an explicitly given config file, a ``.pip-tools.toml``, a ``pyproject.toml``
Expand Down

0 comments on commit ec56341

Please sign in to comment.