|
18 | 18 | DEFAULT_BRANCH = (ROOT / "docs" / "ansible-core-branch.txt").read_text().strip()
|
19 | 19 | DEFAULT_ANSIBLE_CORE_REPO = "https://github.com/ansible/ansible"
|
20 | 20 |
|
| 21 | +"""Directories to copy from ansible-core into the ansible-documentation tree""" |
21 | 22 | KEEP_DIRS = (
|
22 | 23 | "bin",
|
23 | 24 | "lib",
|
24 | 25 | "packaging",
|
25 | 26 | "test/lib",
|
26 | 27 | )
|
27 | 28 |
|
| 29 | +"""Files to copy from ansible-core into the ansible-documentation tree""" |
28 | 30 | KEEP_FILES = (
|
29 | 31 | "MANIFEST.in",
|
30 | 32 | "pyproject.toml",
|
31 | 33 | "requirements.txt",
|
32 | 34 | )
|
33 | 35 |
|
| 36 | +"""Files to remove after cloning ansible-core""" |
| 37 | +REMOVE_FILES = ( |
| 38 | + # See https://github.com/ansible/ansible/commit/68515abf97dfc769c9aed2ba457ed7b8b2580a5c |
| 39 | + # ansible-core removed setup.py and setup.cfg so we need to make sure to |
| 40 | + # remove those when syncing the new version. |
| 41 | + "setup.py", |
| 42 | + "setup.cfg", |
| 43 | +) |
| 44 | + |
34 | 45 |
|
35 | 46 | @dataclasses.dataclass()
|
36 | 47 | class Args:
|
@@ -71,11 +82,31 @@ def parse_args(args: list[str] | None = None) -> Args:
|
71 | 82 | return Args(**vars(parser.parse_args(args)))
|
72 | 83 |
|
73 | 84 |
|
| 85 | +def remove_files(directory: pathlib.Path = pathlib.Path.cwd()) -> list[pathlib.Path]: |
| 86 | + removed: list[pathlib.Path] = [] |
| 87 | + for file in REMOVE_FILES: |
| 88 | + path = directory / file |
| 89 | + if path.is_file(): |
| 90 | + print(f"Removing {file!r} ...") |
| 91 | + path.unlink() |
| 92 | + removed.append(path) |
| 93 | + return removed |
| 94 | + |
| 95 | + |
74 | 96 | def main(args: Args) -> None:
|
| 97 | + # Start by removing extra files |
| 98 | + removed_files = remove_files() |
| 99 | + |
75 | 100 | if (
|
| 101 | + # Check is enabled |
76 | 102 | args.check
|
| 103 | + # All core files exist |
77 | 104 | and all(pathlib.Path(file).is_file() for file in KEEP_FILES)
|
| 105 | + # All core directories exist |
78 | 106 | and all(pathlib.Path(directory).is_dir() for directory in KEEP_DIRS)
|
| 107 | + # If any extra files are still around, that means our checkout is out |
| 108 | + # of date and needs to be refreshed. |
| 109 | + and not removed_files |
79 | 110 | ):
|
80 | 111 | print("The necessary core files already exist.")
|
81 | 112 | print("Run 'nox -e clone-core' without --check to update the core files.")
|
|
0 commit comments