trlcdoc.util ============ .. py:module:: trlcdoc.util .. autoapi-nested-parse:: Common helpers of the trlcdoc steps. Attributes ---------- .. autoapisummary:: trlcdoc.util.MARKER_FILE trlcdoc.util.MARKER_TEXT trlcdoc.util.LOG Exceptions ---------- .. autoapisummary:: trlcdoc.util.TrlcdocError Functions --------- .. autoapisummary:: trlcdoc.util.find_tool trlcdoc.util.find_graphviz trlcdoc.util.run trlcdoc.util.run_unchecked trlcdoc.util.prepare_output trlcdoc.util.clean_dir trlcdoc.util.remove_output trlcdoc.util.git_output trlcdoc.util.git_root trlcdoc.util.repository_url Module Contents --------------- .. py:data:: MARKER_FILE :value: '.trlcdoc' .. py:data:: MARKER_TEXT :value: Multiline-String .. raw:: html
Show Value .. code-block:: python """Generated by trlcdoc. The whole folder is removed by 'trlcdoc clean' ! """ .. raw:: html
.. py:data:: LOG .. py:exception:: TrlcdocError Bases: :py:obj:`Exception` .. autoapi-inheritance-diagram:: trlcdoc.util.TrlcdocError :parts: 1 Error that stops the documentation build with a message. .. py:function:: find_tool(name: str, hint: str = 'Install the trlcdoc package dependencies.') -> str Find a console script, preferring the one of the running Python environment. Tools that are not installed with trlcdoc, e.g. Java, are searched on the PATH. :param name: Name of the console script, e.g. 'lobster-trlc'. :type name: str :param hint: How to install the tool, added to the error message. :type hint: str :returns: Path of the executable. :rtype: str :raises TrlcdocError: If the tool is not installed. .. py:function:: find_graphviz(purpose: str) -> str Find the Graphviz dot program, so a missing Graphviz stops the build instead of leaving out diagrams. :param purpose: What needs Graphviz, added to the error message, e.g. 'for the tracing policy diagram'. :type purpose: str :returns: Path of the dot executable. :rtype: str :raises TrlcdocError: If dot is not on the PATH. .. py:function:: run(cmd: list[str], cwd: pathlib.Path, env: dict[str, str] | None = None, stdin: str | None = None, source: str | None = None) -> int Run an external command and stop the build if it fails. :param cmd: Command and its arguments. :type cmd: list[str] :param cwd: Working directory. :type cwd: Path :param env: Additional environment variables. :type env: dict[str, str] | None :param stdin: Text passed to the standard input of the command. :type stdin: str | None :param source: Configuration entry of the command, e.g. 'tests.command', named in the error message if the program can't be started. None for the tools trlcdoc runs itself. :type source: str | None :returns: The exit code, which is always 0. :rtype: int :raises TrlcdocError: If the program can't be started or the command returns a non-zero exit code. .. py:function:: run_unchecked(cmd: list[str], cwd: pathlib.Path, env: dict[str, str] | None = None, stdin: str | None = None, source: str | None = None) -> int Run an external command and return its exit code. The command is always shown. Verbose output adds the working folder, the environment variables the command gets from trlcdoc, the size of its input, its exit code and duration. The output of the command is not captured, it goes directly to the console. :param cmd: Command and its arguments. :type cmd: list[str] :param cwd: Working directory. :type cwd: Path :param env: Additional environment variables. :type env: dict[str, str] | None :param stdin: Text passed to the standard input of the command. :type stdin: str | None :param source: Configuration entry of the command, e.g. 'tests.command', named in the error message if the program can't be started. None for the tools trlcdoc runs itself. :type source: str | None :returns: The exit code of the command. :rtype: int :raises TrlcdocError: If the program is not found or not executable. .. py:function:: prepare_output(output: pathlib.Path) -> pathlib.Path Create the output folder if needed and mark it as owned by trlcdoc. :param output: The output folder. :type output: Path :returns: The output folder. :rtype: Path :raises TrlcdocError: If the folder exists with content but without the marker file. .. py:function:: clean_dir(folder: pathlib.Path, output: pathlib.Path) -> pathlib.Path Create an empty folder inside the output folder, removing previous content. :param folder: The folder, a subfolder of the output folder. :type folder: Path :param output: The output folder. :type output: Path :returns: The folder. :rtype: Path :raises TrlcdocError: If the folder is not inside a trlcdoc output folder. .. py:function:: remove_output(output: pathlib.Path) -> bool Remove the output folder with all its content. :param output: The output folder. :type output: Path :returns: True if the folder existed and was removed. :rtype: bool :raises TrlcdocError: If the folder exists with content but without the marker file. .. py:function:: git_output(args: list[str], cwd: pathlib.Path) -> str | None Run a git command and return its output. :param args: git arguments. :type args: list[str] :param cwd: Working directory. :type cwd: Path :returns: The stripped output, or None if git failed. :rtype: str | None .. py:function:: git_root(path: pathlib.Path) -> pathlib.Path | None Get the root folder of the git repository that contains a folder. The project root is a subfolder of the repository if several projects share one repository. :param path: A folder inside the repository, e.g. the project root. :type path: Path :returns: The resolved repository root, or None if the folder is not in a git repository. :rtype: Path | None .. py:function:: repository_url(repository: str, root: pathlib.Path) -> str Get the repository URL for links to project files. :param repository: Configured repository URL or 'auto' for the origin remote. :type repository: str :param root: Project root, the git working directory. :type root: Path :returns: HTTPS repository URL without '.git' suffix, the base of the file links. :rtype: str :raises TrlcdocError: If 'auto' is configured and git has no origin remote.