Coverage for src / ezcompiler / adapters / compiler_factory.py: 100.00%
25 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-27 06:49 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-27 06:49 +0000
1# ///////////////////////////////////////////////////////////////
2# COMPILER_FACTORY - Compiler factory for creating compiler instances
3# Project: ezcompiler
4# ///////////////////////////////////////////////////////////////
6"""
7Compiler factory - Factory for creating compiler instances.
9This module provides a centralized factory for creating compiler
10instances based on type and configuration.
11"""
13from __future__ import annotations
15# ///////////////////////////////////////////////////////////////
16# IMPORTS
17# ///////////////////////////////////////////////////////////////
18# Local imports
19from ..shared.compiler_config import CompilerConfig
20from ..shared.exceptions import CompilationError
21from .base_compiler import BaseCompiler
22from .cx_freeze_compiler import CxFreezeCompiler
23from .nuitka_compiler import NuitkaCompiler
24from .pyinstaller_compiler import PyInstallerCompiler
26# ///////////////////////////////////////////////////////////////
27# CLASSES
28# ///////////////////////////////////////////////////////////////
31class CompilerFactory:
32 """Factory class for creating compiler instances."""
34 @staticmethod
35 def create_compiler(config: CompilerConfig, compiler_name: str) -> BaseCompiler:
36 """
37 Create a compiler instance from its name.
39 Args:
40 config: Compiler configuration to inject
41 compiler_name: Compiler name (Cx_Freeze, PyInstaller, Nuitka)
43 Returns:
44 BaseCompiler: Concrete compiler instance
46 Raises:
47 CompilationError: If compiler name is unsupported
48 """
49 normalized_name = compiler_name.strip()
51 if normalized_name == "Cx_Freeze":
52 return CxFreezeCompiler(config=config)
53 if normalized_name == "PyInstaller":
54 return PyInstallerCompiler(config=config)
55 if normalized_name == "Nuitka":
56 return NuitkaCompiler(config=config)
58 raise CompilationError(f"Unsupported compiler: {normalized_name}")
60 @staticmethod
61 def create_from_config(config: CompilerConfig) -> BaseCompiler:
62 """
63 Create a compiler instance using the config default compiler.
65 Args:
66 config: Compiler configuration
68 Returns:
69 BaseCompiler: Concrete compiler instance
71 Raises:
72 CompilationError: If config compiler is unsupported
73 """
74 compiler_name = config.compiler if config.compiler != "auto" else "Cx_Freeze"
75 return CompilerFactory.create_compiler(
76 config=config, compiler_name=compiler_name
77 )
79 @staticmethod
80 def get_supported_compilers() -> list[str]:
81 """Return the list of supported compiler names."""
82 return ["Cx_Freeze", "PyInstaller", "Nuitka"]