diff options
Diffstat (limited to 'generate_release.py')
| -rw-r--r-- | generate_release.py | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/generate_release.py b/generate_release.py index 5ee0a51..76c979d 100644 --- a/generate_release.py +++ b/generate_release.py @@ -33,7 +33,7 @@ def check_subp(x): raise Exception('Got nonzero exit code from command') def log(line): - print('[generate_release.py] ' + line) + print(f'[generate_release.py] {line}') # https://stackoverflow.com/questions/7833715/python-deleting-certain-file-extensions def remove_files_with_extensions(path, extensions): @@ -43,23 +43,23 @@ def remove_files_with_extensions(path, extensions): os.remove(os.path.join(root, file)) def download_if_not_exists(file_name, url, sha256=None): - if not os.path.exists('./' + file_name): + if not os.path.exists(f'./{file_name}'): # Reject non-https URLs so a mistaken constant cannot cause a # plaintext download (bandit B310 hardening). if not url.startswith('https://'): - raise Exception('Refusing to download over non-https URL: ' + url) - log('Downloading ' + file_name + '..') + raise Exception(f'Refusing to download over non-https URL: {url}') + log(f'Downloading {file_name}..') data = urllib.request.urlopen(url).read() - log('Finished downloading ' + file_name) - with open('./' + file_name, 'wb') as f: + log(f'Finished downloading {file_name}') + with open(f'./{file_name}', 'wb') as f: f.write(data) if sha256: digest = hashlib.sha256(data).hexdigest() if digest != sha256: - log('Error: ' + file_name + ' has wrong hash: ' + digest) + log(f'Error: {file_name} has wrong hash: {digest}') sys.exit(1) else: - log('Using existing ' + file_name) + log(f'Using existing {file_name}') def wine_run_shell(command): # Keep argv-style invocation (no shell) to avoid command injection. @@ -120,7 +120,7 @@ if len(os.listdir('./yt-local')) == 0: # ----------- Generate embedded python distribution ----------- os.environ['PYTHONDONTWRITEBYTECODE'] = '1' # *.pyc files double the size of the distribution get_pip_url = 'https://bootstrap.pypa.io/get-pip.py' -latest_dist_url = 'https://www.python.org/ftp/python/' + latest_version + '/python-' + latest_version +latest_dist_url = f'https://www.python.org/ftp/python/{latest_version}/python-{latest_version}' if bitness == '32': latest_dist_url += '-embed-win32.zip' else: @@ -142,7 +142,7 @@ else: download_if_not_exists('get-pip.py', get_pip_url) -python_dist_name = 'python-dist-' + latest_version + '-' + bitness + '.zip' +python_dist_name = f'python-dist-{latest_version}-{bitness}.zip' download_if_not_exists(python_dist_name, latest_dist_url) download_if_not_exists(visual_c_name, @@ -203,7 +203,7 @@ and replaced with a .pth. Isolated mode will have to be specified manually. log('Removing ._pth') major_release = latest_version.split('.')[1] -os.remove(r'./python/python3' + major_release + '._pth') +os.remove(rf'./python/python3{major_release}._pth') log('Adding path_fixes.pth') with open(r'./python/path_fixes.pth', 'w', encoding='utf-8') as f: @@ -214,7 +214,7 @@ with open(r'./python/path_fixes.pth', 'w', encoding='utf-8') as f: # Need to add the directory where packages are installed, # and the parent directory (which is where the yt-local files are) major_release = latest_version.split('.')[1] -with open('./python/python3' + major_release + '._pth', 'a', encoding='utf-8') as f: +with open(rf'./python/python3{major_release}._pth', 'a', encoding='utf-8') as f: f.write('.\\Lib\\site-packages\n') f.write('..\n')''' @@ -255,10 +255,10 @@ log('Copying python distribution into release folder') shutil.copytree(r'./python', r'./yt-local/python') # ----------- Create release zip ----------- -output_filename = 'yt-local-' + release_tag + '-' + suffix + '.zip' -if os.path.exists('./' + output_filename): +output_filename = f'yt-local-{release_tag}-{suffix}.zip' +if os.path.exists(f'./{output_filename}'): log('Removing previous zipped release') - os.remove('./' + output_filename) + os.remove(f'./{output_filename}') log('Zipping release') check_subp(subprocess.run(['7z', '-mx=9', 'a', output_filename, './yt-local'])) |
