src package¶
Submodules¶
Module contents¶
pycompile imports
- class src.CompilerCommands¶
Bases:
object- cython = 'cythonize {} -3 --inplace'¶
- cython_bench = 'cythonize {} -3 --inplace --quiet 2>/dev/null'¶
- nuitka = 'python -m nuitka --module {}'¶
- nuitka_bench = 'python -m nuitka --quiet --module {} 2>/dev/null'¶
- class src.CompilerHandler(files: dict[str, list[Path]], compiler: CompilerWrapper, clean_source: bool = False, keep_builds: bool = True)¶
Bases:
objectCompilerHandler is responsible for compiling all the
.pyfiles usingCythonorNuitkaexample usage:compiler_handler = CompilerHandler(files=dir_files,compiler=compiler, clean_source=True,keep_builds=True) compiler_handler.start()
- clean_executables() None¶
Cleans all the .so files.
- start() None¶
For each
.pyfile runs the compiler command to build the final executable.so
- class src.CompilerWrapper¶
Bases:
ABC- abstract cleanup(file_path: Path) None¶
- abstract property cmd: str¶
- class src.CythonWrapper(cmd: str = 'cythonize {} -3 --inplace')¶
Bases:
CompilerWrapperCython is a programming language, a superset of the Python programming language, designed to give C-like performance with code that is written mostly in Python with optional additional C-inspired syntax. Cython is a compiled language that is typically used to generate CPython extension modules https://cython.org/
- property cmd: str¶
- class src.FileHandler(input_path: Path, additional_exclude_patterns: list[str] | None = None)¶
Bases:
objectFileHandler is responsible for finding all the
.pyfiles within theinput_path. example usage:dir_files = FileHandler("./my_module").start()
By default, all the
testfiles and any__init__files are excluded.- Parameters:
input_path – Should be a valid file/directory path.
additional_exclude_patterns – Any optional additional glob patterns.
- collect_with_pattern(pattern: str) Generator[Path, None, None]¶
Collects all python files within the
input_pathwhere they mach thepattern- Parameters:
pattern – str containing glob patters
- Returns:
A Generator of file paths.
- property exclude_patterns: list[str]¶
Current glob exclude patterns
- property input_path: Path¶
Current input path
- start() dict[str, list[Path]]¶
For the given
input pathcollect all valid.pyfiles based on theexclude_patterns- Returns:
a dictionary for valid files within each directory.
- class src.NuitkaWrapper(cmd: str = 'python -m nuitka --module {}')¶
Bases:
CompilerWrapperNuitka is a source-to-source compiler which compiles Python code to C source code, applying some compile-time optimizations in the process such as constant folding and propagation, built-in call prediction, type inference, and conditional statement execution. https://nuitka.net/
- cleanup(file_path: Path) None¶
Deletes the build`directory alongside with the `file.pyi temp file.
- property cmd: str¶
- src.change_dir(file_path: Path) Generator[None, None, None]¶
Context manager to change the current active directory at the file path parents. This is needed to be able to include the compiled files in the same directory as the source files.
- src.run_sub_process(files: list[Path], compile_cmd: str) None¶
For each file path run in a subprocess the corresponding compiler command.
- src.setup_logging(verbose: int) None¶
setup logging helper function