Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of the debugger #597

Merged
merged 14 commits into from
Mar 8, 2021
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu, macos, windows]
python-version: [ '3.6', '3.7', '3.8', '3.9', 'pypy3' ]
python-version: [ '3.7', '3.8', '3.9' ]
exclude:
- os: windows
python-version: pypy3
Expand Down
64 changes: 64 additions & 0 deletions ipykernel/compiler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from IPython.core.compilerop import CachingCompiler
import tempfile
import os

def murmur2_x86(data, seed):
m = 0x5bd1e995
length = len(data)
h = seed ^ length
rounded_end = (length & 0xfffffffc)
for i in range(0, rounded_end, 4):
k = (ord(data[i]) & 0xff) | ((ord(data[i + 1]) & 0xff) << 8) | \
((ord(data[i + 2]) & 0xff) << 16) | (ord(data[i + 3]) << 24)
k = (k * m) & 0xffffffff
k ^= k >> 24
k = (k * m) & 0xffffffff

h = (h * m) & 0xffffffff
h ^= k

val = length & 0x03
k = 0
if val == 3:
k = (ord(data[rounded_end + 2]) & 0xff) << 16
if val in [2, 3]:
k |= (ord(data[rounded_end + 1]) & 0xff) << 8
if val in [1, 2, 3]:
k |= ord(data[rounded_end]) & 0xff
h ^= k
h = (h * m) & 0xffffffff

h ^= h >> 13
h = (h * m) & 0xffffffff
h ^= h >> 15

return h

def get_tmp_directory():
tmp_dir = tempfile.gettempdir()
pid = os.getpid()
return tmp_dir + '/ipykernel_' + str(pid)

def get_tmp_hash_seed():
hash_seed = 0xc70f6907
return hash_seed

def get_file_name(code):
name = murmur2_x86(code, get_tmp_hash_seed())
return get_tmp_directory() + '/' + str(name) + '.py'

class XCachingCompiler(CachingCompiler):

def __init__(self, *args, **kwargs):
super(XCachingCompiler, self).__init__(*args, **kwargs)
self.filename_mapper = None
self.log = None

def get_code_name(self, raw_code, code, number):
filename = get_file_name(raw_code)

if self.filename_mapper is not None:
self.filename_mapper(filename, number)

return filename

2 changes: 2 additions & 0 deletions ipykernel/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class ControlThread(Thread):
def __init__(self, **kwargs):
Thread.__init__(self, **kwargs)
self.io_loop = IOLoop(make_current=False)
self.pydev_do_not_trace = True
self.is_pydev_daemon_thread = True

def run(self):
self.io_loop.make_current()
Expand Down
Loading