Skip to content

Commit

Permalink
[skip ci] enforce code format
Browse files Browse the repository at this point in the history
  • Loading branch information
taichi-gardener committed Jul 14, 2020
1 parent 0ede8ae commit 1121ab3
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 24 deletions.
6 changes: 4 additions & 2 deletions misc/idle_hello.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import taichi as ti


@ti.kernel
def func(): pass
def func():
pass

func()

func()
34 changes: 23 additions & 11 deletions python/taichi/idle_hacker.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def get_filename(pid):

def idle_ipc_write(source):
with open(get_filename(os.getpid()), 'a') as f:
f.write('\n===\n' + source)
f.write('\n===\n' + source)


def hack(InteractiveInterpreter):
Expand All @@ -36,16 +36,30 @@ def show_error():
path = code.__file__
except:
path = '/usr/lib/python3.8/code.py'
print('It\'s detected that you are using Python IDLE in **interactive mode**.')
print('However, Taichi could not be fully functional due to IDLE limitation, sorry :(')
print('Either run Taichi in IDLE file mode, or use IPython / Jupyter notebook instead.')
print('We do care about your experience, no matter which shell you prefer to use.')
print('So, if you would like to play with Taichi in your favorite IDLE, we may do a dirty hack:')
print(f'Open "{path}" and append the following line to the buttom of this file:')
print(
'It\'s detected that you are using Python IDLE in **interactive mode**.'
)
print(
'However, Taichi could not be fully functional due to IDLE limitation, sorry :('
)
print(
'Either run Taichi in IDLE file mode, or use IPython / Jupyter notebook instead.'
)
print(
'We do care about your experience, no matter which shell you prefer to use.'
)
print(
'So, if you would like to play with Taichi in your favorite IDLE, we may do a dirty hack:'
)
print(
f'Open "{path}" and append the following line to the buttom of this file:'
)
print('')
print(f' {our_code}')
print('')
print('If you don\'t find where to add, we provided a script to automatically inject the code:')
print(
'If you don\'t find where to add, we provided a script to automatically inject the code:'
)
print('')
if ti.get_os_name() == 'win':
print(' python3 -m taichi idle_hacker')
Expand All @@ -55,8 +69,6 @@ def show_error():
print('Then, restart IDLE and enjoy, the sky is blue and we are wizards!')




def startup_clean():
filename = get_filename(os.getppid())
try:
Expand Down Expand Up @@ -99,7 +111,7 @@ def main():
print('Appending our hack code...')

with open(code.__file__, 'a') as f:
f.write('\n' + our_code)
f.write('\n' + our_code)

print('Done, thank for trusting!')
return 0
Expand Down
12 changes: 3 additions & 9 deletions python/taichi/lang/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class ShellInspectorWrapper:
we will redirect getsource() calls to the corresponding inspector
provided by / suitable for each type of shell.
"""

@staticmethod
def get_shell_name(exclude_script=False):
"""
Expand Down Expand Up @@ -58,7 +57,6 @@ def get_shell_name(exclude_script=False):

return ShellType.SCRIPT


@staticmethod
def create_inspector(name):
if name is None:
Expand Down Expand Up @@ -87,7 +85,6 @@ def create_inspector(name):
else:
raise RuntimeError(f'Shell type "{name}" not supported')


def __init__(self):
self.name = self.get_shell_name()
if self.name is not None:
Expand All @@ -98,16 +95,16 @@ def __init__(self):
if hasattr(self.inspector, 'startup_clean'):
self.inspector.startup_clean()


def try_reset_shell_type(self):
new_name = self.get_shell_name(exclude_script=True)
if self.name != new_name:
print(f'[Taichi] Shell type changed from "{self.name}" to "{new_name}"')
print(
f'[Taichi] Shell type changed from "{self.name}" to "{new_name}"'
)

self.name = new_name
self.inspector = self.create_inspector(self.name)


def _catch_forward(foo):
"""
If Taichi starts within IDLE file mode, and after that user moved to interactive mode,
Expand All @@ -126,7 +123,6 @@ def wrapped(self, *args, **kwargs):

return wrapped


@_catch_forward
def getsource(self, o):
return self.inspector.getsource(o)
Expand All @@ -140,10 +136,8 @@ def getsourcefile(self, o):
return self.inspector.getsourcefile(o)



class IPythonInspectorWrapper:
"""`inspect` module wrapper for IPython / Jupyter notebook"""

def __init__(self):
pass

Expand Down
1 change: 1 addition & 0 deletions python/taichi/lang/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def to_taichi_type(dt):

raise AssertionError("Unknown type {}".format(dt))


def deprecated(old, new):
import functools

Expand Down
4 changes: 2 additions & 2 deletions python/taichi/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -974,8 +974,8 @@ def debug(self, arguments: list = sys.argv[2:]):
@register
def idle_hacker(self, arguments: list = sys.argv[2:]):
"""Run idle hack code injector"""
parser = argparse.ArgumentParser(prog='ti idle_hacker',
description=f"{self.idle_hacker.__doc__}")
parser = argparse.ArgumentParser(
prog='ti idle_hacker', description=f"{self.idle_hacker.__doc__}")
args = parser.parse_args(arguments)

from .idle_hacker import main
Expand Down

0 comments on commit 1121ab3

Please sign in to comment.