def at_startup(): assert os.path.exists(get_repo_directory( )), 'Please make sure $TAICHI_REPO_DIR [' + get_repo_directory( ) + '] exists.' output_dir = get_output_directory() if not os.path.exists(output_dir): print('Making output directory') os.mkdir(output_dir) # Load modules load_module('lang_core') tc_core.set_core_state_python_imported(True)
def at_startup(): assert os.path.exists(get_repo_directory( )), 'Please make sure $TAICHI_REPO_DIR [' + get_repo_directory() + '] exists.' output_dir = get_output_directory() if not os.path.exists(output_dir): print('Making output directory') os.mkdir(output_dir) # Load modules f = open(os.path.join(get_repo_directory(), 'modules.txt'), 'r') modules = f.readline().strip().split(';') for module in modules: if module != '': load_module(module) tc_core.set_core_state_python_imported(True) f.close()
def __init__(self, target_file): self.target_file = target_file self.src = '' self.dir = get_output_path(get_unique_task_id()) os.mkdir(self.dir) self.unit_dll = tc_core.create_unit_dll() self.src_path = os.path.join(self.dir, 'unit.cpp') self.dll_path = os.path.join(self.dir, 'build', 'libunit.dylib') self.cmakelists_path = os.path.join(self.dir, 'CMakeLists.txt') cmakelists_src = os.path.join(get_repo_directory(), 'python', 'taichi', 'misc', 'CMakeLists.txt') shutil.copy(cmakelists_src, self.cmakelists_path)
def load_module(name, verbose=True): if verbose: print('Loading module', name) try: if '.so' in name: ctypes.PyDLL(name) else: ctypes.PyDLL( os.path.join(get_repo_directory(), 'build', get_dll_name(name))) except Exception as e: print(Fore.YELLOW + "Warning: module [{}] loading failed: {}".format( name, e) + Style.RESET_ALL)
elif get_os_name() == 'win': bin_dir = get_bin_directory() dll_path = os.path.join(bin_dir, 'Release', 'taichi_core.dll') if not os.path.exists(dll_path): build() # The problem here is, on windows, when an dll/pyd is loaded, we can not write to it any more old_wd = os.getcwd() os.chdir(bin_dir) if CREATE_SAND_BOX_ON_WINDOWS: # Create a sandbox for separated core lib development and loading dir = os.path.join(get_output_directory(), 'tmp', get_unique_task_id()) os.environ['PATH'] += ';' + (os.path.join(get_repo_directory(), 'external', 'lib')) os.makedirs(dir) shutil.copy(dll_path, os.path.join(dir, 'taichi_core.pyd')) sys.path.append(dir) else: shutil.copy(dll_path, os.path.join(bin_dir, 'taichi_core.pyd')) sys.path.append(bin_dir) import taichi_core as tc_core os.chdir(old_wd) def get_dll_name(name): if get_os_name() == 'linux': return 'libtaichi_%s.so' % name
elif get_os_name() == 'win': bin_dir = get_bin_directory() dll_path1 = os.path.join(bin_dir, 'RelWithDebInfo', 'taichi_core.dll') dll_path2 = os.path.join(bin_dir, 'libtaichi_core.dll') assert os.path.exists(dll_path1) and not os.path.exists(dll_path2) # On windows when an dll/pyd is loaded, we can not write to it any more old_wd = os.getcwd() os.chdir(bin_dir) if create_sand_box_on_windows: # Create a sandbox for separated core lib development and loading dir = os.path.join(get_output_directory(), 'tmp', get_unique_task_id()) lib_dir = os.path.join(get_repo_directory(), 'external', 'lib') os.environ['PATH'] += ';' + lib_dir os.makedirs(dir) if os.path.exists(dll_path1): shutil.copy(dll_path1, os.path.join(dir, 'taichi_core.pyd')) else: shutil.copy(dll_path2, os.path.join(dir, 'taichi_core.pyd')) os.environ['PATH'] += ';' + dir sys.path.append(dir) else: shutil.copy(dll_path, os.path.join(bin_dir, 'taichi_core.pyd')) sys.path.append(bin_dir) try: import taichi_core as tc_core except Exception as e:
def get_repo(): from git import Repo repo = Repo(get_repo_directory()) return repo