@@ -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" )
0 commit comments