aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2023-07-03 23:48:57 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2023-07-03 23:48:57 +0200
commit8e6e230a2a617d0f00077a870caf61a218e00ffb (patch)
tree3c1ef736bee45dbb5796be18b83daee36679aa83
parentHarden typesystem + misc. (diff)
downloadmuppet-strings-8e6e230a2a617d0f00077a870caf61a218e00ffb.tar.gz
muppet-strings-8e6e230a2a617d0f00077a870caf61a218e00ffb.tar.xz
Set up logging.
-rw-r--r--muppet/__main__.py15
-rw-r--r--muppet/output.py11
-rw-r--r--muppet/puppet/parser.py4
3 files changed, 30 insertions, 0 deletions
diff --git a/muppet/__main__.py b/muppet/__main__.py
index b064cf1..d72c161 100644
--- a/muppet/__main__.py
+++ b/muppet/__main__.py
@@ -3,12 +3,26 @@
import argparse
import pathlib
import os
+import logging
+import colorlog
from .cache import Cache
from .gather import get_module, get_modules, ModuleEntry
from .output import setup_index, setup_module
+logger = logging.getLogger('muppet')
+logger.setLevel(logging.DEBUG)
+
+
+ch = colorlog.StreamHandler()
+ch.setLevel(logging.INFO)
+# formatter = logging.Formatter('%(name)s - %(levelname)s - %(message)s')
+formatter = colorlog.ColoredFormatter('%(log_color)s%(name)s - %(levelname)s - %(message)s')
+ch.setFormatter(formatter)
+logger.addHandler(ch)
+
+
def __main() -> None:
parser = argparse.ArgumentParser(
prog='puppet-doc configure',
@@ -45,6 +59,7 @@ def __main() -> None:
for module in modules:
# print(module)
+ logger.info('Handling %s', module.name)
setup_module('output', module, path_base=args.path_base)
os.system('make -C static-src --silent install-full PREFIX=$PWD/output')
diff --git a/muppet/output.py b/muppet/output.py
index 016de72..c3a24ca 100644
--- a/muppet/output.py
+++ b/muppet/output.py
@@ -33,6 +33,7 @@ from .puppet.strings import (
DataTypeAlias,
PuppetClass,
)
+import logging
from .breadcrumbs import breadcrumbs
from .syntax_highlight import highlight
@@ -40,6 +41,9 @@ from dataclasses import dataclass, field
from . import templates
+logger = logging.getLogger(__name__)
+
+
# TODO replace 'output' with base, or put this somewhere else
pathlib.Path('output').mkdir(exist_ok=True)
jinja = Environment(
@@ -496,6 +500,7 @@ def setup_module(base: str, module: ModuleEntry, *, path_base: str) -> None:
data = module.strings_output
for puppet_class in data.puppet_classes + data.defined_types:
+ logger.debug('Formamting %s', puppet_class.name)
# localpath = puppet_class['name'].split('::')
localpath, _ = os.path.splitext(puppet_class.file)
dir = os.path.join(path, localpath)
@@ -552,6 +557,8 @@ def setup_module(base: str, module: ModuleEntry, *, path_base: str) -> None:
# puppet_class['line']
for type_alias in data.data_type_aliases:
+ logger.debug('Formamting %s', type_alias.name)
+
localpath, _ = os.path.splitext(type_alias.file)
dir = os.path.join(path, localpath)
pathlib.Path(dir).mkdir(parents=True, exist_ok=True)
@@ -576,6 +583,8 @@ def setup_module(base: str, module: ModuleEntry, *, path_base: str) -> None:
files: dict[str, str] = {}
for file in module.doc_files:
+ logger.debug('Formamting %s', file)
+
basename = os.path.basename(file)
if basename == 'REFERENCE.md':
with open(file) as f:
@@ -588,6 +597,8 @@ def setup_module(base: str, module: ModuleEntry, *, path_base: str) -> None:
doc_files: dict[str, str] = {}
for filename, filepath in files.items():
+ logger.debug('Formamting %s', filename)
+
name, _ = os.path.splitext(filename)
with open(filepath) as f:
raw_content = f.read()
diff --git a/muppet/puppet/parser.py b/muppet/puppet/parser.py
index 846ce11..b957303 100644
--- a/muppet/puppet/parser.py
+++ b/muppet/puppet/parser.py
@@ -11,6 +11,10 @@ import json
from typing import Any, TypeAlias, Union
from ..cache import Cache
+import logging
+
+
+logger = logging.getLogger(__name__)
# TODO cache path