Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fd40d7d

Browse filesBrowse files
authored
Merge pull request #13550 from anntzer/nopy2
Strip out Py2-compat in setupext.
2 parents 9e4cf8e + b7d3197 commit fd40d7d
Copy full SHA for fd40d7d

File tree

Expand file treeCollapse file tree

2 files changed

+9
-39
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+9
-39
lines changed

‎setup.py

Copy file name to clipboardExpand all lines: setup.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
import setupext
4646
from setupext import (print_line, print_raw, print_message, print_status,
47-
download_or_cache, makedirs as _makedirs)
47+
download_or_cache)
4848

4949
# Get the version from versioneer
5050
import versioneer
@@ -129,7 +129,7 @@ def _download_jquery_to(dest):
129129
url = "https://jqueryui.com/resources/download/jquery-ui-1.12.1.zip"
130130
sha = 'f8233674366ab36b2c34c577ec77a3d70cac75d2e387d8587f3836345c0f624d'
131131
if not os.path.exists(os.path.join(dest, "jquery-ui-1.12.1")):
132-
_makedirs(dest, exist_ok=True)
132+
os.makedirs(dest, exist_ok=True)
133133
try:
134134
buff = download_or_cache(url, sha)
135135
except Exception:

‎setupext.py

Copy file name to clipboardExpand all lines: setupext.py
+7-37Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,10 @@
1717
import tarfile
1818
import textwrap
1919
import urllib.request
20+
from urllib.request import Request
2021
import versioneer
2122
import warnings
2223

23-
if sys.version_info < (3, ):
24-
from urllib2 import urlopen, Request
25-
26-
class FileExistsError(OSError):
27-
pass
28-
29-
def makedirs(path, exist_ok=True):
30-
if not exist_ok:
31-
raise ValueError("this backport only supports exist_ok is True")
32-
if not path or os.path.exists(path):
33-
return
34-
head, tail = os.path.split(path)
35-
36-
makedirs(head, exist_ok=True)
37-
os.makedirs(path)
38-
39-
else:
40-
from urllib.request import urlopen, Request
41-
from os import makedirs
42-
4324
_log = logging.getLogger(__name__)
4425

4526

@@ -95,30 +76,20 @@ def download_or_cache(url, sha):
9576
def get_from_cache(local_fn):
9677
if cache_dir is None:
9778
raise Exception("no cache dir")
98-
cache_filename = os.path.join(cache_dir, local_fn)
99-
with open(cache_filename, 'rb') as fin:
100-
buf = BytesIO(fin.read())
101-
file_sha = get_fd_hash(buf)
102-
if file_sha != sha:
79+
buf = BytesIO(pathlib.Path(cache_dir, local_fn).read_bytes())
80+
if get_fd_hash(buf) != sha:
10381
return None
10482
buf.seek(0)
10583
return buf
10684

10785
def write_cache(local_fn, data):
10886
if cache_dir is None:
10987
raise Exception("no cache dir")
110-
11188
cache_filename = os.path.join(cache_dir, local_fn)
112-
makedirs(cache_dir, exist_ok=True)
113-
if sys.version_info < (3, ):
114-
if os.path.exists(cache_filename):
115-
raise FileExistsError
116-
mode = 'wb'
117-
else:
118-
mode = 'xb'
89+
os.makedirs(cache_dir, exist_ok=True)
11990
old_pos = data.tell()
12091
data.seek(0)
121-
with open(cache_filename, mode=mode) as fout:
92+
with open(cache_filename, "xb") as fout:
12293
fout.write(data.read())
12394
data.seek(old_pos)
12495

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

900871
# do we need to download / load the source from cache?
901872
if not os.path.exists(src_path):
902-
if not os.path.exists('build'):
903-
os.makedirs('build')
873+
os.makedirs('build', exist_ok=True)
904874

905875
url_fmts = [
906876
('https://downloads.sourceforge.net/project/freetype'

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.