From b1927c02c3547a8e31ec6defbfb702d17d1a4396 Mon Sep 17 00:00:00 2001 From: Dominik Gresch Date: Thu, 3 Oct 2024 14:31:42 +0200 Subject: [PATCH] Fix docstring indentation --- .../_grpc_helpers/property_helper.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/ansys/acp/core/_tree_objects/_grpc_helpers/property_helper.py b/src/ansys/acp/core/_tree_objects/_grpc_helpers/property_helper.py index a8376b58ab..aafa3f6690 100644 --- a/src/ansys/acp/core/_tree_objects/_grpc_helpers/property_helper.py +++ b/src/ansys/acp/core/_tree_objects/_grpc_helpers/property_helper.py @@ -29,6 +29,7 @@ from collections.abc import Callable from functools import reduce +import sys from typing import TYPE_CHECKING, Any, TypeVar from google.protobuf.message import Message @@ -93,8 +94,20 @@ def mark_grpc_properties(cls: T) -> T: cls._GRPC_PROPERTIES = tuple(props_unique) if cls._SUPPORTED_SINCE is not None: if isinstance(cls.__doc__, str): + # When adding to the docstring, we need to match the existing + # indentation of the docstring (except the first line). + # See PEP 257 'Handling Docstring Indentation'. + # Alternatively, we could strip the common indentation from the + # docstring. + indent = sys.maxsize + for line in cls.__doc__.splitlines()[1:]: + stripped = line.lstrip() + if stripped: # ignore empty lines + indent = min(indent, len(line) - len(stripped)) + if indent == sys.maxsize: + indent = 0 cls.__doc__ += ( - f"\n\nSupported since ACP gRPC server version {cls._SUPPORTED_SINCE}.\n\n" + f"\n\n{indent * ' '}*Added in ACP server version {cls._SUPPORTED_SINCE}.*\n" ) return cls