Skip to content

Commit d7b0e8b

Browse files
authored
Merge pull request #2060 from chrysle/add-api-docs
Add private API documentation
2 parents 3c560cf + e3e9247 commit d7b0e8b

File tree

14 files changed

+187
-86
lines changed

14 files changed

+187
-86
lines changed

docs/conf.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@
3636
# Add any Sphinx extension module names here, as strings. They can be
3737
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3838
# ones.
39-
extensions = ["myst_parser", "sphinxcontrib.programoutput"]
39+
extensions = [
40+
# Stdlib extensions:
41+
"sphinx.ext.intersphinx",
42+
# Third-party extensions:
43+
"myst_parser",
44+
"sphinxcontrib.apidoc",
45+
"sphinxcontrib.programoutput",
46+
]
4047

4148

4249
# -- Options for HTML output -------------------------------------------------
@@ -48,6 +55,14 @@
4855
html_title = f"<nobr>{project}</nobr> documentation v{release}"
4956

5057

58+
# -- Options for intersphinx ----------------------------------------------------------
59+
# https://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html#configuration
60+
61+
intersphinx_mapping = {
62+
"python": ("https://docs.python.org/3", None),
63+
}
64+
65+
5166
# -------------------------------------------------------------------------
5267
default_role = "any"
5368
nitpicky = True
@@ -57,4 +72,30 @@
5772
r"^https://img.shields.io/matrix",
5873
]
5974

75+
nitpick_ignore_regex = [
76+
("py:class", "pip.*"),
77+
("py:class", "pathlib.*"),
78+
("py:class", "click.*"),
79+
("py:class", "build.*"),
80+
("py:class", "optparse.*"),
81+
("py:class", "_ImportLibDist"),
82+
("py:class", "PackageMetadata"),
83+
("py:class", "importlib.*"),
84+
("py:class", "IndexContent"),
85+
("py:exc", "click.*"),
86+
]
87+
6088
suppress_warnings = ["myst.xref_missing"]
89+
90+
# -- Apidoc options -------------------------------------------------------
91+
92+
apidoc_excluded_paths: list[str] = []
93+
apidoc_extra_args = [
94+
"--implicit-namespaces",
95+
"--private", # include “_private” modules
96+
]
97+
apidoc_module_first = False
98+
apidoc_module_dir = "../piptools"
99+
apidoc_output_dir = "pkg"
100+
apidoc_separate_modules = True
101+
apidoc_toc_file = None

docs/index.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,10 @@ cli/index
1313
contributing
1414
changelog
1515
```
16+
17+
```{toctree}
18+
:hidden:
19+
:caption: Private API reference
20+
21+
pkg/modules
22+
```

docs/pkg/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

docs/requirements.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ furo
22
myst-parser
33
setuptools-scm
44
sphinx
5+
sphinxcontrib-apidoc
56
sphinxcontrib-programoutput

docs/requirements.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This file is autogenerated by pip-compile with Python 3.11
33
# by the following command:
44
#
5-
# pip-compile --allow-unsafe --strip-extras docs/requirements.in
5+
# pip-compile --allow-unsafe --strip-extras requirements.in
66
#
77
alabaster==0.7.13
88
# via sphinx
@@ -44,6 +44,8 @@ packaging==23.1
4444
# via
4545
# setuptools-scm
4646
# sphinx
47+
pbr==6.0.0
48+
# via sphinxcontrib-apidoc
4749
pygments==2.16.1
4850
# via
4951
# furo
@@ -64,6 +66,7 @@ sphinx==7.2.2
6466
# furo
6567
# myst-parser
6668
# sphinx-basic-ng
69+
# sphinxcontrib-apidoc
6770
# sphinxcontrib-applehelp
6871
# sphinxcontrib-devhelp
6972
# sphinxcontrib-htmlhelp
@@ -72,6 +75,8 @@ sphinx==7.2.2
7275
# sphinxcontrib-serializinghtml
7376
sphinx-basic-ng==1.0.0b2
7477
# via furo
78+
sphinxcontrib-apidoc==0.5.0
79+
# via -r requirements.in
7580
sphinxcontrib-applehelp==1.0.7
7681
# via sphinx
7782
sphinxcontrib-devhelp==1.0.5

piptools/_compat/pip_compat.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,12 @@ def _from_pkg_resources(cls, dist: _PkgResourcesDist) -> Distribution:
5050

5151
@classmethod
5252
def _from_importlib(cls, dist: _ImportLibDist) -> Distribution:
53-
"""Mimics pkg_resources.Distribution.requires for the case of no
54-
extras. This doesn't fulfill that API's `extras` parameter but
55-
satisfies the needs of pip-tools."""
53+
"""Mimic pkg_resources.Distribution.requires for the case of no
54+
extras.
55+
56+
This doesn't fulfill that API's ``extras`` parameter but
57+
satisfies the needs of pip-tools.
58+
"""
5659
reqs = (Requirement.parse(req) for req in (dist._dist.requires or ()))
5760
requires = [
5861
req
@@ -63,6 +66,8 @@ def _from_importlib(cls, dist: _ImportLibDist) -> Distribution:
6366

6467

6568
class FileLink(Link): # type: ignore[misc]
69+
"""Wrapper for ``pip``'s ``Link`` class."""
70+
6671
_url: str
6772

6873
@property

piptools/cache.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
def _implementation_name() -> str:
2323
"""
24+
Get Python implementation and version.
25+
2426
Similar to PEP 425, however the minor version is separated from the major to
2527
differentiate "3.10" and "31.0".
2628
"""
@@ -57,7 +59,8 @@ def read_cache_file(cache_file_path: str) -> CacheDict:
5759

5860
class DependencyCache:
5961
"""
60-
Creates a new persistent dependency cache for the current Python version.
62+
Create new persistent dependency cache for the current Python version.
63+
6164
The cache file is written to the appropriate user cache dir for the
6265
current platform, i.e.
6366
@@ -89,7 +92,9 @@ def cache(self) -> CacheDict:
8992

9093
def as_cache_key(self, ireq: InstallRequirement) -> CacheKey:
9194
"""
92-
Given a requirement, return its cache key. This behavior is a little weird
95+
Given a requirement, return its cache key.
96+
97+
This behavior is a little weird
9398
in order to allow backwards compatibility with cache files. For a requirement
9499
without extras, this will return, for example:
95100
@@ -108,7 +113,7 @@ def as_cache_key(self, ireq: InstallRequirement) -> CacheKey:
108113
return name, f"{version}{extras_string}"
109114

110115
def write_cache(self) -> None:
111-
"""Writes the cache to disk as JSON."""
116+
"""Write the cache to disk as JSON."""
112117
doc = {"__format__": 1, "dependencies": self._cache}
113118
with open(self._cache_file, "w", encoding="utf-8") as f:
114119
json.dump(doc, f, sort_keys=True)
@@ -135,7 +140,7 @@ def reverse_dependencies(
135140
self, ireqs: Iterable[InstallRequirement]
136141
) -> dict[str, set[str]]:
137142
"""
138-
Returns a lookup table of reverse dependencies for all the given ireqs.
143+
Return a lookup table of reverse dependencies for all the given ireqs.
139144
140145
Since this is all static, it only works if the dependency cache
141146
contains the complete data, otherwise you end up with a partial view.
@@ -149,7 +154,7 @@ def _reverse_dependencies(
149154
self, cache_keys: Iterable[tuple[str, str]]
150155
) -> dict[str, set[str]]:
151156
"""
152-
Returns a lookup table of reverse dependencies for all the given cache keys.
157+
Return a lookup table of reverse dependencies for all the given cache keys.
153158
154159
Example input:
155160

piptools/repositories/local.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def ireq_satisfied_by_existing_pin(
2121
ireq: InstallRequirement, existing_pin: InstallationCandidate
2222
) -> bool:
2323
"""
24-
Return True if the given InstallationRequirement is satisfied by the
24+
Return :py:data:`True` if the given ``InstallRequirement`` is satisfied by the
2525
previously encountered version pin.
2626
"""
2727
version = next(iter(existing_pin.req.specifier)).version

0 commit comments

Comments
 (0)