diff options
author | Felix Fontein <felix@fontein.de> | 2022-10-27 20:07:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-27 13:07:27 -0500 |
commit | 5c8928fa44286e159a0ad7e4707d5944cd5edb7f (patch) | |
tree | 293fb13820a622c34eed17f0fd9705ca49ffa69d | |
parent | b6a24d00311fa03dc80335d9c15f817014fdb0d0 (diff) | |
download | ansible-5c8928fa44286e159a0ad7e4707d5944cd5edb7f.tar.gz |
stable docs build: do not use YAML parsing/serialization for .deps files (#79233) (#79237)
* Do not use YAML parsing/serialization for .deps files.
* Prevent crash.
(cherry picked from commit 9545f2e0deae73d142047f02b499940b07b700aa)
-rw-r--r-- | hacking/build_library/build_ansible/command_plugins/docs_build.py | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/hacking/build_library/build_ansible/command_plugins/docs_build.py b/hacking/build_library/build_ansible/command_plugins/docs_build.py index 1b1351ca8c..62c4b1be7f 100644 --- a/hacking/build_library/build_ansible/command_plugins/docs_build.py +++ b/hacking/build_library/build_ansible/command_plugins/docs_build.py @@ -68,6 +68,21 @@ def find_latest_ansible_dir(build_data_working): return latest +def parse_deps_file(filename): + """Parse an antsibull .deps file.""" + with open(filename, 'r', encoding='utf-8') as f: + contents = f.read() + lines = [c for line in contents.splitlines() if (c := line.strip()) and not c.startswith('#')] + return dict([entry.strip() for entry in line.split(':', 1)] for line in lines) + + +def write_deps_file(filename, deps_data): + """Write an antsibull .deps file.""" + with open(filename, 'w', encoding='utf-8') as f: + for key, value in deps_data.items(): + f.write(f'{key}: {value}\n') + + def find_latest_deps_file(build_data_working, ansible_version): """Find the most recent ansible deps file for the given ansible major version.""" # imports here so that they don't cause unnecessary deps for all of the plugins @@ -82,8 +97,7 @@ def find_latest_deps_file(build_data_working, ansible_version): latest = None latest_ver = Version('0') for filename in deps_files: - with open(filename, 'r') as f: - deps_data = yaml.safe_load(f.read()) + deps_data = parse_deps_file(filename) new_version = Version(deps_data['_ansible_version']) if new_version > latest_ver: latest_ver = new_version @@ -157,14 +171,16 @@ def generate_full_docs(args): modified_deps_file = os.path.join(tmp_dir, 'ansible.deps') shutil.copyfile(latest_filename, modified_deps_file) - # Put our version of ansible-base into the deps file - with open(modified_deps_file, 'r') as f: - deps_data = yaml.safe_load(f.read()) + # Put our version of ansible-core into the deps file + deps_data = parse_deps_file(modified_deps_file) deps_data['_ansible_core_version'] = ansible_base__version__ - with open(modified_deps_file, 'w') as f: - f.write(yaml.dump(deps_data)) + # antsibull-docs will choke when a key `_python` is found. Remove it to work around + # that until antsibull-docs is fixed. + deps_data.pop('_python', None) + + write_deps_file(modified_deps_file, deps_data) params = ['stable', '--deps-file', modified_deps_file] |