transonic.util

Internal utilities

Public API

transonic.util.set_compile_at_import(value=True)[source]

Control the “compile_at_import” mode

Internal API

transonic.util.find_module_name_from_path(path_py: pathlib.Path)[source]

Find the module name from the path of a Python file

It is done by looking to sys.path to see how the module can be imported.

transonic.util.get_module_name(frame)[source]

Get the full module name

transonic.util.modification_date(filename)[source]

Get the modification date of a file

transonic.util.has_to_build(output_file: pathlib.Path, input_file: pathlib.Path)[source]

Check if a file has to be (re)built

transonic.util.get_source_without_decorator(func: Callable)[source]

Get the source of a function without its decorator

class transonic.util.TypeHintRemover[source]

Bases: ast.NodeTransformer

Strip the type hints

from https://stackoverflow.com/a/42734810/1779806

transonic.util.strip_typehints(source)[source]

Strip the type hints from a function

transonic.util.get_ipython_input(last=True)[source]

Get the input code when called from IPython

transonic.util.get_info_from_ipython()[source]

Get the input code and a “filename” when called from IPython

transonic.util.has_to_compile_at_import()[source]

Check if transonic has to pythranize at import time

transonic.util.import_from_path(path: pathlib.Path, module_name: str)[source]

Import a .py file or an extension from its path

transonic.util.query_yes_no(question: str, default: str = None, force: bool = False)[source]

User yes or no query

transonic.util.clear_cached_extensions(module_name: str, force: bool, backend: str)[source]

Delete the cached extensions related to a module

transonic.util.is_method(func)[source]

Determine wether a function is going to be used as a method

transonic.util.has_to_write(path_file: pathlib.Path, new_code: str)[source]

Check if a file exists and contains a code

transonic.util.write_if_has_to_write(path_file: pathlib.Path, new_code: str, logger=None, force=False)[source]

Write a file if it doesn’t exist or doesn’t contain a particular code

Functions

can_import_accelerator(backend)

clear_cached_extensions(module_name, force, …)

Delete the cached extensions related to a module

find_module_name_from_path(path_py)

Find the module name from the path of a Python file

format_str(src_contents)

get_info_from_ipython()

Get the input code and a “filename” when called from IPython

get_ipython_input([last])

Get the input code when called from IPython

get_module_name(frame)

Get the full module name

get_name_calling_module(index_frame)

get_source_without_decorator(func)

Get the source of a function without its decorator

has_to_compile_at_import()

Check if transonic has to pythranize at import time

has_to_write(path_file, new_code)

Check if a file exists and contains a code

import_from_path(path, module_name)

Import a .py file or an extension from its path

is_method(func)

Determine wether a function is going to be used as a method

make_code_from_fdef_node(fdef)

print_versions([accelerators])

query_yes_no(question, default, force)

User yes or no query

set_compile_at_import([value])

Control the “compile_at_import” mode

strip_typehints(source)

Strip the type hints from a function

timeit([stmt, setup, total_duration, globals])

timeit with a approximate total_duration

timeit_verbose(stmt[, setup, …])

write_if_has_to_write(path_file, new_code[, …])

Write a file if it doesn’t exist or doesn’t contain a particular code

Classes

TypeHintRemover

Strip the type hints