From a1e1d98929be355b954349ab4247b26596d363d1 Mon Sep 17 00:00:00 2001 From: BrianPetkovsek <16124109+BrianPetkovsek@users.noreply.github.com> Date: Fri, 14 Jun 2019 21:11:31 -0400 Subject: [PATCH 1/3] Make pip_install function more flexible sys.executable gets the python.exe used to run the script -r allows pip to use requirements.txt --- bin/video2x_setup.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/bin/video2x_setup.py b/bin/video2x_setup.py index d5f814c..b9326bf 100644 --- a/bin/video2x_setup.py +++ b/bin/video2x_setup.py @@ -3,8 +3,9 @@ """ Name: Video2X Setup Script Author: K4YT3X +Author: BrianPetkovsek Date Created: November 28, 2018 -Last Modified: April 28, 2019 +Last Modified: June 14, 2019 Licensed under the GNU General Public License Version 3 (GNU GPL v3), available at: https://www.gnu.org/licenses/gpl-3.0.txt @@ -86,10 +87,7 @@ class Video2xSetup: def _install_python_requirements(self): """ Read requirements.txt and return its content """ - with open('requirements.txt', 'r') as req: - for line in req: - package = line.split('==')[0] - pip_install(package) + pip_install('requirements.txt') def _cleanup(self): """ Cleanup all the temp files downloaded @@ -201,13 +199,13 @@ def download(url, save_path, chunk_size=4096): return output_file -def pip_install(package): +def pip_install(file): """ Install python package via python pip module pip.main() is not available after pip 9.0.1, thus pip module is not used in this case. """ - return subprocess.run(['python', '-m', 'pip', 'install', '-U', package]).returncode + return subprocess.run([sys.executable, '-m', 'pip', 'install', '-U', '-r', file]).returncode if __name__ == "__main__": From b5da9ebbf7c9720011fe1f17f6698994d632b4c6 Mon Sep 17 00:00:00 2001 From: BrianPetkovsek <16124109+BrianPetkovsek@users.noreply.github.com> Date: Fri, 14 Jun 2019 21:37:38 -0400 Subject: [PATCH 2/3] make setup backwards compatible change the f'' to ''.format() --- bin/video2x_setup.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/bin/video2x_setup.py b/bin/video2x_setup.py index b9326bf..ad3434f 100644 --- a/bin/video2x_setup.py +++ b/bin/video2x_setup.py @@ -94,7 +94,7 @@ class Video2xSetup: """ for file in self.trash: try: - print(f'Deleting: {file}') + print('Deleting: {}'.format(file)) os.remove(file) except FileNotFoundError: pass @@ -108,7 +108,7 @@ class Video2xSetup: self.trash.append(ffmpeg_zip) with zipfile.ZipFile(ffmpeg_zip) as zipf: - zipf.extractall(f'{os.getenv("localappdata")}\\video2x') + zipf.extractall('{}\\video2x'.format(os.getenv("localappdata"))) def _install_waifu2x_caffe(self): """ Install waifu2x_caffe @@ -117,7 +117,7 @@ class Video2xSetup: import requests # Get latest release of waifu2x-caffe via GitHub API - latest_release = json.loads(requests.get('https://api.github.com/repos/lltcggie/waifu2x-caffe/releases/latest').content) + latest_release = json.loads(requests.get('https://api.github.com/repos/lltcggie/waifu2x-caffe/releases/latest').content.decode('utf-8')) for a in latest_release['assets']: if 'waifu2x-caffe.zip' in a['browser_download_url']: @@ -125,7 +125,7 @@ class Video2xSetup: self.trash.append(waifu2x_caffe_zip) with zipfile.ZipFile(waifu2x_caffe_zip) as zipf: - zipf.extractall(f'{os.getenv("localappdata")}\\video2x') + zipf.extractall('{}\\video2x'.format(os.getenv("localappdata"))) def _install_waifu2x_converter_cpp(self): """ Install waifu2x_caffe @@ -135,7 +135,7 @@ class Video2xSetup: import requests # Get latest release of waifu2x-caffe via GitHub API - latest_release = json.loads(requests.get('https://api.github.com/repos/DeadSix27/waifu2x-converter-cpp/releases/latest').content) + latest_release = json.loads(requests.get('https://api.github.com/repos/DeadSix27/waifu2x-converter-cpp/releases/latest').content.decode('utf-8')) for a in latest_release['assets']: if re.search(r'waifu2x-DeadSix27-win64_v[0-9]*\.zip', a['browser_download_url']): @@ -143,7 +143,7 @@ class Video2xSetup: self.trash.append(waifu2x_converter_cpp_zip) with zipfile.ZipFile(waifu2x_converter_cpp_zip) as zipf: - zipf.extractall(f'{os.getenv("localappdata")}\\video2x\\waifu2x-converter-cpp') + zipf.extractall('{}\\video2x\\waifu2x-converter-cpp'.format(os.getenv("localappdata"))) def _generate_config(self): """ Generate video2x config @@ -157,14 +157,14 @@ class Video2xSetup: # configure only the specified drivers if self.driver == 'all': - template_dict['waifu2x_caffe']['waifu2x_caffe_path'] = f'{local_app_data}\\video2x\\waifu2x-caffe\\waifu2x-caffe-cui.exe' - template_dict['waifu2x_converter']['waifu2x_converter_path'] = f'{local_app_data}\\video2x\\waifu2x-converter-cpp' + template_dict['waifu2x_caffe']['waifu2x_caffe_path'] = '{}\\video2x\\waifu2x-caffe\\waifu2x-caffe-cui.exe'.format(local_app_data) + template_dict['waifu2x_converter']['waifu2x_converter_path'] = '{}\\video2x\\waifu2x-converter-cpp'.format(local_app_data) elif self.driver == 'waifu2x_caffe': - template_dict['waifu2x_caffe']['waifu2x_caffe_path'] = f'{local_app_data}\\video2x\\waifu2x-caffe\\waifu2x-caffe-cui.exe' + template_dict['waifu2x_caffe']['waifu2x_caffe_path'] = '{}\\video2x\\waifu2x-caffe\\waifu2x-caffe-cui.exe'.format(local_app_data) elif self.driver == 'waifu2x_converter': - template_dict['waifu2x_converter']['waifu2x_converter_path'] = f'{local_app_data}\\video2x\\waifu2x-converter-cpp' + template_dict['waifu2x_converter']['waifu2x_converter_path'] = '{}\\video2x\\waifu2x-converter-cpp'.format(local_app_data) - template_dict['ffmpeg']['ffmpeg_path'] = f'{local_app_data}\\video2x\\ffmpeg-latest-win64-static\\bin' + template_dict['ffmpeg']['ffmpeg_path'] = '{}\\video2x\\ffmpeg-latest-win64-static\\bin'.format(local_app_data) template_dict['video2x']['video2x_cache_directory'] = None template_dict['video2x']['preserve_frames'] = False @@ -180,10 +180,10 @@ def download(url, save_path, chunk_size=4096): from tqdm import tqdm import requests - output_file = f'{save_path}\\{url.split("/")[-1]}' - print(f'Downloading: {url}') - print(f'Chunk size: {chunk_size}') - print(f'Saving to: {output_file}') + output_file = '{}\\{}'.format(save_path, url.split("/")[-1]) + print('Downloading: {}'.format(url)) + print('Chunk size: {}'.format(chunk_size)) + print('Saving to: {}'.format(output_file)) stream = requests.get(url, stream=True) total_size = int(stream.headers['content-length']) @@ -212,7 +212,7 @@ if __name__ == "__main__": try: args = process_arguments() print('Video2X Setup Script') - print(f'Version: {VERSION}') + print('Version: {}'.format(VERSION)) # do not install pip modules if script # is packaged in exe format From 9d5ad2f70c29e884b794cad0f14e117a6ea31861 Mon Sep 17 00:00:00 2001 From: BrianPetkovsek <16124109+BrianPetkovsek@users.noreply.github.com> Date: Fri, 14 Jun 2019 21:43:18 -0400 Subject: [PATCH 3/3] make video2x backwards compatible adds future-fstrings package transforms the source to .format() format on runtime --- bin/exceptions.py | 2 +- bin/ffmpeg.py | 2 +- bin/image_cleaner.py | 2 +- bin/requirements.txt | 1 + bin/upscaler.py | 2 +- bin/video2x.py | 2 +- bin/waifu2x_caffe.py | 2 +- bin/waifu2x_converter.py | 2 +- 8 files changed, 8 insertions(+), 7 deletions(-) diff --git a/bin/exceptions.py b/bin/exceptions.py index c5c5637..685bf67 100644 --- a/bin/exceptions.py +++ b/bin/exceptions.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# -*- code:utf-8 -*- +# -*- coding: future_fstrings -*- """ Name: Video2X Exceptions Dev: K4YT3X diff --git a/bin/ffmpeg.py b/bin/ffmpeg.py index 166f6a3..7e7cf14 100644 --- a/bin/ffmpeg.py +++ b/bin/ffmpeg.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- +# -*- coding: future_fstrings -*- """ Name: FFMPEG Class Author: K4YT3X diff --git a/bin/image_cleaner.py b/bin/image_cleaner.py index 3b878a8..76bb536 100644 --- a/bin/image_cleaner.py +++ b/bin/image_cleaner.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- +# -*- coding: future_fstrings -*- """ Name: Video2X Image Cleaner Author: BrianPetkovsek diff --git a/bin/requirements.txt b/bin/requirements.txt index 472e89c..5855437 100644 --- a/bin/requirements.txt +++ b/bin/requirements.txt @@ -4,3 +4,4 @@ GPUtil psutil requests tqdm +future-fstrings>=1.1.0 diff --git a/bin/upscaler.py b/bin/upscaler.py index 791f004..5390242 100644 --- a/bin/upscaler.py +++ b/bin/upscaler.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- +# -*- coding: future_fstrings -*- """ Name: Video2X Upscaler Author: K4YT3X diff --git a/bin/video2x.py b/bin/video2x.py index 2df9f0b..a9a3aca 100644 --- a/bin/video2x.py +++ b/bin/video2x.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- +# -*- coding: future_fstrings -*- """ __ __ _ _ ___ __ __ diff --git a/bin/waifu2x_caffe.py b/bin/waifu2x_caffe.py index a3ea560..b512297 100644 --- a/bin/waifu2x_caffe.py +++ b/bin/waifu2x_caffe.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- +# -*- coding: future_fstrings -*- """ Name: Waifu2x Caffe Driver Author: K4YT3X diff --git a/bin/waifu2x_converter.py b/bin/waifu2x_converter.py index 4539bc4..d7a2927 100644 --- a/bin/waifu2x_converter.py +++ b/bin/waifu2x_converter.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- +# -*- coding: future_fstrings -*- """ Name: Waifu2x Converter CPP Driver Author: K4YT3X