Skip to content

Commit 9a95beb

Browse files
committed
Assorted documentation improvements
1 parent 69628b1 commit 9a95beb

File tree

6 files changed

+46
-38
lines changed

6 files changed

+46
-38
lines changed

README.rst

+6-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ Installation
5454
.. _tqdm: https://tqdm.github.io
5555

5656

57-
Example
58-
=======
57+
Examples
58+
========
5959

6060
Get information about a package:
6161

@@ -88,3 +88,7 @@ Download a package with a tqdm progress bar:
8888
client.download_package(
8989
pkg, path=pkg.filename, progress=tqdm_progress_factory(),
9090
)
91+
92+
`See more examples in the docs.`__
93+
94+
__ https://pypi-simple.readthedocs.io/en/stable/examples.html

docs/examples.rst

+14-11
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,28 @@ their metadata "backfilled" in; see
1515
.. code:: python
1616
1717
# Requirements:
18-
# Python 3.8+
1918
# packaging 23.1+
20-
# pypi_simple 1.3+
19+
# pypi_simple 1.5+
2120
2221
from packaging.metadata import parse_email
23-
from pypi_simple import PyPISimple
22+
from pypi_simple import NoMetadataError, PyPISimple
2423
2524
with PyPISimple() as client:
2625
page = client.get_project_page("pypi-simple")
2726
for pkg in page.packages:
28-
if pkg.has_metadata:
29-
src = client.get_package_metadata(pkg)
30-
md, _ = parse_email(src)
31-
if deps := md.get("requires_dist"):
32-
print(f"Dependencies for {pkg.filename}:")
33-
for d in deps:
34-
print(f" {d}")
27+
if pkg.has_metadata is not False:
28+
try:
29+
src = client.get_package_metadata(pkg)
30+
except NoMetadataError:
31+
print(f"{pkg.filename}: No metadata available")
3532
else:
36-
print(f"Dependencies for {pkg.filename}: NONE")
33+
md, _ = parse_email(src)
34+
if deps := md.get("requires_dist"):
35+
print(f"Dependencies for {pkg.filename}:")
36+
for d in deps:
37+
print(f" {d}")
38+
else:
39+
print(f"Dependencies for {pkg.filename}: NONE")
3740
else:
3841
print(f"{pkg.filename}: No metadata available")
3942
print()

docs/index.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ Installation
4242
.. _tqdm: https://tqdm.github.io
4343

4444

45-
Example
46-
=======
45+
Examples
46+
========
4747

4848
Get information about a package:
4949

@@ -77,6 +77,7 @@ Download a package with a tqdm progress bar:
7777
pkg, path=pkg.filename, progress=tqdm_progress_factory(),
7878
)
7979
80+
:doc:`See more examples in the docs. <examples>`
8081

8182
Indices and tables
8283
==================

src/pypi_simple/classes.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ class DistributionPackage:
4242
#: The type of the package, or `None` if the filename cannot be parsed.
4343
#: The recognized package types are:
4444
#:
45-
#: - ``'dumb'``
46-
#: - ``'egg'``
47-
#: - ``'msi'``
48-
#: - ``'rpm'``
49-
#: - ``'sdist'``
50-
#: - ``'wheel'``
51-
#: - ``'wininst'``
45+
#: - ``"dumb"``
46+
#: - ``"egg"``
47+
#: - ``"msi"``
48+
#: - ``"rpm"``
49+
#: - ``"sdist"``
50+
#: - ``"wheel"``
51+
#: - ``"wininst"``
5252
package_type: Optional[str]
5353

5454
#: A collection of hash digests for the file as a `dict` mapping hash

src/pypi_simple/client.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,8 @@ def download_package(
326326
:param bool verify:
327327
whether to verify the package's digests against the downloaded file
328328
:param bool keep_on_error:
329-
whether to keep (true) or delete (false) the downloaded file if an
330-
error occurs
329+
whether to keep (true) or delete (false; default) the downloaded
330+
file if an error occurs
331331
:param progress: a callable for constructing a progress tracker
332332
:param timeout: optional timeout to pass to the ``requests`` call
333333
:type timeout: float | tuple[float,float] | None

src/pypi_simple/filenames.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -88,24 +88,24 @@ def parse_filename(
8888
spelled the same as they appear in the filename; no normalization is
8989
performed.
9090
91-
The package type may be any of the following strings:
91+
The package type will be one of the following strings:
9292
93-
- ``'dumb'``
94-
- ``'egg'``
95-
- ``'msi'``
96-
- ``'rpm'``
97-
- ``'sdist'``
98-
- ``'wheel'``
99-
- ``'wininst'``
93+
- ``"dumb"``
94+
- ``"egg"``
95+
- ``"msi"``
96+
- ``"rpm"``
97+
- ``"sdist"``
98+
- ``"wheel"``
99+
- ``"wininst"``
100100
101101
Note that some filenames (e.g., :file:`1-2-3.tar.gz`) may be ambiguous as
102102
to which part is the project name and which is the version. In order to
103-
resolve the ambiguity, the expected value for the project name (*modulo*
104-
normalization) can be supplied as the ``project_name`` argument to the
105-
function. If the filename can be parsed with the given string in the role
106-
of the project name, the results of that parse will be returned; otherwise,
107-
the function will fall back to breaking the project & version apart at an
108-
unspecified point.
103+
resolve the ambiguity, the expected value for the project name can be
104+
supplied as the ``project_name`` argument to the function; it need not be
105+
normalized. If the filename can be parsed with the given string in the
106+
role of the project name, the results of that parse will be returned;
107+
otherwise, the function will fall back to breaking the project & version
108+
apart at an unspecified point.
109109
110110
.. versionchanged:: 1.0.0
111111

0 commit comments

Comments
 (0)