Skip to content

Runners

Results

Represents the results of running modules.

Source code in aoc/runners.py
16
17
18
19
20
21
22
23
24
25
@final
@frozen()
class Results:
    """Represents the results of running modules."""

    results: Dict[Key, AnyResult]
    """The results of running [`Solution`][aoc.solutions.Solution] instances."""

    final_results: Dict[Key, AnyFinalResult]
    """The results of running [`FinalSolution`][aoc.solutions.FinalSolution] instances."""

results: Dict[Key, AnyResult] instance-attribute

The results of running Solution instances.

final_results: Dict[Key, AnyFinalResult] instance-attribute

The results of running FinalSolution instances.

Runner

Represents runners for python paths containing modules.

Source code in aoc/runners.py
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
@frozen()
class Runner:
    """Represents runners for python paths containing modules."""

    def run_path(self, path: Path, data_path: Path = DATA_PATH) -> Results:
        """Runs the module from the `path` and returns the results.

        Arguments:
            path: The path to the module.
            data_path: The path to the data directory.

        Returns:
            The results of running the module.

        Raises:
            AnyError: Any error that occurs while running.
        """
        namespace = run_python_path(str(path))

        solutions = SOLUTIONS
        final_solutions = FINAL_SOLUTIONS

        results = {}
        final_results = {}

        for name in namespace:
            try:
                key = get_key_by_name(name)

            except TypeError:
                pass

            else:
                if key in solutions:
                    solution = solutions[key]()

                    data = load_data(key, data_path)

                    results[key] = solution.execute(data)

                if key in final_solutions:
                    final_solution = final_solutions[key]()

                    data = load_data(key, data_path)

                    final_results[key] = final_solution.execute(data)

        return Results(results, final_results)

run_path(path: Path, data_path: Path = DATA_PATH) -> Results

Runs the module from the path and returns the results.

Parameters:

Name Type Description Default
path Path

The path to the module.

required
data_path Path

The path to the data directory.

DATA_PATH

Returns:

Type Description
Results

The results of running the module.

Raises:

Type Description
AnyError

Any error that occurs while running.

Source code in aoc/runners.py
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
def run_path(self, path: Path, data_path: Path = DATA_PATH) -> Results:
    """Runs the module from the `path` and returns the results.

    Arguments:
        path: The path to the module.
        data_path: The path to the data directory.

    Returns:
        The results of running the module.

    Raises:
        AnyError: Any error that occurs while running.
    """
    namespace = run_python_path(str(path))

    solutions = SOLUTIONS
    final_solutions = FINAL_SOLUTIONS

    results = {}
    final_results = {}

    for name in namespace:
        try:
            key = get_key_by_name(name)

        except TypeError:
            pass

        else:
            if key in solutions:
                solution = solutions[key]()

                data = load_data(key, data_path)

                results[key] = solution.execute(data)

            if key in final_solutions:
                final_solution = final_solutions[key]()

                data = load_data(key, data_path)

                final_results[key] = final_solution.execute(data)

    return Results(results, final_results)

run_path(path: Path, data_path: Path = DATA_PATH, runner_type: Type[Runner] = Runner) -> Results

Runs the module with the given name and returns the results.

This is equivalent to:

runner_type().run_path(path, data_path)

Parameters:

Name Type Description Default
path Path

The path to the module.

required
data_path Path

The path to the data directory.

DATA_PATH
runner_type Type[Runner]

The runner type to use.

Runner

Returns:

Type Description
Results

The results of running the module.

Raises:

Type Description
AnyError

Any error that occurs while running.

Source code in aoc/runners.py
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
def run_path(
    path: Path, data_path: Path = DATA_PATH, runner_type: Type[Runner] = Runner
) -> Results:
    """Runs the module with the given `name` and returns the results.

    This is equivalent to:

    ```python
    runner_type().run_path(path, data_path)
    ```

    Arguments:
        path: The path to the module.
        data_path: The path to the data directory.
        runner_type: The runner type to use.

    Returns:
        The results of running the module.

    Raises:
        AnyError: Any error that occurs while running.
    """
    return runner_type().run_path(path, data_path)