Coverage for sources/mimeogram/__/preparation.py: 100%
29 statements
« prev ^ index » next coverage.py v7.8.2, created at 2025-06-07 04:07 +0000
« prev ^ index » next coverage.py v7.8.2, created at 2025-06-07 04:07 +0000
1# vim: set filetype=python fileencoding=utf-8:
2# -*- coding: utf-8 -*-
4#============================================================================#
5# #
6# Licensed under the Apache License, Version 2.0 (the "License"); #
7# you may not use this file except in compliance with the License. #
8# You may obtain a copy of the License at #
9# #
10# http://www.apache.org/licenses/LICENSE-2.0 #
11# #
12# Unless required by applicable law or agreed to in writing, software #
13# distributed under the License is distributed on an "AS IS" BASIS, #
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
15# See the License for the specific language governing permissions and #
16# limitations under the License. #
17# #
18#============================================================================#
21''' Preparation of the library core. '''
24from . import imports as __
25from . import application as _application
26from . import configuration as _configuration
27from . import dictedits as _dictedits
28from . import distribution as _distribution
29from . import environment as _environment
30from . import inscription as _inscription
31from . import nomina as _nomina
32from . import state as _state
35_application_information = _application.Information( )
37async def prepare( # noqa: PLR0913
38 exits: __.ExitsAsync,
39 application: _application.Information = _application_information,
40 configedits: _dictedits.Edits = ( ),
41 configfile: __.Absential[ __.Path ] = __.absent,
42 environment: bool = False,
43 inscription: __.Absential[ _inscription.Control ] = __.absent,
44) -> _state.Globals:
45 ''' Prepares globals DTO for use with library functions.
47 Also:
48 * Configures logging for library package (not application).
49 * Optionally, loads process environment from files.
51 Note that asynchronous preparation allows for applications to
52 concurrently initialize other entities outside of the library, even
53 though the library initialization, itself, is inherently sequential.
54 '''
55 directories = application.produce_platform_directories( )
56 distribution = (
57 await _distribution.Information.prepare(
58 package = _nomina.package_name, exits = exits ) )
59 configuration = (
60 await _configuration.acquire(
61 application_name = application.name,
62 directories = directories,
63 distribution = distribution,
64 edits = configedits,
65 file = configfile ) )
66 auxdata = _state.Globals(
67 application = application,
68 configuration = configuration,
69 directories = directories,
70 distribution = distribution,
71 exits = exits )
72 if environment: await _environment.update( auxdata )
73 if __.is_absent( inscription ):
74 inscription_: _inscription.Control = _inscription.Control( )
75 else: inscription_ = inscription
76 _inscription.prepare( control = inscription_ )
77 _inscribe_preparation_report( auxdata )
78 return auxdata
81def _inscribe_preparation_report( auxdata: _state.Globals ):
82 scribe = __.produce_scribe( _nomina.package_name )
83 scribe.debug( f"Application Name: {auxdata.application.name}" )
84 # scribe.debug( f"Execution ID: {auxdata.application.execution_id}" )
85 scribe.debug( "Application Cache Location: {}".format(
86 auxdata.provide_cache_location( ) ) )
87 scribe.debug( "Application Data Location: {}".format(
88 auxdata.provide_data_location( ) ) )
89 scribe.debug( "Application State Location: {}".format(
90 auxdata.provide_state_location( ) ) )
91 scribe.debug( "Package Data Location: {}".format(
92 auxdata.distribution.provide_data_location( ) ) )