Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if mod_name == "__main__":
mod_name = find_module_name_from_path(module.__file__)
path_jit_class = mpi.Path(backend.jit.path_class)
# 1. create a Python file with @jit functions and methods
python_path_dir = path_jit_class / mod_name.replace(".", os.path.sep)
python_path = python_path_dir / (cls_name + ".py")
if mpi.has_to_build(python_path, module.__file__):
from transonic.justintime import _get_module_jit
mod = _get_module_jit(backend_name=backend.name, index_frame=5)
if mpi.rank == 0:
python_path = mpi.PathSeq(python_path)
python_code = (
mod.info_analysis["codes_dependance_classes"][cls_name] + "\n"
)
python_code += backend.jit.produce_code_class(cls)
write_if_has_to_write(python_path, python_code)
python_path = mpi.Path(python_path)
mpi.barrier()
# 2. import the file
python_mod_name = path_jit_class.name + "." + mod_name + "." + cls_name
module = import_from_path(python_path, python_mod_name)
# 3. replace the methods
for name_method, method in jit_methods.items():
func = method.func
name_new_method = f"__new_method__{cls.__name__}__{name_method}"
def has_to_build(output_file: Path, input_file: Path):
"""Check if a file has to be (re)built"""
output_file = PathSeq(output_file)
input_file = PathSeq(input_file)
if not output_file.exists():
return True
mod_date_output = modification_date(output_file)
if mod_date_output < modification_date(input_file):
return True
return False
def has_to_build(output_file: Path, input_file: Path):
"""Check if a file has to be (re)built"""
output_file = PathSeq(output_file)
input_file = PathSeq(input_file)
if not output_file.exists():
return True
mod_date_output = modification_date(output_file)
if mod_date_output < modification_date(input_file):
return True
return False
openmp=self.openmp,
)
# for backend like numba
if not self.compiling:
backend_module = import_from_path(self.path_extension, name_mod)
assert backend.check_if_compiled(backend_module)
self.backend_func = getattr(backend_module, func_name)
ext_files = None
if mpi.rank == 0:
glob_name_ext_file = (
func_name + "_" + hex_src + "_*" + backend.suffix_extension
)
ext_files = list(
mpi.PathSeq(path_backend).parent.glob(glob_name_ext_file)
)
ext_files = mpi.bcast(ext_files)
if not ext_files:
if has_to_compile_at_import() and _COMPILE_JIT:
backenize_with_new_header()
self.backend_func = None
else:
path_ext = max(ext_files, key=lambda p: p.stat().st_ctime)
backend_module = import_from_path(path_ext, name_mod)
self.backend_func = getattr(backend_module, func_name)
# this is the function that will be called by the user
@wraps(func)
def type_collector(*args, **kwargs):
def name_ext_from_path_backend(self, path_backend):
"""Return an extension name given the path of a Pythran file"""
name = None
if mpi.rank == 0:
path_backend = PathSeq(path_backend)
if path_backend.exists():
with open(path_backend) as file:
src = file.read()
# quick fix to recompile when the header has been changed
for suffix in (".pythran", ".pxd"):
path_header = path_backend.with_suffix(suffix)
if path_header.exists():
with open(path_header) as file:
src += file.read()
else:
src = ""
name = path_backend.stem + "_" + make_hex(src) + self.suffix_extension
return mpi.bcast(name)