Skip to content

Commit

Permalink
Reformat all Python code using Black
Browse files Browse the repository at this point in the history
  • Loading branch information
adisbladis committed Jan 12, 2022
1 parent b4d2477 commit 8078110
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 32 deletions.
36 changes: 20 additions & 16 deletions fetch_from_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,36 @@ def handle_endtag(self, tag):
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]

Expand All @@ -107,9 +113,7 @@ def handle_endtag(self, tag):
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)
12 changes: 6 additions & 6 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
4 changes: 3 additions & 1 deletion hooks/pyproject-without-special-deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
8 changes: 4 additions & 4 deletions tests/dependency-environment/trivial.py
Original file line number Diff line number Diff line change
@@ -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])
9 changes: 5 additions & 4 deletions tests/editable-egg/src/trivial/__init__.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion tests/eggs/eggs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ def main():
print("egg-test")


if __name__ == '__main__':
if __name__ == "__main__":
main()

0 comments on commit 8078110

Please sign in to comment.