Commit 10c3d0d5 by Sébastien Eustace

Improve installer

parent 4490b68c
...@@ -29,6 +29,7 @@ import sys ...@@ -29,6 +29,7 @@ import sys
import tarfile import tarfile
import tempfile import tempfile
from contextlib import closing
from contextlib import contextmanager from contextlib import contextmanager
from functools import cmp_to_key from functools import cmp_to_key
from gzip import GzipFile from gzip import GzipFile
...@@ -36,9 +37,11 @@ from io import UnsupportedOperation ...@@ -36,9 +37,11 @@ from io import UnsupportedOperation
try: try:
from urllib.error import HTTPError from urllib.error import HTTPError
from urllib.request import Request
from urllib.request import urlopen from urllib.request import urlopen
except ImportError: except ImportError:
from urllib2 import HTTPError from urllib2 import HTTPError
from urllib2 import Request
from urllib2 import urlopen from urllib2 import urlopen
try: try:
...@@ -329,9 +332,7 @@ class Installer: ...@@ -329,9 +332,7 @@ class Installer:
def get_version(self): def get_version(self):
print(colorize("info", "Retrieving Poetry metadata")) print(colorize("info", "Retrieving Poetry metadata"))
r = urlopen(self.METADATA_URL) metadata = json.loads(self._get(self.METADATA_URL))
metadata = json.loads(r.read().decode())
r.close()
def _compare_versions(x, y): def _compare_versions(x, y):
mx = self.VERSION_REGEX.match(x) mx = self.VERSION_REGEX.match(x)
...@@ -775,6 +776,12 @@ class Installer: ...@@ -775,6 +776,12 @@ class Installer:
def call(self, *args): def call(self, *args):
return subprocess.check_output(args, stderr=subprocess.STDOUT) return subprocess.check_output(args, stderr=subprocess.STDOUT)
def _get(self, url):
request = Request(url, headers={"User-Agent": "Python Poetry"})
with closing(urlopen(request)) as r:
return r.read()
def main(): def main():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment