Skip to content

check_engine

Engine

Source code in src/cookiecutter_python/backend/hosting_services/check_engine.py
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
@attr.s(auto_attribs=True, slots=True, frozen=True)
class Engine:
    config_file: Union[None, str]
    default_config: Union[None, bool]
    services_info: Tuple

    checker: Checker = attr.ib(
        default=attr.Factory(
            lambda self: Checker.from_hosting_info(
                self.config_file, self.default_config, self.services_info
            ),
            takes_self=True,
        )
    )

    handlers: Handlers = attr.ib(
        default=attr.Factory(
            lambda self: Handlers.from_checkers(self.checker), takes_self=True
        )
    )

    def __getattr__(self, name):
        return getattr(self.checker, name)

    def handle(self, request_result):
        return self.handlers(request_result)

    def check(self, servers: List[str]) -> Iterator:
        """Request Future per supported server, for web hosting service checks

        For each server the dedicated 'checker' is called, which tries to
        return a Future.

        Returns None checker's 'activation' boolean flag was off at runtime.
        Returns None if internal mechanism for determining server URL fails to
        derive the URL (atm URL is only trie d to be read from User Config yaml)

        Args:
            servers (List[str]): [description]

        Returns:
            Iterator: of custom objects with 'future' evaluatable attribute
        """
        return iter(filter(None, [getattr(self, server)() for server in servers]))

    @staticmethod
    def create(config_file: str, default_config: bool):
        """Initialize objects, for Asynchronous http with 3rd-party Services

        Objects are designed to Ask PyPI and Read The Docs, if the soon to be
        generated package name, and readthedocs project slug are available.

        These 'Checker' objects make asynchronous http requests to PyPI and RTD
        web servers, for non-blocking IO, and to avoid blocking the main thread.

        Checkers are initialized as 'Activated' if User Config is given and
        Default Config is False.

        Then each Checker (pypi, rtd) requires:
        - PyPI requires the 'pkg_name' in User's yaml Config
        - RTD requires the 'readthedocs_project_slug' in User's yaml Config

        to derive the URLs for Future Requests

        Args:
            config_file (str): user's yaml config file
            default_config (bool): default config flag
        """
        return Engine(
            config_file,
            default_config,
            # load implementations and automatically instatiate all
            tuple((HostingServices.create(x) for x in ('pypi', 'readthedocs'))),
        )

check(servers)

Request Future per supported server, for web hosting service checks

For each server the dedicated 'checker' is called, which tries to return a Future.

Returns None checker's 'activation' boolean flag was off at runtime. Returns None if internal mechanism for determining server URL fails to derive the URL (atm URL is only trie d to be read from User Config yaml)

Parameters:

Name Type Description Default
servers List[str]

[description]

required

Returns:

Name Type Description
Iterator Iterator

of custom objects with 'future' evaluatable attribute

Source code in src/cookiecutter_python/backend/hosting_services/check_engine.py
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
def check(self, servers: List[str]) -> Iterator:
    """Request Future per supported server, for web hosting service checks

    For each server the dedicated 'checker' is called, which tries to
    return a Future.

    Returns None checker's 'activation' boolean flag was off at runtime.
    Returns None if internal mechanism for determining server URL fails to
    derive the URL (atm URL is only trie d to be read from User Config yaml)

    Args:
        servers (List[str]): [description]

    Returns:
        Iterator: of custom objects with 'future' evaluatable attribute
    """
    return iter(filter(None, [getattr(self, server)() for server in servers]))

create(config_file, default_config) staticmethod

Initialize objects, for Asynchronous http with 3rd-party Services

Objects are designed to Ask PyPI and Read The Docs, if the soon to be generated package name, and readthedocs project slug are available.

These 'Checker' objects make asynchronous http requests to PyPI and RTD web servers, for non-blocking IO, and to avoid blocking the main thread.

Checkers are initialized as 'Activated' if User Config is given and Default Config is False.

Then each Checker (pypi, rtd) requires: - PyPI requires the 'pkg_name' in User's yaml Config - RTD requires the 'readthedocs_project_slug' in User's yaml Config

to derive the URLs for Future Requests

Parameters:

Name Type Description Default
config_file str

user's yaml config file

required
default_config bool

default config flag

required
Source code in src/cookiecutter_python/backend/hosting_services/check_engine.py
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
@staticmethod
def create(config_file: str, default_config: bool):
    """Initialize objects, for Asynchronous http with 3rd-party Services

    Objects are designed to Ask PyPI and Read The Docs, if the soon to be
    generated package name, and readthedocs project slug are available.

    These 'Checker' objects make asynchronous http requests to PyPI and RTD
    web servers, for non-blocking IO, and to avoid blocking the main thread.

    Checkers are initialized as 'Activated' if User Config is given and
    Default Config is False.

    Then each Checker (pypi, rtd) requires:
    - PyPI requires the 'pkg_name' in User's yaml Config
    - RTD requires the 'readthedocs_project_slug' in User's yaml Config

    to derive the URLs for Future Requests

    Args:
        config_file (str): user's yaml config file
        default_config (bool): default config flag
    """
    return Engine(
        config_file,
        default_config,
        # load implementations and automatically instatiate all
        tuple((HostingServices.create(x) for x in ('pypi', 'readthedocs'))),
    )