1
1
from IPython .core .compilerop import CachingCompiler
2
2
import tempfile
3
3
import os
4
+ import sys
4
5
5
6
6
7
def murmur2_x86 (data , seed ):
@@ -36,11 +37,35 @@ def murmur2_x86(data, seed):
36
37
37
38
return h
38
39
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
39
64
40
65
def get_tmp_directory ():
41
- tmp_dir = tempfile .gettempdir ()
66
+ tmp_dir = convert_to_long_pathname ( tempfile .gettempdir () )
42
67
pid = os .getpid ()
43
- return tmp_dir + '/ ipykernel_' + str (pid )
68
+ return tmp_dir + os . sep + ' ipykernel_' + str (pid )
44
69
45
70
46
71
def get_tmp_hash_seed ():
@@ -52,7 +77,7 @@ def get_file_name(code):
52
77
cell_name = os .environ .get ("IPYKERNEL_CELL_NAME" )
53
78
if cell_name is None :
54
79
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'
56
81
return cell_name
57
82
58
83
0 commit comments