From 8078110a7f158087add0720f629e205c94865a46 Mon Sep 17 00:00:00 2001 From: adisbladis Date: Wed, 12 Jan 2022 18:25:02 +1300 Subject: [PATCH] Reformat all Python code using Black --- fetch_from_legacy.py | 36 ++++++++++++---------- generate.py | 12 ++++---- hooks/pyproject-without-special-deps.py | 4 ++- tests/dependency-environment/trivial.py | 8 ++--- tests/editable-egg/src/trivial/__init__.py | 9 +++--- tests/eggs/eggs.py | 2 +- 6 files changed, 39 insertions(+), 32 deletions(-) diff --git a/fetch_from_legacy.py b/fetch_from_legacy.py index a721d00..1a11db8 100644 --- a/fetch_from_legacy.py +++ b/fetch_from_legacy.py @@ -63,30 +63,36 @@ context.verify_mode = ssl.CERT_NONE req = urllib.request.Request(index_url) if username and password: import base64 - password_b64 = base64.b64encode(bytes(f"{username}:{password}", "utf-8")).decode("utf-8") + + password_b64 = base64.b64encode(bytes(f"{username}:{password}", "utf-8")).decode( + "utf-8" + ) req.add_header("Authorization", f"Basic {password_b64}") -response = urllib.request.urlopen( - req, - context=context) +response = urllib.request.urlopen(req, context=context) index = response.read() parser = Pep503() parser.feed(str(index)) if package_filename not in parser.sources: - print("The file %s has not be found in the index %s" % ( - package_filename, index_url)) + print( + "The file %s has not be found in the index %s" % (package_filename, index_url) + ) exit(1) package_file = open(package_filename, "wb") # Sometimes the href is a relative path -if urlparse(parser.sources[package_filename]).netloc == '': +if urlparse(parser.sources[package_filename]).netloc == "": parsed_url = urlparse(index_url) - package_url = urlunparse(( - parsed_url.scheme, - parsed_url.netloc, - parsed_url.path + "/" + parser.sources[package_filename], - None, None, None, - )) + package_url = urlunparse( + ( + parsed_url.scheme, + parsed_url.netloc, + parsed_url.path + "/" + parser.sources[package_filename], + None, + None, + None, + ) + ) else: package_url = parser.sources[package_filename] @@ -107,9 +113,7 @@ print("Downloading %s" % real_package_url) req = urllib.request.Request(real_package_url) if username and password: req.add_unredirected_header("Authorization", f"Basic {password_b64}") -response = urllib.request.urlopen( - req, - context=context) +response = urllib.request.urlopen(req, context=context) with response as r: shutil.copyfileobj(r, package_file) diff --git a/generate.py b/generate.py index 76a6114..d4e1484 100755 --- a/generate.py +++ b/generate.py @@ -6,10 +6,10 @@ from poetry.packages.utils.utils import SUPPORTED_EXTENSIONS import json -EXT_FILE = 'extensions.json' +EXT_FILE = "extensions.json" -if __name__ == '__main__': - with open(EXT_FILE, 'w') as f: - ext = set(ext.lstrip('.') for ext in SUPPORTED_EXTENSIONS) - ext.add('egg') - f.write(json.dumps(sorted(ext), indent=2) + '\n') +if __name__ == "__main__": + with open(EXT_FILE, "w") as f: + ext = set(ext.lstrip(".") for ext in SUPPORTED_EXTENSIONS) + ext.add("egg") + f.write(json.dumps(sorted(ext), indent=2) + "\n") diff --git a/hooks/pyproject-without-special-deps.py b/hooks/pyproject-without-special-deps.py index 0357291..9f79f9a 100644 --- a/hooks/pyproject-without-special-deps.py +++ b/hooks/pyproject-without-special-deps.py @@ -25,7 +25,9 @@ def main(input, output, fields_to_remove): # Set ensure_ascii to False because TOML is valid UTF-8 so text that can't # be represented in ASCII is perfectly legitimate # HACK: Setting ensure_asscii to False breaks Python2 for some dependencies (like cachy==0.3.0) - json.dump(data, output, separators=(",", ":"), ensure_ascii=sys.version_info.major < 3) + json.dump( + data, output, separators=(",", ":"), ensure_ascii=sys.version_info.major < 3 + ) if __name__ == "__main__": diff --git a/tests/dependency-environment/trivial.py b/tests/dependency-environment/trivial.py index f098632..e1b9e70 100644 --- a/tests/dependency-environment/trivial.py +++ b/tests/dependency-environment/trivial.py @@ -1,10 +1,10 @@ def app(environ, start_response): """Simplest possible application object""" - data = b'Hello, World!\n' - status = '200 OK' + data = b"Hello, World!\n" + status = "200 OK" response_headers = [ - ('Content-type', 'text/plain'), - ('Content-Length', str(len(data))) + ("Content-type", "text/plain"), + ("Content-Length", str(len(data))), ] start_response(status, response_headers) return iter([data]) diff --git a/tests/editable-egg/src/trivial/__init__.py b/tests/editable-egg/src/trivial/__init__.py index 3324d4d..a6dcd8b 100644 --- a/tests/editable-egg/src/trivial/__init__.py +++ b/tests/editable-egg/src/trivial/__init__.py @@ -1,13 +1,14 @@ def app(environ, start_response): """Simplest possible application object""" - data = b'Original\n' - status = '200 OK' + data = b"Original\n" + status = "200 OK" response_headers = [ - ('Content-type', 'text/plain'), - ('Content-Length', str(len(data))) + ("Content-type", "text/plain"), + ("Content-Length", str(len(data))), ] start_response(status, response_headers) return iter([data]) + def app_factory(global_config, **local_conf): return app diff --git a/tests/eggs/eggs.py b/tests/eggs/eggs.py index 0d4571c..033c333 100644 --- a/tests/eggs/eggs.py +++ b/tests/eggs/eggs.py @@ -5,5 +5,5 @@ def main(): print("egg-test") -if __name__ == '__main__': +if __name__ == "__main__": main()