Skip to content

Commit 74dfaec

Browse files
authored
Merge pull request #838 from kycutler/kycutler/debugpaths
2 parents c5b1751 + 6ffb3d3 commit 74dfaec

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

ipykernel/compiler.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from IPython.core.compilerop import CachingCompiler
22
import tempfile
33
import os
4+
import sys
45

56

67
def murmur2_x86(data, seed):
@@ -36,11 +37,35 @@ def murmur2_x86(data, seed):
3637

3738
return h
3839

40+
convert_to_long_pathname = lambda filename:filename
41+
42+
if sys.platform == 'win32':
43+
try:
44+
import ctypes
45+
from ctypes.wintypes import MAX_PATH, LPCWSTR, LPWSTR, DWORD
46+
47+
_GetLongPathName = ctypes.windll.kernel32.GetLongPathNameW
48+
_GetLongPathName.argtypes = [LPCWSTR, LPWSTR, DWORD]
49+
_GetLongPathName.restype = DWORD
50+
51+
def _convert_to_long_pathname(filename):
52+
buf = ctypes.create_unicode_buffer(MAX_PATH)
53+
rv = _GetLongPathName(filename, buf, MAX_PATH)
54+
if rv != 0 and rv <= MAX_PATH:
55+
filename = buf.value
56+
return filename
57+
58+
# test that it works so if there are any issues we fail just once here
59+
_convert_to_long_pathname(__file__)
60+
except:
61+
pass
62+
else:
63+
convert_to_long_pathname = _convert_to_long_pathname
3964

4065
def get_tmp_directory():
41-
tmp_dir = tempfile.gettempdir()
66+
tmp_dir = convert_to_long_pathname(tempfile.gettempdir())
4267
pid = os.getpid()
43-
return tmp_dir + '/ipykernel_' + str(pid)
68+
return tmp_dir + os.sep + 'ipykernel_' + str(pid)
4469

4570

4671
def get_tmp_hash_seed():
@@ -52,7 +77,7 @@ def get_file_name(code):
5277
cell_name = os.environ.get("IPYKERNEL_CELL_NAME")
5378
if cell_name is None:
5479
name = murmur2_x86(code, get_tmp_hash_seed())
55-
cell_name = get_tmp_directory() + '/' + str(name) + '.py'
80+
cell_name = get_tmp_directory() + os.sep + str(name) + '.py'
5681
return cell_name
5782

5883

ipykernel/debugger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ async def debugInfo(self, message):
507507
'isStarted': self.is_started,
508508
'hashMethod': 'Murmur2',
509509
'hashSeed': get_tmp_hash_seed(),
510-
'tmpFilePrefix': get_tmp_directory() + '/',
510+
'tmpFilePrefix': get_tmp_directory() + os.sep,
511511
'tmpFileSuffix': '.py',
512512
'breakpoints': breakpoint_list,
513513
'stoppedThreads': self.stopped_threads,

ipykernel/tests/test_debugger.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,9 @@ def test_rich_inspect_at_breakpoint(kernel_with_debug):
271271
)
272272

273273
assert reply["body"]["data"] == {"text/plain": locals_[0]["value"]}
274+
275+
276+
def test_convert_to_long_pathname():
277+
if sys.platform == 'win32':
278+
from ipykernel.compiler import _convert_to_long_pathname
279+
_convert_to_long_pathname(__file__)

0 commit comments

Comments
 (0)