From 4813ff02d4e8b76700c77e938621b3d758bae0e1 Mon Sep 17 00:00:00 2001 From: aemonge Date: Tue, 29 Oct 2024 17:00:53 +0100 Subject: [PATCH] feat(logging): Using logging instead of print, in parse_config. --- pydoclint/main.py | 2 ++ pydoclint/parse_config.py | 13 +++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pydoclint/main.py b/pydoclint/main.py index c05ccc2..06f03f6 100644 --- a/pydoclint/main.py +++ b/pydoclint/main.py @@ -1,4 +1,5 @@ import ast +import logging import re from pathlib import Path from typing import Dict, List, Optional, Tuple @@ -329,6 +330,7 @@ def main( # noqa: C901 config: Optional[str], # don't remove it b/c it's required by `click` ) -> None: """Command-line entry point of pydoclint""" + logging.basicConfig(level=logging.WARN if quiet else logging.INFO) ctx.ensure_object(dict) if type_hints_in_docstring != 'None': # it means users supply this option diff --git a/pydoclint/parse_config.py b/pydoclint/parse_config.py index 2cd02f8..def6090 100644 --- a/pydoclint/parse_config.py +++ b/pydoclint/parse_config.py @@ -1,3 +1,4 @@ +import logging import sys from pathlib import Path from typing import Any, Dict, Optional, Sequence @@ -36,7 +37,7 @@ def injectDefaultOptionsFromUserSpecifiedTomlFilePath( if not value: return None - print(f'Loading config from user-specified .toml file: {value}') + logging.info(f'Loading config from user-specified .toml file: {value}') config = parseOneTomlFile(tomlFilename=Path(value)) updateCtxDefaultMap(ctx=ctx, config=config) return value @@ -49,14 +50,14 @@ def parseToml(paths: Optional[Sequence[str]]) -> Dict[str, Any]: commonParent: Path = findCommonParentFolder(paths) tomlFilename = commonParent / Path('pyproject.toml') - print(f'Loading config from inferred .toml file path: {tomlFilename}') + logging.info(f'Loading config from inferred .toml file path: {tomlFilename}') return parseOneTomlFile(tomlFilename) def parseOneTomlFile(tomlFilename: Path) -> Dict[str, Any]: """Parse a .toml file""" if not tomlFilename.exists(): - print(f'File "{tomlFilename}" does not exist; nothing to load.') + logging.info(f'File "{tomlFilename}" does not exist; nothing to load.') return {} try: @@ -71,10 +72,10 @@ def parseOneTomlFile(tomlFilename: Path) -> Dict[str, Any]: finalConfig = {} if len(finalConfig) > 0: - print(f'Found options defined in {tomlFilename}:') - print(finalConfig) + logging.info(f'Found options defined in {tomlFilename}:') + logging.info(finalConfig) else: - print(f'No config found in {tomlFilename}.') + logging.info(f'No config found in {tomlFilename}.') return finalConfig