File tree Expand file tree Collapse file tree 2 files changed +18
-17
lines changed
Expand file tree Collapse file tree 2 files changed +18
-17
lines changed Original file line number Diff line number Diff line change @@ -35,23 +35,24 @@ def get_download_url(purl: str):
3535 if not p .name or not p .version :
3636 return None
3737
38- try :
39- parsed_name = urllib .parse .quote (p .name )
40- parsed_version = urllib .parse .quote (p .version )
41- api = f"https://fastapi.metacpan.org/v1/release/{ parsed_name } /{ parsed_version } "
38+ parsed_name = urllib .parse .quote (p .name )
39+ parsed_version = urllib .parse .quote (p .version )
40+ api = f"https://fastapi.metacpan.org/v1/release/{ parsed_name } /{ parsed_version } "
41+ if _http_exists (api ):
42+ # Fetch release data from MetaCPAN API
43+ # Example: https://fastapi.metacpan.org/v1/release/Some-Module/1.2.3
4244 data = fetch_json_response (url = api )
4345 url = data .get ("download_url" ) or data .get ("archive" )
4446 if url and _http_exists (url ):
4547 return url
46- except Exception :
47- pass
4848
4949 author = p .namespace
50- if author :
51- auth = author .upper ()
52- a = auth [0 ]
53- ab = auth [:2 ] if len (auth ) >= 2 else auth
54- for ext in (".tar.gz" , ".zip" ):
55- url = f"https://cpan.metacpan.org/authors/id/{ a } /{ ab } /{ auth } /{ p .name } -{ p .version } { ext } "
56- if _http_exists (url ):
57- return url
50+ if not author :
51+ return
52+ auth = author .upper ()
53+ a = auth [0 ]
54+ ab = auth [:2 ] if len (auth ) >= 2 else auth
55+ for ext in (".tar.gz" , ".zip" ):
56+ url = f"https://cpan.metacpan.org/authors/id/{ a } /{ ab } /{ auth } /{ p .name } -{ p .version } { ext } "
57+ if _http_exists (url ):
58+ return url
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ def test_success_from_metacpan_api(valid_purl):
3939 result = get_download_url (valid_purl )
4040 assert result == expected_url
4141 mock_fetch .assert_called_once ()
42- mock_exists .assert_called_once_with ( expected_url )
42+ assert mock_exists .call_count == 2
4343
4444
4545def test_fallback_to_author_path (valid_purl ):
@@ -68,7 +68,7 @@ def test_author_zip_fallback(valid_purl):
6868
6969 result = get_download_url (valid_purl )
7070 assert result == zip_url
71- assert mock_exists .call_count == 2
71+ assert mock_exists .call_count == 3
7272 assert tar_url in [call [0 ][0 ] for call in mock_exists .call_args_list ]
7373
7474
@@ -79,7 +79,7 @@ def test_neither_api_nor_fallback_works(valid_purl):
7979
8080 result = get_download_url (valid_purl )
8181 assert result is None
82- assert mock_exists .call_count == 2
82+ assert mock_exists .call_count == 3
8383
8484
8585def test_missing_name_or_version ():
You can’t perform that action at this time.
0 commit comments