Source code for gen_unnamed_pipe.setup.factory
# -*- coding: UTF-8 -*-
'''
Module
factory.py
Copyright
Copyright (C) 2026 Vladimir Roncevic <elektron.ronca@gmail.com>
gen_unnamed_pipe is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
gen_unnamed_pipe is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>.
Info
Factory for creating the gen_unnamed_pipe bundle.
'''
from __future__ import annotations
from ats_utilities.base.setup.factory import BaseBundleFactory
from ats_utilities.base.setup.bundle import BaseBundle
from ats_utilities.base.setup.options import BaseBundleOptions
from ats_utilities.context.bundle import ContextBundle
from ats_utilities.context.factory import ContextBundleFactory
from gen_unnamed_pipe.setup.bundle import GenUnnamedPipeBundle
from gen_unnamed_pipe.setup.options import GenUnnamedPipeBundleOptions
from gen_unnamed_pipe.setup.registry import GenUnnamedPipeBundleRegistry
from gen_unnamed_pipe.setup.dependencies import GenUnnamedPipeBundleDependencies
from gen_unnamed_pipe.setup.opt_validator import GenUnnamedPipeBundleOptionsValidator
from gen_unnamed_pipe.setup.keys import GenUnnamedPipeBundleKeys
from gen_unnamed_pipe.core.service.engine import Service
from gen_unnamed_pipe.infrastructure.subprocessor import SubProcessor
from gen_unnamed_pipe.infrastructure.cli.engine import CLI
from gen_unnamed_pipe.infrastructure.cli.setup.bundle import CLIBundle
from gen_unnamed_pipe.infrastructure.cli.setup.dependencies import CLIBundleDependencies
from gen_unnamed_pipe.infrastructure.cli.setup.registry import CLIBundleRegistry
from gen_unnamed_pipe.infrastructure.command.command import CommandBundle
from gen_unnamed_pipe.infrastructure.command.gen_unnamed_pipe_command_definition import GenUnnamedPipeCommandDefinition
from gen_unnamed_pipe.infrastructure.command.gen_unnamed_pipe_command_executor import GenUnnamedPipeCommandExecutor
__author__ = 'Vladimir Roncevic'
__copyright__ = '(C) 2026, https://vroncevic.github.io/gen_unnamed_pipe'
__credits__ = ['Vladimir Roncevic', 'Python Software Foundation']
__license__ = 'https://github.com/vroncevic/gen_unnamed_pipe/blob/dev/LICENSE'
__version__ = '1.0.9'
__maintainer__ = 'Vladimir Roncevic'
__email__ = 'elektron.ronca@gmail.com'
__status__ = 'Updated'
[docs]
class GenUnnamedPipeBundleFactory:
'''
Factory for creating the gen_unnamed_pipe bundle.
It defines:
:attributes:
| _info_file - Path to the gen_unnamed_pipe info file.
:methods:
| create_bundle - Creates the gen_unnamed_pipe bundle with optional pre-configured options.
| get_version - Returns the factory version.
'''
_info_file: str = 'gen_unnamed_pipe/infrastructure/config/gen_unnamed_pipe.cfg'
[docs]
@classmethod
def create_bundle(cls, options: GenUnnamedPipeBundleOptions | None = None) -> GenUnnamedPipeBundle:
'''
Creates the gen_unnamed_pipe bundle with optional pre-configured options.
:param options: The pre-configured options for the gen_unnamed_pipe bundle.
:return: The gen_unnamed_pipe bundle.
:exceptions:
| ATSValueError: The gen_unnamed_pipe bundle options must be provided and have proper values.
| ATSTypeError: The gen_unnamed_pipe bundle options must be an instance of Mapping and its
| attributes must be instances of their respective types.
| ATSValueError: The gen_unnamed_pipe bundle dependencies must be provided and have proper values.
| ATSTypeError: The gen_unnamed_pipe bundle dependencies must be an instance of Mapping and its
| attributes must be instances of their respective types.
| ATSValueError: The gen_unnamed_pipe bundle must be provided and have proper values.
| ATSTypeError: The gen_unnamed_pipe bundle must be an instance of GenUnnamedPipeBundle and
| its attributes must be instances of their respective types.
'''
if options is not None:
GenUnnamedPipeBundleOptionsValidator.validate(options)
info_file = options.get(GenUnnamedPipeBundleKeys.OPTION_INFO_FILE) if options else cls._info_file
context_bundle: ContextBundle = ContextBundleFactory.create_bundle()
base_bundle: BaseBundle = BaseBundleFactory.create_bundle(
options=BaseBundleOptions(
info_file=info_file,
use_generator=True,
context_bundle=context_bundle
)
)
subprocessor: SubProcessor = SubProcessor(generator=base_bundle.generation_manager)
service: Service = Service(subprocessor=subprocessor)
gen_unnamed_pipe_definition: GenUnnamedPipeCommandDefinition = GenUnnamedPipeCommandDefinition()
gen_unnamed_pipe_bundle: CommandBundle = CommandBundle(
definition=gen_unnamed_pipe_definition,
executor=GenUnnamedPipeCommandExecutor(gen_unnamed_pipe_definition)
)
cli_bundle: CLIBundle = CLIBundleRegistry.create_bundle(
dependencies=CLIBundleDependencies(
service=service,
parser=base_bundle.option_manager,
commands=[gen_unnamed_pipe_bundle]
)
)
cli: CLI = CLI(cli_bundle)
return GenUnnamedPipeBundleRegistry.create_bundle(
dependencies=GenUnnamedPipeBundleDependencies(
base=base_bundle,
service=service,
subprocessor=subprocessor,
cli=cli
)
)
[docs]
@classmethod
def get_version(cls) -> str:
'''
Returns the factory version.
:return: The factory version.
:exceptions: None.
'''
return __version__