Skip to content

Commit

Permalink
Merge pull request #42 from nexB/41_fix_encoding_error
Browse files Browse the repository at this point in the history
Fixed #41 - Handled encoding issue when generating ABOUT files
  • Loading branch information
chinyeungli authored Oct 4, 2021
2 parents d3b8524 + d2bafb9 commit c41196a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions etc/scripts/utils_thirdparty.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,8 @@ def save_if_modified(location, content):
return False

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

Expand Down Expand Up @@ -725,6 +726,8 @@ def load_about_data(self, about_filename_or_data=None, dest_dir=THIRDPARTY_DIR):
if os.path.exists(about_path):
with open(about_path) as fi:
about_data = saneyaml.load(fi.read())
if not about_data:
return False
else:
return False
else:
Expand Down Expand Up @@ -1842,7 +1845,7 @@ def get(self, path_or_url, as_text=True):
if not os.path.exists(cached):
content = get_file_content(path_or_url=path_or_url, as_text=as_text)
wmode = 'w' if as_text else 'wb'
with open(cached, wmode) as fo:
with open(cached, wmode, encoding="utf-8") as fo:
fo.write(content)
return content
else:
Expand All @@ -1854,7 +1857,7 @@ def put(self, filename, content):
"""
cached = os.path.join(self.directory, filename)
wmode = 'wb' if isinstance(content, bytes) else 'w'
with open(cached, wmode) as fo:
with open(cached, wmode, encoding="utf-8") as fo:
fo.write(content)


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

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


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

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

################################################################################
Expand Down

0 comments on commit c41196a

Please sign in to comment.