24
24
import attr
25
25
import license_expression
26
26
import packageurl
27
- import utils_pip_compatibility_tags
28
- import utils_pypi_supported_tags
29
27
import requests
30
28
import saneyaml
29
+ import utils_pip_compatibility_tags
30
+ import utils_pypi_supported_tags
31
31
32
32
from commoncode import fileutils
33
33
from commoncode .hash import multi_checksums
34
+ from commoncode .text import python_safe_name
34
35
from packaging import tags as packaging_tags
35
36
from packaging import version as packaging_version
36
37
from utils_requirements import load_requirements
@@ -172,11 +173,20 @@ def fetch_wheels(
172
173
else :
173
174
force_pinned = False
174
175
175
- rrp = list (get_required_remote_packages (
176
- requirements_file = requirements_file ,
177
- force_pinned = force_pinned ,
178
- remote_links_url = remote_links_url ,
179
- ))
176
+ try :
177
+ rrp = list (get_required_remote_packages (
178
+ requirements_file = requirements_file ,
179
+ force_pinned = force_pinned ,
180
+ remote_links_url = remote_links_url ,
181
+ ))
182
+ except Exception as e :
183
+ raise Exception (
184
+ dict (
185
+ requirements_file = requirements_file ,
186
+ force_pinned = force_pinned ,
187
+ remote_links_url = remote_links_url ,
188
+ )
189
+ ) from e
180
190
181
191
fetched_filenames = set ()
182
192
for name , version , package in rrp :
@@ -211,6 +221,7 @@ def fetch_wheels(
211
221
print (f'Missed package { nv } in remote repo, has only:' )
212
222
for pv in rr .get_versions (n ):
213
223
print (' ' , pv )
224
+ raise Exception ('Missed some packages in remote repo' )
214
225
215
226
216
227
def fetch_sources (
@@ -261,6 +272,8 @@ def fetch_sources(
261
272
fetched = package .fetch_sdist (dest_dir = dest_dir )
262
273
error = f'Failed to fetch' if not fetched else None
263
274
yield package , error
275
+ if missed :
276
+ raise Exception (f'Missing source packages in { remote_links_url } ' , missed )
264
277
265
278
################################################################################
266
279
#
@@ -693,8 +706,7 @@ def save_if_modified(location, content):
693
706
return False
694
707
695
708
if TRACE : print (f'Saving ABOUT (and NOTICE) files for: { self } ' )
696
- wmode = 'wb' if isinstance (content , bytes ) else 'w'
697
- with open (location , wmode , encoding = "utf-8" ) as fo :
709
+ with open (location , 'w' ) as fo :
698
710
fo .write (content )
699
711
return True
700
712
@@ -905,16 +917,16 @@ def load_pkginfo_data(self, dest_dir=THIRDPARTY_DIR):
905
917
other_classifiers = [c for c in classifiers if not c .startswith ('License' )]
906
918
907
919
holder = raw_data ['Author' ]
908
- holder_contact = raw_data ['Author-email' ]
909
- copyright = f'Copyright (c) { holder } <{ holder_contact } >'
920
+ holder_contact = raw_data ['Author-email' ]
921
+ copyright_statement = f'Copyright (c) { holder } <{ holder_contact } >'
910
922
911
923
pkginfo_data = dict (
912
924
name = raw_data ['Name' ],
913
925
declared_license = declared_license ,
914
926
version = raw_data ['Version' ],
915
927
description = raw_data ['Summary' ],
916
928
homepage_url = raw_data ['Home-page' ],
917
- copyright = copyright ,
929
+ copyright = copyright_statement ,
918
930
license_expression = license_expression ,
919
931
holder = holder ,
920
932
holder_contact = holder_contact ,
@@ -1845,7 +1857,7 @@ def get(self, path_or_url, as_text=True):
1845
1857
if not os .path .exists (cached ):
1846
1858
content = get_file_content (path_or_url = path_or_url , as_text = as_text )
1847
1859
wmode = 'w' if as_text else 'wb'
1848
- with open (cached , wmode , encoding = "utf-8" ) as fo :
1860
+ with open (cached , wmode ) as fo :
1849
1861
fo .write (content )
1850
1862
return content
1851
1863
else :
@@ -1857,7 +1869,7 @@ def put(self, filename, content):
1857
1869
"""
1858
1870
cached = os .path .join (self .directory , filename )
1859
1871
wmode = 'wb' if isinstance (content , bytes ) else 'w'
1860
- with open (cached , wmode , encoding = "utf-8" ) as fo :
1872
+ with open (cached , wmode ) as fo :
1861
1873
fo .write (content )
1862
1874
1863
1875
@@ -2331,7 +2343,7 @@ def get_required_remote_packages(
2331
2343
repo = get_remote_repo (remote_links_url = remote_links_url )
2332
2344
else :
2333
2345
# a local path
2334
- assert os .path .exists (remote_links_url )
2346
+ assert os .path .exists (remote_links_url ), f'Path does not exist: { remote_links_url } '
2335
2347
repo = get_local_repo (directory = remote_links_url )
2336
2348
2337
2349
for name , version in required_name_versions :
@@ -2365,7 +2377,7 @@ def update_requirements(name, version=None, requirements_file='requirements.txt'
2365
2377
updated_name_versions = sorted (updated_name_versions )
2366
2378
nvs = '\n ' .join (f'{ name } =={ version } ' for name , version in updated_name_versions )
2367
2379
2368
- with open (requirements_file , 'w' , encoding = "utf-8" ) as fo :
2380
+ with open (requirements_file , 'w' ) as fo :
2369
2381
fo .write (nvs )
2370
2382
2371
2383
@@ -2383,7 +2395,7 @@ def hash_requirements(dest_dir=THIRDPARTY_DIR, requirements_file='requirements.t
2383
2395
raise Exception (f'Missing required package { name } =={ version } ' )
2384
2396
hashed .append (package .specifier_with_hashes )
2385
2397
2386
- with open (requirements_file , 'w' , encoding = "utf-8" ) as fo :
2398
+ with open (requirements_file , 'w' ) as fo :
2387
2399
fo .write ('\n ' .join (hashed ))
2388
2400
2389
2401
################################################################################
@@ -2961,5 +2973,6 @@ def compute_normalized_license_expression(declared_licenses):
2961
2973
from packagedcode import pypi
2962
2974
return pypi .compute_normalized_license (declared_licenses )
2963
2975
except ImportError :
2964
- # Scancode is not installed, we join all license strings and return it
2965
- return ' ' .join (declared_licenses )
2976
+ # Scancode is not installed, clean and join all the licenses
2977
+ lics = [python_safe_name (l ).lower () for l in declared_licenses ]
2978
+ return ' AND ' .join (lics ).lower ()
0 commit comments