From 1121ab3e9b6088749961060c5882959a4f44bd73 Mon Sep 17 00:00:00 2001 From: Taichi Gardener Date: Tue, 14 Jul 2020 00:03:58 -0400 Subject: [PATCH] [skip ci] enforce code format --- misc/idle_hello.py | 6 ++++-- python/taichi/idle_hacker.py | 34 +++++++++++++++++++++++----------- python/taichi/lang/shell.py | 12 +++--------- python/taichi/lang/util.py | 1 + python/taichi/main.py | 4 ++-- 5 files changed, 33 insertions(+), 24 deletions(-) diff --git a/misc/idle_hello.py b/misc/idle_hello.py index 42551d8bb46a4b..8e49844690ce2b 100644 --- a/misc/idle_hello.py +++ b/misc/idle_hello.py @@ -1,7 +1,9 @@ import taichi as ti + @ti.kernel -def func(): pass +def func(): + pass -func() +func() diff --git a/python/taichi/idle_hacker.py b/python/taichi/idle_hacker.py index 1a8b5693862221..0792b74297f4ac 100644 --- a/python/taichi/idle_hacker.py +++ b/python/taichi/idle_hacker.py @@ -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): @@ -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') @@ -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: @@ -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 diff --git a/python/taichi/lang/shell.py b/python/taichi/lang/shell.py index c55775ee9f3d37..30fafd3e923d32 100644 --- a/python/taichi/lang/shell.py +++ b/python/taichi/lang/shell.py @@ -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): """ @@ -58,7 +57,6 @@ def get_shell_name(exclude_script=False): return ShellType.SCRIPT - @staticmethod def create_inspector(name): if name is None: @@ -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: @@ -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, @@ -126,7 +123,6 @@ def wrapped(self, *args, **kwargs): return wrapped - @_catch_forward def getsource(self, o): return self.inspector.getsource(o) @@ -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 diff --git a/python/taichi/lang/util.py b/python/taichi/lang/util.py index 3d7f95ae93f83e..3fcf3678de7389 100644 --- a/python/taichi/lang/util.py +++ b/python/taichi/lang/util.py @@ -164,6 +164,7 @@ def to_taichi_type(dt): raise AssertionError("Unknown type {}".format(dt)) + def deprecated(old, new): import functools diff --git a/python/taichi/main.py b/python/taichi/main.py index 9968b6f818b2c6..cb06440396ed28 100644 --- a/python/taichi/main.py +++ b/python/taichi/main.py @@ -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