Coverage for sources/mimeogram/__/preparation.py: 100%
27 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-02-16 01:42 +0000
« prev ^ index » next coverage.py v7.6.12, created at 2025-02-16 01:42 +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 state as _state
34async def prepare( # pylint: disable=too-many-arguments,too-many-locals
35 exits: __.ExitsAsync,
36 application: _application.Information = _application.Information( ),
37 configedits: _dictedits.Edits = ( ),
38 configfile: __.Absential[ __.Path ] = __.absent,
39 environment: bool = False,
40 inscription: __.Absential[ _inscription.Control ] = __.absent,
41) -> _state.Globals:
42 ''' Prepares globals DTO for use with library functions.
44 Also:
45 * Configures logging for library package (not application).
46 * Optionally, loads process environment from files.
48 Note that asynchronous preparation allows for applications to
49 concurrently initialize other entities outside of the library, even
50 though the library initialization, itself, is inherently sequential.
51 '''
52 directories = application.produce_platform_directories( )
53 distribution = (
54 await _distribution.Information.prepare(
55 package = __.package_name, exits = exits ) )
56 configuration = (
57 await _configuration.acquire(
58 application_name = application.name,
59 directories = directories,
60 distribution = distribution,
61 edits = configedits,
62 file = configfile ) )
63 auxdata = _state.Globals(
64 application = application,
65 configuration = configuration,
66 directories = directories,
67 distribution = distribution,
68 exits = exits )
69 if environment: await _environment.update( auxdata )
70 if __.is_absent( inscription ):
71 inscription_: _inscription.Control = _inscription.Control( )
72 else: inscription_ = inscription
73 _inscription.prepare( control = inscription_ )
74 _inscribe_preparation_report( auxdata )
75 return auxdata
78def _inscribe_preparation_report( auxdata: _state.Globals ):
79 scribe = __.produce_scribe( __.package_name )
80 scribe.debug( f"Application Name: {auxdata.application.name}" )
81 # scribe.debug( f"Execution ID: {auxdata.application.execution_id}" )
82 scribe.debug( "Application Cache Location: {}".format(
83 auxdata.provide_cache_location( ) ) )
84 scribe.debug( "Application Data Location: {}".format(
85 auxdata.provide_data_location( ) ) )
86 scribe.debug( "Application State Location: {}".format(
87 auxdata.provide_state_location( ) ) )
88 scribe.debug( "Package Data Location: {}".format(
89 auxdata.distribution.provide_data_location( ) ) )