Skip to content

Commit b09a200

Browse files
committed
clone-core: update clone core script to remove old files
See the linked issue. The lingering setup.py and setup.cfg files from older versions of ansible-core were breaking a local user's doc build. The clone-core script should automatically remove these. Relates: ansible/ansible#83937
1 parent de21da1 commit b09a200

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

docs/bin/clone-core.py

+31
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,30 @@
1818
DEFAULT_BRANCH = (ROOT / "docs" / "ansible-core-branch.txt").read_text().strip()
1919
DEFAULT_ANSIBLE_CORE_REPO = "https://github.com/ansible/ansible"
2020

21+
"""Directories to copy from ansible-core into the ansible-documentation tree"""
2122
KEEP_DIRS = (
2223
"bin",
2324
"lib",
2425
"packaging",
2526
"test/lib",
2627
)
2728

29+
"""Files to copy from ansible-core into the ansible-documentation tree"""
2830
KEEP_FILES = (
2931
"MANIFEST.in",
3032
"pyproject.toml",
3133
"requirements.txt",
3234
)
3335

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+
3445

3546
@dataclasses.dataclass()
3647
class Args:
@@ -71,11 +82,31 @@ def parse_args(args: list[str] | None = None) -> Args:
7182
return Args(**vars(parser.parse_args(args)))
7283

7384

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+
7496
def main(args: Args) -> None:
97+
# Start by removing extra files
98+
removed_files = remove_files()
99+
75100
if (
101+
# Check is enabled
76102
args.check
103+
# All core files exist
77104
and all(pathlib.Path(file).is_file() for file in KEEP_FILES)
105+
# All core directories exist
78106
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
79110
):
80111
print("The necessary core files already exist.")
81112
print("Run 'nox -e clone-core' without --check to update the core files.")

0 commit comments

Comments
 (0)