From 4f9a51d4840a18d2e581e19365f5de4f0649cea6 Mon Sep 17 00:00:00 2001 From: Greg Price Date: Sat, 3 Aug 2019 21:12:26 -0700 Subject: [PATCH 1/4] bpo-37760: Avoid cluttering work tree with downloaded Unicode files. --- .gitignore | 1 + Tools/unicode/makeunicodedata.py | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 9445ef1e2c5252..5f1ba0b92ceb6e 100644 --- a/.gitignore +++ b/.gitignore @@ -74,6 +74,7 @@ PCbuild/arm32/ PCbuild/arm64/ PCbuild/obj/ PCbuild/win32/ +Tools/unicode/data/ .purify __pycache__ autom4te.cache diff --git a/Tools/unicode/makeunicodedata.py b/Tools/unicode/makeunicodedata.py index 5b9427acd39003..51216d5c3737c4 100644 --- a/Tools/unicode/makeunicodedata.py +++ b/Tools/unicode/makeunicodedata.py @@ -886,15 +886,19 @@ class Difference(Exception):pass normalization_changes)) +DATA_DIR = os.path.join('Tools', 'unicode', 'data') + def open_data(template, version): - local = template % ('-'+version,) + local = os.path.join(DATA_DIR, template % ('-'+version,)) if not os.path.exists(local): import urllib.request if version == '3.2.0': # irregular url structure - url = 'http://www.unicode.org/Public/3.2-Update/' + local + url = ('http://www.unicode.org/Public/3.2-Update/'+template) % ('-'+version,) else: url = ('http://www.unicode.org/Public/%s/ucd/'+template) % (version, '') + if not os.path.exists(DATA_DIR): + os.mkdir(DATA_DIR) urllib.request.urlretrieve(url, filename=local) if local.endswith('.txt'): return open(local, encoding='utf-8') From f8d11c6e50aa8c6ef82562c918906f17d748038e Mon Sep 17 00:00:00 2001 From: Greg Price Date: Tue, 13 Aug 2019 00:18:31 -0700 Subject: [PATCH 2/4] Use spiffy os.makedirs(..., exist_ok=True). --- Tools/unicode/makeunicodedata.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Tools/unicode/makeunicodedata.py b/Tools/unicode/makeunicodedata.py index 51216d5c3737c4..aefd86bec61787 100644 --- a/Tools/unicode/makeunicodedata.py +++ b/Tools/unicode/makeunicodedata.py @@ -897,8 +897,7 @@ def open_data(template, version): url = ('http://www.unicode.org/Public/3.2-Update/'+template) % ('-'+version,) else: url = ('http://www.unicode.org/Public/%s/ucd/'+template) % (version, '') - if not os.path.exists(DATA_DIR): - os.mkdir(DATA_DIR) + os.makedirs(DATA_DIR, exist_ok=True) urllib.request.urlretrieve(url, filename=local) if local.endswith('.txt'): return open(local, encoding='utf-8') From 7268d819bf541275c35d65081ce2b14ea32b6124 Mon Sep 17 00:00:00 2001 From: Greg Price Date: Tue, 13 Aug 2019 00:40:44 -0700 Subject: [PATCH 3/4] Add to `make clean`. --- Makefile.pre.in | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile.pre.in b/Makefile.pre.in index 363a4eb9d2cb29..c99aee1cc267f4 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -1760,6 +1760,7 @@ clean: pycremoval -rm -f Programs/_testembed Programs/_freeze_importlib -find build -type f -a ! -name '*.gc??' -exec rm -f {} ';' -rm -f Include/pydtrace_probes.h + -rm -rf Tools/unicode/data -rm -f profile-gen-stamp profile-removal: From de76a66742c05a12a2acec7cb37df74abfa4acfd Mon Sep 17 00:00:00 2001 From: Greg Price Date: Tue, 13 Aug 2019 21:22:13 -0700 Subject: [PATCH 4/4] Revert "Add to `make clean`." This reverts commit 7268d819bf541275c35d65081ce2b14ea32b6124. --- Makefile.pre.in | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile.pre.in b/Makefile.pre.in index c99aee1cc267f4..363a4eb9d2cb29 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -1760,7 +1760,6 @@ clean: pycremoval -rm -f Programs/_testembed Programs/_freeze_importlib -find build -type f -a ! -name '*.gc??' -exec rm -f {} ';' -rm -f Include/pydtrace_probes.h - -rm -rf Tools/unicode/data -rm -f profile-gen-stamp profile-removal: