Skip to content

Commit

Permalink
feat(logging): Using logging instead of print, in parse_config.
Browse files Browse the repository at this point in the history
  • Loading branch information
aemonge committed Oct 29, 2024
1 parent f758604 commit 4813ff0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 2 additions & 0 deletions pydoclint/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ast
import logging
import re
from pathlib import Path
from typing import Dict, List, Optional, Tuple
Expand Down Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions pydoclint/parse_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import sys
from pathlib import Path
from typing import Any, Dict, Optional, Sequence
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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

Expand Down

0 comments on commit 4813ff0

Please sign in to comment.