From 6f22823bed74c809bf92110393d6b404c1780e93 Mon Sep 17 00:00:00 2001 From: simonhammes Date: Wed, 30 Oct 2024 18:36:44 +0100 Subject: [PATCH 1/4] Refactor to increase readability --- scripts/generate_operations_docs.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/scripts/generate_operations_docs.py b/scripts/generate_operations_docs.py index a8329f2c5..da250421a 100755 --- a/scripts/generate_operations_docs.py +++ b/scripts/generate_operations_docs.py @@ -141,11 +141,18 @@ def build_operations_docs(): ) # Build args string - args = [ - "{0}={1}".format(arg, defaults[arg]) if arg in defaults else arg - for arg in argspec.args - if arg not in ("state", "host") and not arg.startswith("_") - ] + args = [] + + for arg in argspec.args: + if arg in ("state", "host") or arg.startswith("_"): + continue + + value = arg + + if arg in defaults: + value += f'={defaults[arg]}' + + args.append(value) if len(", ".join(args)) <= MODULE_DEF_LINE_MAX: args_string = ", ".join(args) From 6e62ea4c8dde147116fd206908065862050cd171 Mon Sep 17 00:00:00 2001 From: simonhammes Date: Wed, 30 Oct 2024 18:49:52 +0100 Subject: [PATCH 2/4] Add type annotations to operation docs --- scripts/generate_operations_docs.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/generate_operations_docs.py b/scripts/generate_operations_docs.py index da250421a..fba36f8b3 100755 --- a/scripts/generate_operations_docs.py +++ b/scripts/generate_operations_docs.py @@ -149,6 +149,9 @@ def build_operations_docs(): value = arg + if arg in argspec.annotations: + value += f': {argspec.annotations[arg]}' + if arg in defaults: value += f'={defaults[arg]}' From 67934e20eb0c287a9a9d61348e172246bb00c20c Mon Sep 17 00:00:00 2001 From: simonhammes Date: Wed, 30 Oct 2024 18:52:02 +0100 Subject: [PATCH 3/4] Fix "Could not lex literal_block" warning when building docs Related: https://blog.derlin.ch/python-type-hints-and-future-annotations --- pyinfra/operations/runit.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyinfra/operations/runit.py b/pyinfra/operations/runit.py index d92380ca5..444d92d74 100644 --- a/pyinfra/operations/runit.py +++ b/pyinfra/operations/runit.py @@ -2,6 +2,8 @@ Manage runit services. """ +from __future__ import annotations + from typing import Optional from pyinfra import host From 674df3681a3f68afcefbc2984614e67c69f29aa0 Mon Sep 17 00:00:00 2001 From: simonhammes Date: Wed, 30 Oct 2024 18:57:16 +0100 Subject: [PATCH 4/4] Fix CS --- scripts/generate_operations_docs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/generate_operations_docs.py b/scripts/generate_operations_docs.py index fba36f8b3..8faca4232 100755 --- a/scripts/generate_operations_docs.py +++ b/scripts/generate_operations_docs.py @@ -150,10 +150,10 @@ def build_operations_docs(): value = arg if arg in argspec.annotations: - value += f': {argspec.annotations[arg]}' + value += f": {argspec.annotations[arg]}" if arg in defaults: - value += f'={defaults[arg]}' + value += f"={defaults[arg]}" args.append(value)