Source code for gen_mmap.setup.factory
# -*- coding: UTF-8 -*-
'''
Module
factory.py
Copyright
Copyright (C) 2026 Vladimir Roncevic <elektron.ronca@gmail.com>
gen_mmap 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_mmap 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_mmap bundle.
'''
from __future__ import annotations
from os.path import abspath, dirname, join
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_mmap.setup.bundle import GenMmapBundle
from gen_mmap.setup.options import GenMmapBundleOptions
from gen_mmap.setup.registry import GenMmapBundleRegistry
from gen_mmap.setup.dependencies import GenMmapBundleDependencies
from gen_mmap.setup.opt_validator import GenMmapBundleOptionsValidator
from gen_mmap.setup.keys import GenMmapBundleKeys
from gen_mmap.core.service.engine import Service
from gen_mmap.infrastructure.subprocessor import SubProcessor
from gen_mmap.infrastructure.cli.engine import CLI
from gen_mmap.infrastructure.cli.setup.bundle import CLIBundle
from gen_mmap.infrastructure.cli.setup.dependencies import CLIBundleDependencies
from gen_mmap.infrastructure.cli.setup.registry import CLIBundleRegistry
from gen_mmap.infrastructure.command.command import CommandBundle
from gen_mmap.infrastructure.command.gen_mmap_command_definition import GenMmapCommandDefinition
from gen_mmap.infrastructure.command.gen_mmap_command_executor import GenMmapCommandExecutor
__author__ = 'Vladimir Roncevic'
__copyright__ = '(C) 2026, https://vroncevic.github.io/gen_mmap'
__credits__ = ['Vladimir Roncevic', 'Python Software Foundation']
__license__ = 'https://github.com/vroncevic/gen_mmap/blob/dev/LICENSE'
__version__ = '1.0.6'
__maintainer__ = 'Vladimir Roncevic'
__email__ = 'elektron.ronca@gmail.com'
__status__ = 'Updated'
[docs]
class GenMmapBundleFactory:
'''
Factory for creating the gen_mmap bundle.
It defines:
:attributes:
| _info_file - Path to the gen_mmap info file.
:methods:
| create_bundle - Creates the gen_mmap bundle with optional pre-configured options.
| get_version - Returns the factory version.
'''
_info_file: str = join(
dirname(dirname(abspath(__file__))), 'infrastructure', 'config', 'gen_mmap.cfg'
)
[docs]
@classmethod
def create_bundle(cls, options: GenMmapBundleOptions | None = None) -> GenMmapBundle:
'''
Creates the gen_mmap bundle with optional pre-configured options.
:param options: The pre-configured options for the gen_mmap bundle.
:return: The gen_mmap bundle.
:exceptions:
| ATSValueError: The gen_mmap bundle options must be provided and have proper values.
| ATSTypeError: The gen_mmap bundle options must be an instance of Mapping and its
| attributes must be instances of their respective types.
| ATSValueError: The gen_mmap bundle dependencies must be provided and have proper values.
| ATSTypeError: The gen_mmap bundle dependencies must be an instance of Mapping and its
| attributes must be instances of their respective types.
| ATSValueError: The gen_mmap bundle must be provided and have proper values.
| ATSTypeError: The gen_mmap bundle must be an instance of GenMmapBundle and
| its attributes must be instances of their respective types.
'''
if options is not None:
GenMmapBundleOptionsValidator.validate(options)
info_file = options.get(GenMmapBundleKeys.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_mmap_definition: GenMmapCommandDefinition = GenMmapCommandDefinition()
gen_mmap_bundle: CommandBundle = CommandBundle(
definition=gen_mmap_definition,
executor=GenMmapCommandExecutor(gen_mmap_definition)
)
cli_bundle: CLIBundle = CLIBundleRegistry.create_bundle(
dependencies=CLIBundleDependencies(
service=service,
parser=base_bundle.option_manager,
commands=[gen_mmap_bundle]
)
)
cli: CLI = CLI(cli_bundle)
return GenMmapBundleRegistry.create_bundle(
dependencies=GenMmapBundleDependencies(
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__