Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Strip out Py2-compat in setupext. #13550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

import setupext
from setupext import (print_line, print_raw, print_message, print_status,
download_or_cache, makedirs as _makedirs)
download_or_cache)

# Get the version from versioneer
import versioneer
Expand Down Expand Up @@ -129,7 +129,7 @@ def _download_jquery_to(dest):
url = "https://jqueryui.com/resources/download/jquery-ui-1.12.1.zip"
sha = 'f8233674366ab36b2c34c577ec77a3d70cac75d2e387d8587f3836345c0f624d'
if not os.path.exists(os.path.join(dest, "jquery-ui-1.12.1")):
_makedirs(dest, exist_ok=True)
os.makedirs(dest, exist_ok=True)
try:
buff = download_or_cache(url, sha)
except Exception:
Expand Down
44 changes: 7 additions & 37 deletions setupext.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,10 @@
import tarfile
import textwrap
import urllib.request
from urllib.request import Request
import versioneer
import warnings

if sys.version_info < (3, ):
from urllib2 import urlopen, Request

class FileExistsError(OSError):
pass

def makedirs(path, exist_ok=True):
if not exist_ok:
raise ValueError("this backport only supports exist_ok is True")
if not path or os.path.exists(path):
return
head, tail = os.path.split(path)

makedirs(head, exist_ok=True)
os.makedirs(path)

else:
from urllib.request import urlopen, Request
from os import makedirs

_log = logging.getLogger(__name__)


Expand Down Expand Up @@ -95,30 +76,20 @@ def download_or_cache(url, sha):
def get_from_cache(local_fn):
if cache_dir is None:
raise Exception("no cache dir")
cache_filename = os.path.join(cache_dir, local_fn)
with open(cache_filename, 'rb') as fin:
buf = BytesIO(fin.read())
file_sha = get_fd_hash(buf)
if file_sha != sha:
buf = BytesIO(pathlib.Path(cache_dir, local_fn).read_bytes())
if get_fd_hash(buf) != sha:
return None
buf.seek(0)
return buf

def write_cache(local_fn, data):
if cache_dir is None:
raise Exception("no cache dir")

cache_filename = os.path.join(cache_dir, local_fn)
makedirs(cache_dir, exist_ok=True)
if sys.version_info < (3, ):
if os.path.exists(cache_filename):
raise FileExistsError
mode = 'wb'
else:
mode = 'xb'
os.makedirs(cache_dir, exist_ok=True)
old_pos = data.tell()
data.seek(0)
with open(cache_filename, mode=mode) as fout:
with open(cache_filename, "xb") as fout:
fout.write(data.read())
data.seek(old_pos)

Expand All @@ -130,7 +101,7 @@ def write_cache(local_fn, data):
# jQueryUI's website blocks direct downloads from urllib.request's
# default User-Agent, but not (for example) wget; so I don't feel too
# bad passing in an empty User-Agent.
with urlopen(
with urllib.request.urlopen(
Request(url, headers={"User-Agent": ""})) as req:
file_contents = BytesIO(req.read())
file_contents.seek(0)
Expand Down Expand Up @@ -899,8 +870,7 @@ def do_custom_build(self):

# do we need to download / load the source from cache?
if not os.path.exists(src_path):
if not os.path.exists('build'):
os.makedirs('build')
os.makedirs('build', exist_ok=True)

url_fmts = [
('https://downloads.sourceforge.net/project/freetype'
Expand Down