Skip to content

Commit 866e3f4

Browse files
committed
Add documentation for --prefer-source option
Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
1 parent e8993cc commit 866e3f4

5 files changed

Lines changed: 24 additions & 11 deletions

File tree

CHANGELOG.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ Changelog
55
v0.9.1
66
------
77

8-
- Add --prefer-source option.
8+
- Add --prefer-source option, to prefer source packages over binary ones
9+
if no source distribution is available then binary distributions are used.
910

1011

1112
v0.9.0

docs/source/dependencies-design.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ repositories.
223223
PyPI "simple" API. Both the "simple" API and the PyPI JSON
224224
"warehouse-style" API are supported.
225225

226+
- ``--prefer-source``: when set, prefer source distribution instead
227+
of binary distribution. In case there is no source distribution
228+
available, the tool should provide binary distribution.
226229

227230
Strategy and error processing:
228231
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

src/python_inspector/package_data.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ def get_pypi_data_from_purl(
3333
``purl`` is a package-url of pypi type
3434
``environment`` is a `Environment` object defaulting Python version 3.8 and linux OS
3535
``repos`` is a list of `PypiSimpleRepository` objects
36+
``prefer_source`` is a boolean value to prefer source distribution over wheel,
37+
if no source distribution is available then wheel is used
3638
"""
3739
purl = PackageURL.from_string(purl)
3840
name = purl.name
@@ -53,7 +55,18 @@ def get_pypi_data_from_purl(
5355
bug_tracking_url = get_pypi_bugtracker_url(project_urls)
5456
python_version = get_python_version_from_env_tag(python_version=environment.python_version)
5557
valid_distribution_urls = []
56-
if not prefer_source:
58+
59+
valid_distribution_urls.append(
60+
get_sdist_download_url(
61+
purl=purl,
62+
repos=repos,
63+
python_version=python_version,
64+
)
65+
)
66+
67+
# if prefer_source is True then only source distribution is used
68+
# in case of no source distribution available then wheel is used
69+
if not valid_distribution_urls or not prefer_source:
5770
valid_distribution_urls.extend(
5871
list(
5972
get_wheel_download_urls(
@@ -64,13 +77,7 @@ def get_pypi_data_from_purl(
6477
)
6578
)
6679
)
67-
valid_distribution_urls.append(
68-
get_sdist_download_url(
69-
purl=purl,
70-
repos=repos,
71-
python_version=python_version,
72-
)
73-
)
80+
7481
urls = response.get("urls") or []
7582
for url in urls:
7683
dist_url = url.get("url")

src/python_inspector/resolve_cli.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ def print_version(ctx, param, value):
154154
@click.option(
155155
"--prefer-source",
156156
is_flag=True,
157-
help="Prefer source distributions over binary distributions.",
157+
help="Prefer source distributions over binary distributions"
158+
" if no source distribution is available then binary distributions are used",
158159
)
159160
@click.option(
160161
"--verbose",
@@ -203,6 +204,7 @@ def resolve_dependencies(
203204
to PyPI.org.
204205
205206
Provide source distributions over binary distributions with the --prefer-source
207+
option. If no source distribution is available then binary distributions are used.
206208
207209
Error and progress are printed to stderr.
208210

src/python_inspector/utils_pypi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ def download_sdist(
336336
fetched_sdist_filename = None
337337

338338
for repo in repos:
339-
sdist = get_valid_sdist(repo, name, version, python_version=DEFAULT_PYTHON_VERSION)
339+
sdist = get_valid_sdist(repo, name, version, python_version=python_version)
340340
if not sdist:
341341
if TRACE_DEEP:
342342
print(f" download_sdist: No valid sdist for {name}=={version}")

0 commit comments

Comments
 (0)