@@ -39,15 +39,15 @@ class NoSuchFile(Exception):
39
39
# Helpers
40
40
#
41
41
42
- def find_latest_ansible_dir (build_data_working ):
42
+ def find_latest_ansible_dir (build_data_working ) -> tuple [ str , "packaging.version.Version" ] :
43
43
"""Find the most recent ansible major version."""
44
44
# imports here so that they don't cause unnecessary deps for all of the plugins
45
45
from packaging .version import InvalidVersion , Version
46
46
47
47
ansible_directories = glob .glob (os .path .join (build_data_working , '[0-9.]*' ))
48
48
49
49
# Find the latest ansible version directory
50
- latest = None
50
+ latest_dir = None
51
51
latest_ver = Version ('0' )
52
52
for directory_name in (d for d in ansible_directories if os .path .isdir (d )):
53
53
try :
@@ -61,12 +61,12 @@ def find_latest_ansible_dir(build_data_working):
61
61
62
62
if new_version > latest_ver :
63
63
latest_ver = new_version
64
- latest = directory_name
64
+ latest_dir = directory_name
65
65
66
- if latest is None :
66
+ if latest_dir is None :
67
67
raise NoSuchFile ('Could not find an ansible data directory in {0}' .format (build_data_working ))
68
68
69
- return latest
69
+ return latest_dir , latest_ver
70
70
71
71
72
72
def parse_deps_file (filename ):
@@ -84,7 +84,7 @@ def write_deps_file(filename, deps_data):
84
84
f .write (f'{ key } : { value } \n ' )
85
85
86
86
87
- def find_latest_deps_file (build_data_working , ansible_version ) :
87
+ def find_latest_deps_file (build_data_working , ansible_version : str ) -> tuple [ str , "packaging.version.Version" ] :
88
88
"""Find the most recent ansible deps file for the given ansible major version."""
89
89
# imports here so that they don't cause unnecessary deps for all of the plugins
90
90
from packaging .version import Version
@@ -95,19 +95,19 @@ def find_latest_deps_file(build_data_working, ansible_version):
95
95
raise Exception ('No deps files exist for version {0}' .format (ansible_version ))
96
96
97
97
# Find the latest version of the deps file for this major version
98
- latest = None
98
+ latest_deps_file = None
99
99
latest_ver = Version ('0' )
100
100
for filename in deps_files :
101
101
deps_data = parse_deps_file (filename )
102
102
new_version = Version (deps_data ['_ansible_version' ])
103
103
if new_version > latest_ver :
104
104
latest_ver = new_version
105
- latest = filename
105
+ latest_deps_file = filename
106
106
107
- if latest is None :
107
+ if latest_deps_file is None :
108
108
raise NoSuchFile ('Could not find an ansible deps file in {0}' .format (data_dir ))
109
109
110
- return latest
110
+ return latest_deps_file , latest_ver
111
111
112
112
113
113
#
@@ -133,9 +133,18 @@ def generate_core_docs(args):
133
133
f .write (yaml .dump (deps_file_contents ))
134
134
135
135
# Generate the plugin rst
136
- return antsibull_docs .run (['antsibull-docs' , 'stable' , '--deps-file' , modified_deps_file ,
137
- '--ansible-core-source' , str (args .top_dir ),
138
- '--dest-dir' , args .output_dir ])
136
+ full_command = [
137
+ 'antsibull-docs' ,
138
+ 'stable' ,
139
+ '--deps-file' ,
140
+ modified_deps_file ,
141
+ '--ansible-core-source' ,
142
+ str (args .top_dir ),
143
+ '--dest-dir' ,
144
+ args .output_dir ,
145
+ ]
146
+ print (f"Running { full_command !r} :" )
147
+ return antsibull_docs .run (full_command )
139
148
140
149
# If we make this more than just a driver for antsibull:
141
150
# Run other rst generation
@@ -164,16 +173,21 @@ def generate_full_docs(args):
164
173
if args .ansible_build_data :
165
174
build_data_working = args .ansible_build_data
166
175
167
- ansible_version = args .ansible_version
176
+ ansible_version : str = args .ansible_version
168
177
if ansible_version is None :
169
- ansible_version = find_latest_ansible_dir (build_data_working )
170
- params = ['devel' , '--pieces-file' , os .path .join (ansible_version , 'ansible.in' )]
178
+ devel_dir , devel_version = find_latest_ansible_dir (build_data_working )
179
+ params = ['devel' , '--pieces-file' , 'ansible.in' , '--major-version' , str (devel_version .major )]
180
+ cwd = str (devel_dir )
171
181
else :
172
- latest_filename = find_latest_deps_file (build_data_working , ansible_version )
182
+ latest_deps_file , ansible_version_ver = find_latest_deps_file (build_data_working , ansible_version )
183
+ deps_dir = os .path .dirname (latest_deps_file )
173
184
174
185
# Make a copy of the deps file so that we can set the ansible-core version we'll use
175
186
modified_deps_file = os .path .join (tmp_dir , 'ansible.deps' )
176
- shutil .copyfile (latest_filename , modified_deps_file )
187
+ shutil .copyfile (latest_deps_file , modified_deps_file )
188
+
189
+ # Make a copy of collection-meta.yaml
190
+ shutil .copyfile (os .path .join (deps_dir , 'collection-meta.yaml' ), os .path .join (tmp_dir , 'collection-meta.yaml' ))
177
191
178
192
# Put our version of ansible-core into the deps file
179
193
deps_data = parse_deps_file (modified_deps_file )
@@ -182,12 +196,23 @@ def generate_full_docs(args):
182
196
183
197
write_deps_file (modified_deps_file , deps_data )
184
198
185
- params = ['stable' , '--deps-file' , modified_deps_file ]
199
+ params = ['stable' , '--deps-file' , 'ansible.deps' , '--version' , str (ansible_version_ver )]
200
+ cwd = str (tmp_dir )
186
201
187
- # Generate the plugin rst
188
- return antsibull_docs .run (['antsibull-docs' ] + params +
189
- ['--ansible-core-source' , str (args .top_dir ),
190
- '--dest-dir' , args .output_dir ])
202
+ old_cwd = os .getcwd ()
203
+ try :
204
+ os .chdir (cwd )
205
+ # Generate the plugin rst
206
+ full_command = ['antsibull-docs' ] + params + [
207
+ '--ansible-core-source' ,
208
+ os .path .join (old_cwd , str (args .top_dir )),
209
+ '--dest-dir' ,
210
+ os .path .join (old_cwd , args .output_dir ),
211
+ ]
212
+ print (f"Running { full_command !r} in { cwd !r} :" )
213
+ return antsibull_docs .run (full_command )
214
+ finally :
215
+ os .chdir (old_cwd )
191
216
192
217
# If we make this more than just a driver for antsibull:
193
218
# Run other rst generation
@@ -199,7 +224,6 @@ class CollectionPluginDocs(Command):
199
224
_ACTION_HELP = """Action to perform.
200
225
full: Regenerate the rst for the full ansible website.
201
226
core: Regenerate the rst for plugins in ansible-core and then build the website.
202
- named: Regenerate the rst for the named plugins and then build the website.
203
227
"""
204
228
205
229
@classmethod
@@ -212,7 +236,7 @@ def init_parser(cls, add_parser):
212
236
' hierarchy.' )
213
237
# I think we should make the actions a subparser but need to look in git history and see if
214
238
# we tried that and changed it for some reason.
215
- parser .add_argument ('action' , action = 'store' , choices = ('full' , 'core' , 'named' ),
239
+ parser .add_argument ('action' , action = 'store' , choices = ('full' , 'core' ),
216
240
default = 'full' , help = cls ._ACTION_HELP )
217
241
parser .add_argument ("-o" , "--output-dir" , action = "store" , dest = "output_dir" ,
218
242
default = DEFAULT_OUTPUT_DIR ,
@@ -249,7 +273,7 @@ def main(args):
249
273
250
274
if args .action == 'core' :
251
275
return generate_core_docs (args )
252
- # args.action == 'named' (Invalid actions are caught by argparse)
253
- raise NotImplementedError ('Building docs for specific files is not yet implemented ' )
276
+
277
+ raise NotImplementedError ('New actions have to be explicitly supported by the code ' )
254
278
255
279
# return 0
0 commit comments