Skip to content

pre_main

pre_main(request)

Do preparatory steps before the Generation process.

Makes Request Futures and modifies the Template Context.

Source code in src/cookiecutter_python/backend/pre_main.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
def pre_main(request):
    """Do preparatory steps before the Generation process.

    Makes Request Futures and modifies the Template Context.
    """
    ## External Services Clients Initialization ##
    # clients "how to question" 3rd party web services like pypi, and rtd
    # making http request to web servers hosting endpoints for APIs

    # Checkers are initialized as 'Activated'

    # Activate Async HTTP only if all below are True:
    # - User did not pass the --offline CLI flag
    # - User did not pass the --default-config CLI flag
    # - User passed a Config file YAML

    # Activate: if User Config is given and Default Config is False
    deactivate_signal: bool = bool(request.default_config)
    if request.offline:
        deactivate_signal = True

    request.check = Engine.create(request.config_file, deactivate_signal)

    # Start Requesting Futures! - Hosting Service: PyPI, Read The Docs
    request.check_results = request.check.check(request.web_servers)
    """
    If skipped due to missing info in User Config, we can expect Logs roughly as:
    logger.info(
        "Skipping check of remote server, because of missing context variable"
    )
    logger.info(error)
    """
    _context = request.extra_context or {}
    interactive_mode = not bool(request.no_input)

    # If INTERACTIVE, Run Dialog Pipeline, to update Context
    if interactive_mode:
        # Render Context to be used in Dialogs
        user_input = parse_context(request.config_file)
        _context.update(
            {
                'interpreters': {
                    'supported-interpreters': user_input.pop('supported-interpreters')
                },  # 'supported-interpreters
                # 'supported-interpreters': user_input.pop('supported-interpreters'),
                **user_input,
            }
        )
    elif request.config_file and bool(
        interpreters := get_interpreters_from_yaml(request.config_file)
    ):
        # just update interpreters cookiecutter extra_context
        _context['interpreters'] = interpreters

    request.extra_context = dict(_context)
    return request