mirror of
https://github.com/vale981/poetry2nix
synced 2025-03-04 08:41:42 -05:00
Reformat all Python code using Black
This commit is contained in:
parent
b4d2477b1f
commit
8078110a7f
6 changed files with 39 additions and 32 deletions
|
@ -63,30 +63,36 @@ context.verify_mode = ssl.CERT_NONE
|
||||||
req = urllib.request.Request(index_url)
|
req = urllib.request.Request(index_url)
|
||||||
if username and password:
|
if username and password:
|
||||||
import base64
|
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}")
|
req.add_header("Authorization", f"Basic {password_b64}")
|
||||||
response = urllib.request.urlopen(
|
response = urllib.request.urlopen(req, context=context)
|
||||||
req,
|
|
||||||
context=context)
|
|
||||||
index = response.read()
|
index = response.read()
|
||||||
|
|
||||||
parser = Pep503()
|
parser = Pep503()
|
||||||
parser.feed(str(index))
|
parser.feed(str(index))
|
||||||
if package_filename not in parser.sources:
|
if package_filename not in parser.sources:
|
||||||
print("The file %s has not be found in the index %s" % (
|
print(
|
||||||
package_filename, index_url))
|
"The file %s has not be found in the index %s" % (package_filename, index_url)
|
||||||
|
)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
package_file = open(package_filename, "wb")
|
package_file = open(package_filename, "wb")
|
||||||
# Sometimes the href is a relative path
|
# 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)
|
parsed_url = urlparse(index_url)
|
||||||
package_url = urlunparse((
|
package_url = urlunparse(
|
||||||
parsed_url.scheme,
|
(
|
||||||
parsed_url.netloc,
|
parsed_url.scheme,
|
||||||
parsed_url.path + "/" + parser.sources[package_filename],
|
parsed_url.netloc,
|
||||||
None, None, None,
|
parsed_url.path + "/" + parser.sources[package_filename],
|
||||||
))
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
package_url = parser.sources[package_filename]
|
package_url = parser.sources[package_filename]
|
||||||
|
|
||||||
|
@ -107,9 +113,7 @@ print("Downloading %s" % real_package_url)
|
||||||
req = urllib.request.Request(real_package_url)
|
req = urllib.request.Request(real_package_url)
|
||||||
if username and password:
|
if username and password:
|
||||||
req.add_unredirected_header("Authorization", f"Basic {password_b64}")
|
req.add_unredirected_header("Authorization", f"Basic {password_b64}")
|
||||||
response = urllib.request.urlopen(
|
response = urllib.request.urlopen(req, context=context)
|
||||||
req,
|
|
||||||
context=context)
|
|
||||||
|
|
||||||
with response as r:
|
with response as r:
|
||||||
shutil.copyfileobj(r, package_file)
|
shutil.copyfileobj(r, package_file)
|
||||||
|
|
12
generate.py
12
generate.py
|
@ -6,10 +6,10 @@
|
||||||
from poetry.packages.utils.utils import SUPPORTED_EXTENSIONS
|
from poetry.packages.utils.utils import SUPPORTED_EXTENSIONS
|
||||||
import json
|
import json
|
||||||
|
|
||||||
EXT_FILE = 'extensions.json'
|
EXT_FILE = "extensions.json"
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
with open(EXT_FILE, 'w') as f:
|
with open(EXT_FILE, "w") as f:
|
||||||
ext = set(ext.lstrip('.') for ext in SUPPORTED_EXTENSIONS)
|
ext = set(ext.lstrip(".") for ext in SUPPORTED_EXTENSIONS)
|
||||||
ext.add('egg')
|
ext.add("egg")
|
||||||
f.write(json.dumps(sorted(ext), indent=2) + '\n')
|
f.write(json.dumps(sorted(ext), indent=2) + "\n")
|
||||||
|
|
|
@ -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
|
# Set ensure_ascii to False because TOML is valid UTF-8 so text that can't
|
||||||
# be represented in ASCII is perfectly legitimate
|
# be represented in ASCII is perfectly legitimate
|
||||||
# HACK: Setting ensure_asscii to False breaks Python2 for some dependencies (like cachy==0.3.0)
|
# 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__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
def app(environ, start_response):
|
def app(environ, start_response):
|
||||||
"""Simplest possible application object"""
|
"""Simplest possible application object"""
|
||||||
data = b'Hello, World!\n'
|
data = b"Hello, World!\n"
|
||||||
status = '200 OK'
|
status = "200 OK"
|
||||||
response_headers = [
|
response_headers = [
|
||||||
('Content-type', 'text/plain'),
|
("Content-type", "text/plain"),
|
||||||
('Content-Length', str(len(data)))
|
("Content-Length", str(len(data))),
|
||||||
]
|
]
|
||||||
start_response(status, response_headers)
|
start_response(status, response_headers)
|
||||||
return iter([data])
|
return iter([data])
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
def app(environ, start_response):
|
def app(environ, start_response):
|
||||||
"""Simplest possible application object"""
|
"""Simplest possible application object"""
|
||||||
data = b'Original\n'
|
data = b"Original\n"
|
||||||
status = '200 OK'
|
status = "200 OK"
|
||||||
response_headers = [
|
response_headers = [
|
||||||
('Content-type', 'text/plain'),
|
("Content-type", "text/plain"),
|
||||||
('Content-Length', str(len(data)))
|
("Content-Length", str(len(data))),
|
||||||
]
|
]
|
||||||
start_response(status, response_headers)
|
start_response(status, response_headers)
|
||||||
return iter([data])
|
return iter([data])
|
||||||
|
|
||||||
|
|
||||||
def app_factory(global_config, **local_conf):
|
def app_factory(global_config, **local_conf):
|
||||||
return app
|
return app
|
||||||
|
|
|
@ -5,5 +5,5 @@ def main():
|
||||||
print("egg-test")
|
print("egg-test")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Add table
Reference in a new issue