Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if name_ext_file is None:
name_ext_file = name_ext_from_path_backend(path)
if not force:
path_out = path.with_name(name_ext_file)
if not has_to_build(path_out, path):
logger.warning(
f"Do not pythranize {path} because it seems up-to-date "
"(but the compilation options may have changed). "
"You can force the compilation with the option -f."
)
return
if mpi.rank == 0:
logger.info(f"Schedule pythranization of file {path}")
if str_pythran_flags is not None:
flags = str_pythran_flags.strip().split()
else:
flags = []
def update_flags(flag):
if flag not in flags:
flags.append(flag)
if native and os.name != "nt":
update_flags("-march=native")
if xsimd:
update_flags("-DUSE_XSIMD")
parallel=True,
force=True,
):
if not force:
path_out = path.with_name(name_ext_file)
if not has_to_build(path_out, path):
logger.warning(
f"Do not {backend}ize {path} because it seems up-to-date "
"(but the compilation options may have changed). "
"You can force the compilation with the option -f."
)
return
if mpi.rank == 0:
logger.info(f"Schedule {backend}ization of file {path}")
if str_accelerator_flags is not None:
flags = str_accelerator_flags.strip().split()
else:
flags = []
def update_flags(flag):
if flag not in flags:
flags.append(flag)
if native and os.name != "nt":
update_flags("-march=native")
if xsimd:
update_flags("-DUSE_XSIMD")
"jitted_dicts": jitted_dicts,
"codes_dependance": codes_dependance,
"codes_dependance_classes": codes_dependance_classes,
"special": special,
}
self.backend = backend = backends[backend_name]
path_jit = mpi.Path(backend.jit.path_base)
path_jit_class = mpi.Path(backend.jit.path_class)
# TODO: check if these files have to be written here...
# Write exterior code for functions
for file_name, code in code_ext["function"].items():
path_ext = path_jit / self.module_name.replace(".", os.path.sep)
path_ext_file = path_ext / (file_name + ".py")
write_if_has_to_write(path_ext_file, format_str(code), logger.info)
# Write exterior code for classes
for file_name, code in code_ext["class"].items():
path_ext = path_jit_class / self.module_name.replace(".", os.path.sep)
path_ext_file = path_ext / (file_name + ".py")
write_if_has_to_write(path_ext_file, format_str(code), logger.info)
"It seems that a jitted Pythran function has been called "
'with a "reshaped" array which is not supported by Pythran.'
)
raise
logger.debug(error)
if self.compiling or not _COMPILE_JIT:
return func(*args, **kwargs)
if (
self.backend_func
and error
and error.startswith("Invalid call to pythranized function `")
):
logger.debug(error)
logger.info(
f"{backend.name_capitalized} function `{func_name}` called with new types."
)
logger.debug(
"Transonic is going to recompute the function for the new types."
)
arg_types = [
backend.jit.compute_typename_from_object(arg)
for arg in itertools.chain(args, kwargs.values())
]
backenize_with_new_header(arg_types)
return func(*args, **kwargs)
if not args.path and not args.clear_cache:
logger.warning("No python files given. Nothing to do! ✨ 🍰 ✨.")
return
if args.clear_cache:
clear_cached_extensions(args.clear_cache, args.force, args.backend)
return
if args.verbose is None:
logger.set_level(None)
elif args.verbose == 1:
logger.set_level("info")
elif args.verbose > 1:
logger.set_level("debug")
logger.info(args)
path = args.path
if isinstance(path, list) and len(path) == 1:
path = path[0]
if isinstance(path, list):
paths = path
else:
path = Path(path)
if path.is_file():
paths = (path,)
elif path.is_dir():
paths = path.glob("*.py")
else:
paths = glob(str(path))
self.backend = backend = backends[backend_name]
path_jit = mpi.Path(backend.jit.path_base)
path_jit_class = mpi.Path(backend.jit.path_class)
# TODO: check if these files have to be written here...
# Write exterior code for functions
for file_name, code in code_ext["function"].items():
path_ext = path_jit / self.module_name.replace(".", os.path.sep)
path_ext_file = path_ext / (file_name + ".py")
write_if_has_to_write(path_ext_file, format_str(code), logger.info)
# Write exterior code for classes
for file_name, code in code_ext["class"].items():
path_ext = path_jit_class / self.module_name.replace(".", os.path.sep)
path_ext_file = path_ext / (file_name + ".py")
write_if_has_to_write(path_ext_file, format_str(code), logger.info)
written = write_if_has_to_write(
path_backend, code_backend, logger.info, force
)
if not written:
logger.warning(f"Code in file {path_backend} already up-to-date.")
return
if self.suffix_header:
path_header = (path_dir / path_py.name).with_suffix(
self.suffix_header
)
write_if_has_to_write(path_header, code_header, logger.info, force)
logger.info(f"File {path_backend} updated")
return path_backend
if not analyse:
with open(path_py) as file:
code = file.read()
analyse = analyse_aot(code, path_py, self.name)
code_backend, codes_ext, code_header = self._make_backend_code(
path_py, analyse
)
if not code_backend:
return
logger.debug(f"code_{self.name}:\n{code_backend}")
for file_name, code in codes_ext["function"].items():
path_ext_file = path_dir / (file_name + ".py")
write_if_has_to_write(
path_ext_file, format_str(code), logger.info, force
)
for file_name, code in codes_ext["class"].items():
path_ext_file = (
path_dir.parent / f"__{self.name}__" / (file_name + ".py")
)
write_if_has_to_write(
path_ext_file, format_str(code), logger.info, force
)
written = write_if_has_to_write(
path_backend, code_backend, logger.info, force
)
if not written:
logger.warning(f"Code in file {path_backend} already up-to-date.")