1818DEFAULT_BRANCH = (ROOT / "docs" / "ansible-core-branch.txt" ).read_text ().strip ()
1919DEFAULT_ANSIBLE_CORE_REPO = "https://github.com/ansible/ansible"
2020
21+ KEEP_DIRS = (
22+ "bin" ,
23+ "lib" ,
24+ "packaging" ,
25+ "test/lib" ,
26+ )
27+
28+ KEEP_FILES = (
29+ "MANIFEST.in" ,
30+ "pyproject.toml" ,
31+ "requirements.txt" ,
32+ "setup.cfg" ,
33+ "setup.py" ,
34+ )
35+
2136
2237@dataclasses .dataclass ()
2338class Args :
2439 branch : str | None
2540 repo : str
41+ check : bool
2642
2743
2844def parse_args (args : list [str ] | None = None ) -> Args :
@@ -47,24 +63,25 @@ def parse_args(args: list[str] | None = None) -> Args:
4763 help = "ansible-core repository to check out. Default: %(default)s" ,
4864 default = DEFAULT_ANSIBLE_CORE_REPO ,
4965 )
66+ parser .add_argument (
67+ "--check" ,
68+ action = argparse .BooleanOptionalAction ,
69+ help = "Ensure that the necessary files exist."
70+ " If they don't clone new ones from ansible-core."
71+ " Otherwise, leave the existing versions alone." ,
72+ )
5073 return Args (** vars (parser .parse_args (args )))
5174
5275
5376def main (args : Args ) -> None :
54- keep_dirs = [
55- "bin" ,
56- "lib" ,
57- "packaging" ,
58- "test/lib" ,
59- ]
60-
61- keep_files = [
62- "MANIFEST.in" ,
63- "pyproject.toml" ,
64- "requirements.txt" ,
65- "setup.cfg" ,
66- "setup.py" ,
67- ]
77+ if (
78+ args .check
79+ and all (pathlib .Path (file ).is_file () for file in KEEP_FILES )
80+ and all (pathlib .Path (directory ).is_dir () for directory in KEEP_DIRS )
81+ ):
82+ print ("The necessary core files already exist." )
83+ print ("Run 'nox -e clone-core' without --check to update the core files." )
84+ return
6885
6986 with tempfile .TemporaryDirectory () as temp_dir :
7087 cmd : list [str ] = ["git" , "clone" , args .repo , "--depth=1" ]
@@ -73,7 +90,7 @@ def main(args: Args) -> None:
7390 cmd .append (temp_dir )
7491 subprocess .run (cmd , check = True )
7592
76- for keep_dir in keep_dirs :
93+ for keep_dir in KEEP_DIRS :
7794 src = pathlib .Path (temp_dir , keep_dir )
7895 dst = pathlib .Path .cwd () / keep_dir
7996
@@ -86,7 +103,7 @@ def main(args: Args) -> None:
86103
87104 (dst / ".gitignore" ).write_text ("*" )
88105
89- for keep_file in keep_files :
106+ for keep_file in KEEP_FILES :
90107 src = pathlib .Path (temp_dir , keep_file )
91108 dst = pathlib .Path .cwd () / keep_file
92109
0 commit comments