Skip to content

Commit d2bafb9

Browse files
committed
Fixed #41 - Handled encoding issue when generating ABOUT files
Signed-off-by: Chin Yeung Li <tli@nexb.com>
1 parent d3b8524 commit d2bafb9

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

etc/scripts/utils_thirdparty.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,8 @@ def save_if_modified(location, content):
693693
return False
694694

695695
if TRACE: print(f'Saving ABOUT (and NOTICE) files for: {self}')
696-
with open(location, 'w') as fo:
696+
wmode = 'wb' if isinstance(content, bytes) else 'w'
697+
with open(location, wmode, encoding="utf-8") as fo:
697698
fo.write(content)
698699
return True
699700

@@ -725,6 +726,8 @@ def load_about_data(self, about_filename_or_data=None, dest_dir=THIRDPARTY_DIR):
725726
if os.path.exists(about_path):
726727
with open(about_path) as fi:
727728
about_data = saneyaml.load(fi.read())
729+
if not about_data:
730+
return False
728731
else:
729732
return False
730733
else:
@@ -1842,7 +1845,7 @@ def get(self, path_or_url, as_text=True):
18421845
if not os.path.exists(cached):
18431846
content = get_file_content(path_or_url=path_or_url, as_text=as_text)
18441847
wmode = 'w' if as_text else 'wb'
1845-
with open(cached, wmode) as fo:
1848+
with open(cached, wmode, encoding="utf-8") as fo:
18461849
fo.write(content)
18471850
return content
18481851
else:
@@ -1854,7 +1857,7 @@ def put(self, filename, content):
18541857
"""
18551858
cached = os.path.join(self.directory, filename)
18561859
wmode = 'wb' if isinstance(content, bytes) else 'w'
1857-
with open(cached, wmode) as fo:
1860+
with open(cached, wmode, encoding="utf-8") as fo:
18581861
fo.write(content)
18591862

18601863

@@ -2362,7 +2365,7 @@ def update_requirements(name, version=None, requirements_file='requirements.txt'
23622365
updated_name_versions = sorted(updated_name_versions)
23632366
nvs = '\n'.join(f'{name}=={version}' for name, version in updated_name_versions)
23642367

2365-
with open(requirements_file, 'w') as fo:
2368+
with open(requirements_file, 'w', encoding="utf-8") as fo:
23662369
fo.write(nvs)
23672370

23682371

@@ -2380,7 +2383,7 @@ def hash_requirements(dest_dir=THIRDPARTY_DIR, requirements_file='requirements.t
23802383
raise Exception(f'Missing required package {name}=={version}')
23812384
hashed.append(package.specifier_with_hashes)
23822385

2383-
with open(requirements_file, 'w') as fo:
2386+
with open(requirements_file, 'w', encoding="utf-8") as fo:
23842387
fo.write('\n'.join(hashed))
23852388

23862389
################################################################################

0 commit comments

Comments
 (0)