|
2 | 2 | A script to check that all strategy modules have been included in
|
3 | 3 | `./docs/reference/all_strategies.rst`
|
4 | 4 | """
|
5 |
| -import glob |
6 | 5 | import sys
|
7 |
| -import os |
| 6 | +import pathlib |
8 | 7 |
|
9 |
| -def read_index(index_path: str) -> str: |
10 |
| - """ |
11 |
| - Read the index of strategies |
12 |
| -
|
13 |
| - Parameters |
14 |
| - ---------- |
15 |
| - index_path : str |
16 |
| - A file path for the index file where all strategies are auto documented |
17 |
| -
|
18 |
| - Returns |
19 |
| - ------- |
20 |
| - strategies_reference : str |
21 |
| - The string value of the contents of the index file. |
22 |
| - """ |
23 |
| - with open(index_path, "r") as f: |
24 |
| - strategies_reference = f.read() |
25 |
| - return strategies_reference |
26 |
| - |
27 |
| -def get_module_name(module_path: str) -> str: |
28 |
| - """ |
29 |
| - Take string of the form `./axelrod/strategies/titfortat.py` and returns |
30 |
| - `titfortat`. |
31 |
| -
|
32 |
| - Parameters |
33 |
| - ---------- |
34 |
| - module_path : str |
35 |
| - A file path for a module file. |
36 |
| -
|
37 |
| - Returns |
38 |
| - ------- |
39 |
| - module_name : str |
40 |
| - The name of the module |
41 |
| - """ |
42 |
| - filename = os.path.basename(module_path) |
43 |
| - module_name = os.path.splitext(filename)[0] |
44 |
| - return module_name |
| 8 | +default_index_path = pathlib.Path("./docs/reference/all_strategies.rst") |
| 9 | +excluded_modules = ("_strategies", "__init__", "_filters", "human") |
45 | 10 |
|
46 |
| -def check_module(module_path: str, |
47 |
| - index_path: str="./docs/reference/all_strategies.rst", |
48 |
| - excluded: tuple=("_strategies", "__init__", |
49 |
| - "_filters", "human")) -> bool: |
| 11 | +def check_module(module_path: pathlib.Path, |
| 12 | + index_path: pathlib.Path=default_index_path, |
| 13 | + excluded: tuple=excluded_modules) -> bool: |
50 | 14 | """
|
51 | 15 | Check if a module name is written in the index of strategies.
|
52 | 16 |
|
53 | 17 | Parameters
|
54 | 18 | ----------
|
55 |
| - module_path : str |
| 19 | + module_path : |
56 | 20 | A file path for a module file.
|
57 |
| - index_path : str |
| 21 | + index_path : |
58 | 22 | A file path for the index file where all strategies are auto documented
|
59 |
| - excluded : tuple |
| 23 | + excluded : |
60 | 24 | A collection of module names to be ignored
|
61 | 25 |
|
62 | 26 | Returns
|
63 | 27 | -------
|
64 |
| - boolean : bool |
| 28 | + boolean : |
65 | 29 | True/False if module is referenced.
|
66 | 30 |
|
67 | 31 | """
|
68 |
| - strategies_index = read_index(index_path) |
69 |
| - module_name = get_module_name(module_path) |
| 32 | + strategies_index = index_path.read_text() |
| 33 | + module_name = module_path.stem |
70 | 34 | if module_name not in excluded and module_name not in strategies_index:
|
71 |
| - print("{} not in index".format(module_name)) |
72 |
| - return False |
| 35 | + print("{} not in index".format(module_name)) |
| 36 | + return False |
73 | 37 | return True
|
74 | 38 |
|
75 | 39 |
|
76 | 40 | if __name__ == "__main__":
|
77 | 41 |
|
78 |
| - modules = glob.glob("./axelrod/strategies/*.py") |
| 42 | + p = pathlib.Path('.') |
| 43 | + modules = p.glob("./axelrod/strategies/*.py") |
79 | 44 | exit_codes = []
|
80 | 45 |
|
81 | 46 | for module_path in modules:
|
|
0 commit comments