Skip to content

Commit 8a367c0

Browse files
gmfrascamprahl
authored andcommitted
chore: Move logger setup to CLI in readme generator
- Also just create logger instances in the modules themselves rather than using a shared one in constants.py Signed-off-by: Giulio Frasca <[email protected]>
1 parent fa9f912 commit 8a367c0

File tree

7 files changed

+21
-58
lines changed

7 files changed

+21
-58
lines changed

scripts/generate_readme/cli.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import logging
55
from pathlib import Path
66

7-
from .constants import logger
7+
logger = logging.getLogger(__name__)
8+
89
from .writer import ReadmeWriter
910

1011

@@ -130,12 +131,18 @@ def main():
130131
# Parse arguments
131132
args = parse_arguments()
132133

134+
# Configure logging at application entry point
135+
log_level = logging.DEBUG if args.verbose else logging.INFO
136+
logging.basicConfig(
137+
level=log_level,
138+
format='%(levelname)s: %(message)s'
139+
)
140+
133141
# Create and run the README writer
134142
writer = ReadmeWriter(
135143
component_dir=args.component,
136144
pipeline_dir=args.pipeline,
137145
output_file=args.output,
138-
verbose=args.verbose,
139146
overwrite=args.overwrite
140147
)
141148
writer.generate()
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
"""Constants and shared configuration for the generate_readme package."""
22

3-
import logging
4-
5-
# Set up logger
6-
logger = logging.getLogger(__name__)
7-
83
# Custom content marker for preserving user-added content
94
CUSTOM_CONTENT_MARKER = '<!-- custom-content -->'

scripts/generate_readme/content_generator.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
"""README content generator for KFP components and pipelines."""
22

3+
import logging
34
import re
45
from pathlib import Path
56
from typing import Any, Dict
67
import yaml
78
from jinja2 import Environment, FileSystemLoader
8-
from .constants import logger
9+
10+
logger = logging.getLogger(__name__)
911

1012

1113
class ReadmeContentGenerator:

scripts/generate_readme/metadata_parser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
"""
77

88
import ast
9+
import logging
910
from pathlib import Path
1011
from typing import Any, Dict, Optional, Union
1112

1213
from docstring_parser import parse as parse_docstring
1314

14-
from .constants import logger
15+
logger = logging.getLogger(__name__)
1516

1617

1718
class MetadataParser:

scripts/generate_readme/tests/test_constants.py

Lines changed: 0 additions & 29 deletions
This file was deleted.

scripts/generate_readme/tests/test_writer.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ def test_init_with_component(self, component_dir):
1313
"""Test initialization with component directory."""
1414
generator = ReadmeWriter(
1515
component_dir=component_dir,
16-
verbose=False,
1716
overwrite=True
1817
)
1918

@@ -26,7 +25,6 @@ def test_init_with_pipeline(self, pipeline_dir):
2625
"""Test initialization with pipeline directory."""
2726
generator = ReadmeWriter(
2827
pipeline_dir=pipeline_dir,
29-
verbose=False,
3028
overwrite=True
3129
)
3230

@@ -170,15 +168,15 @@ def test_custom_output_file(self, component_dir, temp_dir):
170168
content = custom_output.read_text()
171169
assert "# Sample Component" in content
172170

173-
def test_generate_with_verbose(self, component_dir, caplog):
174-
"""Test that verbose mode produces debug output."""
171+
def test_generate_with_debug_logging(self, component_dir, caplog):
172+
"""Test that debug messages are logged when debug level is set."""
175173
import logging
176174

175+
# Set debug level (normally done by CLI)
177176
caplog.set_level(logging.DEBUG)
178177

179178
generator = ReadmeWriter(
180179
component_dir=component_dir,
181-
verbose=True,
182180
overwrite=True
183181
)
184182
generator.generate()

scripts/generate_readme/writer.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,24 @@
55
from pathlib import Path
66
from typing import Optional
77

8-
from .constants import CUSTOM_CONTENT_MARKER, logger
8+
from .constants import CUSTOM_CONTENT_MARKER
99
from .content_generator import ReadmeContentGenerator
1010
from .metadata_parser import MetadataParser
1111

12+
logger = logging.getLogger(__name__)
13+
1214

1315
class ReadmeWriter:
1416
"""Writes README documentation for Kubeflow Pipelines components and pipelines."""
1517

1618
def __init__(self, component_dir: Optional[Path] = None, pipeline_dir: Optional[Path] = None,
17-
output_file: Optional[Path] = None, verbose: bool = False, overwrite: bool = False):
19+
output_file: Optional[Path] = None, overwrite: bool = False):
1820
"""Initialize the README writer.
1921
2022
Args:
2123
component_dir: Path to the component directory (must contain component.py and metadata.yaml).
2224
pipeline_dir: Path to the pipeline directory (must contain pipeline.py and metadata.yaml).
2325
output_file: Optional output path for the generated README.
24-
verbose: Enable verbose logging output.
2526
overwrite: Overwrite existing README without prompting.
2627
"""
2728
# Validate that exactly one of component_dir or pipeline_dir is provided
@@ -46,20 +47,8 @@ def __init__(self, component_dir: Optional[Path] = None, pipeline_dir: Optional[
4647
self.parser = MetadataParser(self.source_file, self.function_type)
4748
self.metadata_file = self.source_dir / 'metadata.yaml'
4849
self.readme_file = output_file if output_file else self.source_dir / "README.md"
49-
self.verbose = verbose
5050
self.overwrite = overwrite
5151

52-
# Configure logging
53-
self._configure_logging()
54-
55-
def _configure_logging(self) -> None:
56-
"""Configure logging based on verbose flag."""
57-
log_level = logging.DEBUG if self.verbose else logging.INFO
58-
logging.basicConfig(
59-
level=log_level,
60-
format='%(levelname)s: %(message)s'
61-
)
62-
6352
def _extract_custom_content(self) -> Optional[str]:
6453
"""Extract custom content from existing README if it has a custom-content marker.
6554

0 commit comments

Comments
 (0)