Skip to content

Commit

Permalink
[skip ci] enforce code format
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanming-hu committed Mar 14, 2020
1 parent 016fe6c commit 2cac539
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
2 changes: 1 addition & 1 deletion misc/format_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def do_GET(self):

# self.exec(f'git checkout master')
def x():
a = 1
a = 1


def run(addr, port):
Expand Down
29 changes: 20 additions & 9 deletions python/taichi/core/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def import_tc_core(tmp_dir=None):
import taichi_core as core
except Exception as e:
if isinstance(e, ImportError):
print("Share object taichi_core import failed. If you are on Windows, please consider installing \"Microsoft Visual C++ Redistributable\" (https://aka.ms/vs/16/release/vc_redist.x64.exe)")
print(
"Share object taichi_core import failed. If you are on Windows, please consider installing \"Microsoft Visual C++ Redistributable\" (https://aka.ms/vs/16/release/vc_redist.x64.exe)"
)
raise e
tc_core = core
if get_os_name() != 'win':
Expand Down Expand Up @@ -127,6 +129,7 @@ def format(all=False, diff=None):

create_sand_box_on_windows = True


def build():
tmp_cwd = os.getcwd()
bin_dir = get_build_directory()
Expand All @@ -151,6 +154,7 @@ def build():

os.chdir(tmp_cwd)


def prepare_sandbox(src):
global g_tmp_dir
assert os.path.exists(src)
Expand Down Expand Up @@ -258,6 +262,7 @@ def prepare_sandbox(src):
if log_level:
tc_core.set_logging_level(log_level)


def get_dll_name(name):
if get_os_name() == 'linux':
return 'libtaichi_%s.so' % name
Expand Down Expand Up @@ -295,7 +300,7 @@ def at_startup():
if not os.path.exists(output_dir):
print('Making output directory')
os.mkdir(output_dir)

tc_core.set_core_state_python_imported(True)


Expand All @@ -321,26 +326,32 @@ def task():

proc = multiprocessing.Process(target=task, daemon=True)
proc.start()



def require_version(major, minor=None, patch=None):
versions = [
int(tc_core.get_version_major()),
int(tc_core.get_version_minor()),
int(tc_core.get_version_patch()),
int(tc_core.get_version_major()),
int(tc_core.get_version_minor()),
int(tc_core.get_version_patch()),
]
match = major == versions[0] and (minor < versions[1] or minor == versions[1] and patch <= versions[2])
match = major == versions[0] and (
minor < versions[1] or minor == versions[1] and patch <= versions[2])
if match:
return
else:
print("Taichi version mismatch. required >= {}.{}.{}".format(major, minor, patch))
print("Taichi version mismatch. required >= {}.{}.{}".format(
major, minor, patch))
print("Installed =", tc_core.get_version_string())
raise Exception("Taichi version mismatch")


at_startup()

device_string = 'cpu only' if not tc_core.with_cuda() else 'cuda {}'.format(
tc_core.cuda_version())
print(f'[Taichi] version {tc_core.get_version_string()}, {device_string}, commit {tc_core.get_commit_hash()[:8]}, python {sys.version_info[0]}.{sys.version_info[1]}.{sys.version_info[2]}')
print(
f'[Taichi] version {tc_core.get_version_string()}, {device_string}, commit {tc_core.get_commit_hash()[:8]}, python {sys.version_info[0]}.{sys.version_info[1]}.{sys.version_info[2]}'
)

if not is_release():
tc_core.set_core_trigger_gdb_when_crash(True)
16 changes: 11 additions & 5 deletions python/taichi/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,19 @@ def test_python(test_files=(), verbose=False):
if verbose:
args += ['-s']
if len(test_files) == 0 or len(test_files) > 4:
if int(pytest.main([os.path.join(root_dir, 'misc/empty_pytest.py'), '-n1'])) == 0: # if pytest has xdist
if int(
pytest.main([os.path.join(root_dir, 'misc/empty_pytest.py'),
'-n1'])) == 0: # if pytest has xdist
try:
from multiprocessing import cpu_count
threads = min(8, cpu_count()) # To prevent running out of memory
threads = min(8, cpu_count()) # To prevent running out of memory
except:
threads = 2
env_threads = os.environ.get('TI_TEST_THREADS', '')
if env_threads:
threads = int(env_threads)
print(f'Following TI_TEST_THREADS to use {threads} testing thread(s)...')
print(
f'Following TI_TEST_THREADS to use {threads} testing thread(s)...')
print(f'Starting {threads} testing thread(s)...')
if threads > 1:
args += ['-n', str(threads)]
Expand All @@ -66,7 +69,8 @@ def main(debug=False):
if 'TI_DEBUG' in os.environ:
val = os.environ['TI_DEBUG']
if val not in ['0', '1']:
raise ValueError("Environment variable TI_DEBUG can only have value 0 or 1.")
raise ValueError(
"Environment variable TI_DEBUG can only have value 0 or 1.")
if debug:
lines.append(u' *****************Debug Mode****************')
os.environ['TI_DEBUG'] = '1'
Expand Down Expand Up @@ -150,7 +154,8 @@ def main(debug=False):
elif mode == "interpolate":
interpolate_frames('.')
elif mode == "doc":
os.system('cd {}/docs && sphinx-build -b html . build'.format(ti.get_repo_directory()))
os.system('cd {}/docs && sphinx-build -b html . build'.format(
ti.get_repo_directory()))
elif mode == "video":
files = sorted(os.listdir('.'))
files = list(filter(lambda x: x.endswith('.png'), files))
Expand Down Expand Up @@ -248,5 +253,6 @@ def main(debug=False):
def main_debug():
main(debug=True)


if __name__ == '__main__':
exit(main())

0 comments on commit 2cac539

Please sign in to comment.