Skip to content

Commit b00b938

Browse files
committed
nptools: Respect ignore error parameter. Use short windows paths.
1 parent 85624f0 commit b00b938

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

Lib/__np__/common.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,31 @@ class NoSuchURL(Exception):
131131
pass
132132

133133

134-
def copytree(src, dst, symlinks=False, ignore=None, executable=False):
134+
def copytree(src, dst, symlinks=False, ignore_errors=None, executable=False):
135135
if not os.path.exists(dst):
136136
os.makedirs(dst)
137137
for item in os.listdir(src):
138138
s = os.path.join(src, item)
139+
if os.name == "nt":
140+
from __np__.windows import get_short_path
141+
try:
142+
s = get_short_path(os.path.dirname(s))
143+
except:
144+
pass
139145
d = os.path.join(dst, item)
146+
if os.name == "nt":
147+
try:
148+
d = get_short_path(os.path.dirname(d))
149+
except:
150+
pass
140151
if os.path.isdir(s):
141-
copytree(s, d, symlinks, ignore)
152+
copytree(s, d, symlinks, ignore_errors)
142153
else:
143-
shutil.copy2(s, d)
154+
try:
155+
shutil.copy2(s, d)
156+
except:
157+
if not ignore_errors:
158+
raise
144159
if executable:
145160
os.chmod(d, 509) # 775
146161

@@ -281,6 +296,7 @@ def run_with_output(*args, **kwargs):
281296
def install_files(dst, *files, **kwargs):
282297
base_dir = kwargs.pop("base_dir", None)
283298
executable = kwargs.pop("executable", None)
299+
ignore_errors = kwargs.pop("ignore_errors", None)
284300
assert not kwargs
285301

286302
if not os.path.isdir(dst):
@@ -294,7 +310,7 @@ def install_files(dst, *files, **kwargs):
294310
if not os.path.exists(os.path.dirname(file_dst)):
295311
os.makedirs(os.path.dirname(file_dst))
296312
if os.path.isdir(file):
297-
copytree(file, os.path.join(dst, destination_filename), executable=executable)
313+
copytree(file, os.path.join(dst, destination_filename), executable=executable, ignore_errors=ignore_errors)
298314
else:
299315
shutil.copy(file, os.path.join(dst, destination_filename))
300316
if executable:
@@ -323,10 +339,11 @@ def install_dep_libs(dependency_name, *files, **kwargs):
323339

324340
def install_build_tool(tool_name, *files, **kwargs):
325341
base_dir = kwargs.pop("base_dir", None)
342+
ignore_errors = kwargs.pop("ignore_errors", None)
326343
assert not kwargs
327344

328345
dependency_location = os.path.join(getToolsInstallDir(), tool_name)
329-
install_files(dependency_location, *files, base_dir=base_dir, executable=True)
346+
install_files(dependency_location, *files, base_dir=base_dir, executable=True, ignore_errors=ignore_errors)
330347

331348

332349
def find_build_tool_exe(tool_name, exe):
@@ -435,4 +452,4 @@ def importFileAsModule(modulename, filename):
435452
)
436453
build_script_module = importlib.util.module_from_spec(build_script_spec)
437454
build_script_spec.loader.exec_module(build_script_module)
438-
return build_script_module
455+
return build_script_module

Lib/__np__/windows.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,24 @@ def rename_symbols_in_wheel_file(wheel, filename, prefix, protected_symbols = []
184184
rename_symbols_in_file(os.path.join(tmpdir, filename), prefix, protected_symbols)
185185
with WheelFile(wheel, 'a') as wf:
186186
wf.write(os.path.join(tmpdir, filename), filename)
187+
188+
189+
import os
190+
if os.name == "nt":
191+
import ctypes
192+
from ctypes import wintypes
193+
_GetShortPathNameW = ctypes.windll.kernel32.GetShortPathNameW
194+
_GetShortPathNameW.argtypes = [wintypes.LPCWSTR, wintypes.LPWSTR, wintypes.DWORD]
195+
_GetShortPathNameW.restype = wintypes.DWORD
196+
197+
def get_short_path(path):
198+
output_buf_size = 0
199+
while True:
200+
output_buf = ctypes.create_unicode_buffer(output_buf_size)
201+
needed = _GetShortPathNameW(path, output_buf, output_buf_size)
202+
if needed == 0:
203+
raise ctypes.WinError()
204+
if output_buf_size >= needed:
205+
return output_buf.value
206+
else:
207+
output_buf_size = needed

0 commit comments

Comments
 (0)