From 2941d1d9c19e2d64746fdf92192002f13988d729 Mon Sep 17 00:00:00 2001 From: stonebig Date: Sun, 11 Dec 2022 12:48:17 +0100 Subject: [PATCH] black 22.12 reformat --- winpython/associate.py | 92 +++---- winpython/piptree.py | 14 +- winpython/qthelpers.py | 66 ++--- winpython/wppm.py | 537 +++++++++++++++++------------------------ 4 files changed, 284 insertions(+), 425 deletions(-) diff --git a/winpython/associate.py b/winpython/associate.py index 2dca32aa..adf48d49 100644 --- a/winpython/associate.py +++ b/winpython/associate.py @@ -15,6 +15,7 @@ import sys import os from pathlib import Path + # import subprocess @@ -40,14 +41,12 @@ def _get_shortcut_data(target, current=True): - wpgroup = utils.create_winpython_start_menu_folder( - current=current - ) + wpgroup = utils.create_winpython_start_menu_folder(current=current) wpdir = str(Path(target).parent) data = [] for name in os.listdir(wpdir): bname, ext = Path(name).stem, Path(name).suffix - if ext == '.exe': + if ext == ".exe": data.append( ( str(Path(wpdir) / name), @@ -60,11 +59,7 @@ def _get_shortcut_data(target, current=True): def register(target, current=True): """Register a Python distribution in Windows registry""" - root = ( - winreg.HKEY_CURRENT_USER - if current - else winreg.HKEY_LOCAL_MACHINE - ) + root = winreg.HKEY_CURRENT_USER if current else winreg.HKEY_LOCAL_MACHINE # Extensions winreg.SetValueEx( @@ -113,9 +108,9 @@ def register(target, current=True): ) # Verbs - python = str((Path(target) / 'python.exe').resolve()) - pythonw = str((Path(target) / 'pythonw.exe').resolve()) - spyder = str((Path(target).parent / 'Spyder.exe').resolve()) + python = str((Path(target) / "python.exe").resolve()) + pythonw = str((Path(target) / "pythonw.exe").resolve()) + spyder = str((Path(target).parent / "Spyder.exe").resolve()) if not Path(spyder).is_file(): spyder = f'{pythonw}" "{target}\Scripts\spyder' @@ -134,9 +129,7 @@ def register(target, current=True): '"%s" "%%1" %%*' % pythonw, ) winreg.SetValueEx( - winreg.CreateKey( - root, KEY_C2 % ("Compiled", "open") - ), + winreg.CreateKey(root, KEY_C2 % ("Compiled", "open")), "", 0, winreg.REG_SZ, @@ -147,16 +140,14 @@ def register(target, current=True): "", 0, winreg.REG_SZ, - '"%s" "%s\Lib\idlelib\idle.pyw" -n -e "%%1"' - % (pythonw, target), + '"%s" "%s\Lib\idlelib\idle.pyw" -n -e "%%1"' % (pythonw, target), ) winreg.SetValueEx( winreg.CreateKey(root, KEY_C2 % ("NoCon", EWI)), "", 0, winreg.REG_SZ, - '"%s" "%s\Lib\idlelib\idle.pyw" -n -e "%%1"' - % (pythonw, target), + '"%s" "%s\Lib\idlelib\idle.pyw" -n -e "%%1"' % (pythonw, target), ) winreg.SetValueEx( winreg.CreateKey(root, KEY_C2 % ("", EWS)), @@ -184,27 +175,27 @@ def register(target, current=True): handler, ) # Icons - dlls = str(Path(target) / 'DLLs') + dlls = str(Path(target) / "DLLs") winreg.SetValueEx( winreg.CreateKey(root, KEY_I % ""), "", 0, winreg.REG_SZ, - r'%s\py.ico' % dlls, + r"%s\py.ico" % dlls, ) winreg.SetValueEx( winreg.CreateKey(root, KEY_I % "NoCon"), "", 0, winreg.REG_SZ, - r'%s\py.ico' % dlls, + r"%s\py.ico" % dlls, ) winreg.SetValueEx( winreg.CreateKey(root, KEY_I % "Compiled"), "", 0, winreg.REG_SZ, - r'%s\pyc.ico' % dlls, + r"%s\pyc.ico" % dlls, ) # Descriptions @@ -233,32 +224,30 @@ def register(target, current=True): # PythonCore entries short_version = utils.get_python_infos(target)[0] long_version = utils.get_python_long_version(target) - key_core = (KEY_S1 % short_version) + r'\%s' + key_core = (KEY_S1 % short_version) + r"\%s" winreg.SetValueEx( - winreg.CreateKey(root, key_core % 'InstallPath'), + winreg.CreateKey(root, key_core % "InstallPath"), "", 0, winreg.REG_SZ, target, ) winreg.SetValueEx( - winreg.CreateKey( - root, key_core % r'InstallPath\InstallGroup' - ), + winreg.CreateKey(root, key_core % r"InstallPath\InstallGroup"), "", 0, winreg.REG_SZ, "Python %s" % short_version, ) winreg.SetValueEx( - winreg.CreateKey(root, key_core % 'Modules'), + winreg.CreateKey(root, key_core % "Modules"), "", 0, winreg.REG_SZ, "", ) winreg.SetValueEx( - winreg.CreateKey(root, key_core % 'PythonPath'), + winreg.CreateKey(root, key_core % "PythonPath"), "", 0, winreg.REG_SZ, @@ -267,7 +256,7 @@ def register(target, current=True): winreg.SetValueEx( winreg.CreateKey( root, - key_core % r'Help\Main Python Documentation', + key_core % r"Help\Main Python Documentation", ), "", 0, @@ -276,21 +265,16 @@ def register(target, current=True): ) # Create start menu entries for all WinPython launchers - for path, desc, fname in _get_shortcut_data( - target, current=current - ): + for path, desc, fname in _get_shortcut_data(target, current=current): utils.create_shortcut(path, desc, fname) + def unregister(target, current=True): """Unregister a Python distribution in Windows registry""" # Registry entries - root = ( - winreg.HKEY_CURRENT_USER - if current - else winreg.HKEY_LOCAL_MACHINE - ) + root = winreg.HKEY_CURRENT_USER if current else winreg.HKEY_LOCAL_MACHINE short_version = utils.get_python_infos(target)[0] - key_core = (KEY_S1 % short_version) + r'\%s' + key_core = (KEY_S1 % short_version) + r"\%s" for key in ( # Drop support KEY_DROP1 % "", @@ -328,12 +312,12 @@ def unregister(target, current=True): KEY_D % "Compiled", KEY_D % "", # PythonCore - key_core % r'InstallPath\InstallGroup', - key_core % 'InstallPath', - key_core % 'Modules', - key_core % 'PythonPath', - key_core % r'Help\Main Python Documentation', - key_core % 'Help', + key_core % r"InstallPath\InstallGroup", + key_core % "InstallPath", + key_core % "Modules", + key_core % "PythonPath", + key_core % r"Help\Main Python Documentation", + key_core % "Help", KEY_S1 % short_version, KEY_S0, KEY_S, @@ -342,23 +326,17 @@ def unregister(target, current=True): print(key) winreg.DeleteKey(root, key) except WindowsError: - rootkey = ( - 'HKEY_CURRENT_USER' - if current - else 'HKEY_LOCAL_MACHINE' - ) + rootkey = "HKEY_CURRENT_USER" if current else "HKEY_LOCAL_MACHINE" print( - r'Unable to remove %s\%s' % (rootkey, key), + r"Unable to remove %s\%s" % (rootkey, key), file=sys.stderr, ) # Start menu shortcuts - for path, desc, fname in _get_shortcut_data( - target, current=current - ): + for path, desc, fname in _get_shortcut_data(target, current=current): if Path(fname).exists(): os.remove(fname) -if __name__ == '__main__': +if __name__ == "__main__": register(sys.prefix) - unregister(sys.prefix) + unregister(sys.prefix) \ No newline at end of file diff --git a/winpython/piptree.py b/winpython/piptree.py index e44fdca1..fd1d86ac 100644 --- a/winpython/piptree.py +++ b/winpython/piptree.py @@ -54,12 +54,12 @@ def __init__(self): if "requires_dist" in meta: for i in meta["requires_dist"]: det = (i + ";").split(";") - + # req_nameextra is "python-jose[cryptography]" # from fastapi "python-jose[cryptography]<4.0.0,>=3.3.0 - # req_nameextra is "google-cloud-storage" + # req_nameextra is "google-cloud-storage" # from "google-cloud-storage (<2.0.0,>=1.26.0) - req_nameextra = re.split(' |;|==|!|>|<', det[0]+ ";")[0] + req_nameextra = re.split(" |;|==|!|>|<", det[0] + ";")[0] req_nameextra = normalize(req_nameextra) req_key = normalize((req_nameextra + "[").split("[")[0]) req_key_extra = req_nameextra[len(req_key) + 1 :].split("]")[0] @@ -187,9 +187,7 @@ def description(self, pp): "return desciption of the package" if pp in self.distro: return print("\n".join(self.distro[pp]["description"].split(r"\n"))) - + def pip_list(self): - """ do like pip list""" - return [(p , self.distro[p]['version']) for p in sorted(self.distro)] - - \ No newline at end of file + """do like pip list""" + return [(p, self.distro[p]["version"]) for p in sorted(self.distro)] \ No newline at end of file diff --git a/winpython/qthelpers.py b/winpython/qthelpers.py index 92d05622..ebc31a05 100644 --- a/winpython/qthelpers.py +++ b/winpython/qthelpers.py @@ -83,10 +83,7 @@ def event(self, event): def qapplication(translate=True): """Return QApplication instance Creates it if it doesn't already exist""" - if ( - sys.platform == "darwin" - and 'Spyder.app' in __file__ - ): + if sys.platform == "darwin" and "Spyder.app" in __file__: SpyderApplication = MacApplication else: SpyderApplication = QApplication @@ -94,7 +91,7 @@ def qapplication(translate=True): if not app: # Set Application name for Gnome 3 # https://groups.google.com/forum/#!topic/pyside/24qxvwfrRDs - app = SpyderApplication(['Spyder']) + app = SpyderApplication(["Spyder"]) if translate: install_translator(app) return app @@ -102,15 +99,15 @@ def qapplication(translate=True): def file_uri(fname): """Select the right file uri scheme according to the operating system""" - if os.name == 'nt': + if os.name == "nt": # Local file - if re.search(r'^[a-zA-Z]:', fname): - return 'file:///' + fname + if re.search(r"^[a-zA-Z]:", fname): + return "file:///" + fname # UNC based path else: - return 'file://' + fname + return "file://" + fname else: - return 'file://' + fname + return "file://" + fname QT_TRANSLATOR = None @@ -123,13 +120,9 @@ def install_translator(qapp): qt_translator = QTranslator() if qt_translator.load( "qt_" + QLocale.system().name(), - QLibraryInfo.location( - QLibraryInfo.TranslationsPath - ), + QLibraryInfo.location(QLibraryInfo.TranslationsPath), ): - QT_TRANSLATOR = ( - qt_translator - ) # Keep reference alive + QT_TRANSLATOR = qt_translator # Keep reference alive if QT_TRANSLATOR is not None: qapp.installTranslator(QT_TRANSLATOR) @@ -137,29 +130,22 @@ def install_translator(qapp): def keybinding(attr): """Return keybinding""" ks = getattr(QKeySequence, attr) - return from_qvariant( - QKeySequence.keyBindings(ks)[0], str - ) + return from_qvariant(QKeySequence.keyBindings(ks)[0], str) def _process_mime_path(path, extlist): if path.startswith(r"file://"): - if os.name == 'nt': + if os.name == "nt": # On Windows platforms, a local path reads: file:///c:/... # and a UNC based path reads like: file://server/share - if path.startswith( - r"file:///" - ): # this is a local path + if path.startswith(r"file:///"): # this is a local path path = path[8:] else: # this is a unc path path = path[5:] else: path = path[7:] if Path(path).exists(): - if ( - extlist is None - or Path(path).suffix in extlist - ): + if extlist is None or Path(path).suffix in extlist: return path @@ -171,15 +157,11 @@ def mimedata2url(source, extlist=None): pathlist = [] if source.hasUrls(): for url in source.urls(): - path = _process_mime_path( - to_text_string(url.toString()), extlist - ) + path = _process_mime_path(to_text_string(url.toString()), extlist) if path is not None: pathlist.append(path) elif source.hasText(): - for rawpath in to_text_string( - source.text() - ).splitlines(): + for rawpath in to_text_string(source.text()).splitlines(): path = _process_mime_path(rawpath, extlist) if path is not None: pathlist.append(path) @@ -200,9 +182,7 @@ def action2button( button.setDefaultAction(action) button.setAutoRaise(autoraise) if text_beside_icon: - button.setToolButtonStyle( - Qt.ToolButtonTextBesideIcon - ) + button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) return button @@ -264,9 +244,7 @@ def add_actions(target, actions, insert_before=None): if previous_action.isSeparator(): previous_action = None for action in actions: - if (action is None) and ( - previous_action is not None - ): + if (action is None) and (previous_action is not None): if insert_before is None: target.addSeparator() else: @@ -287,13 +265,9 @@ def add_actions(target, actions, insert_before=None): def get_std_icon(name, size=None): """Get standard platform icon Call 'show_std_icons()' for details""" - if not name.startswith('SP_'): - name = 'SP_' + name - icon = ( - QWidget() - .style() - .standardIcon(getattr(QStyle, name)) - ) + if not name.startswith("SP_"): + name = "SP_" + name + icon = QWidget().style().standardIcon(getattr(QStyle, name)) if size is None: return icon else: diff --git a/winpython/wppm.py b/winpython/wppm.py index b2fcc0bf..dc86e642 100644 --- a/winpython/wppm.py +++ b/winpython/wppm.py @@ -27,46 +27,53 @@ # from former wppm separate script launcher import textwrap from argparse import ArgumentParser, HelpFormatter, RawTextHelpFormatter + # from winpython import py3compat -from winpython import piptree +from winpython import piptree # import information reader # importlib_metadata before Python 3.8 try: from importlib import metadata as metadata # Python-3.8 + metadata = metadata.metadata except: try: - from importlib_metadata import metadata #