Skip to content

Commit 6d1d641

Browse files
committed
refactor hooks
Signed-off-by: sirutBuasai <sirutbuasai27@outlook.com>
1 parent f2b8281 commit 6d1d641

File tree

3 files changed

+29
-31
lines changed

3 files changed

+29
-31
lines changed

docs/src/hooks.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,23 @@
1616
Add to mkdocs.yaml: hooks: [docs/src/hooks.py]
1717
"""
1818

19-
import logging
2019
import os
21-
import subprocess
2220

2321
from generate import generate_all
24-
from utils import load_yaml
25-
26-
logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")
27-
LOGGER = logging.getLogger(__name__)
22+
from utils import clone_git_repository, load_yaml
2823

2924
# Resolve paths relative to this file
3025
SRC_DIR = os.path.dirname(os.path.abspath(__file__))
3126
DOCS_DIR = os.path.dirname(SRC_DIR)
3227
DATA_FILE = os.path.join(SRC_DIR, "data", "images.yml")
33-
34-
35-
def clone_tutorials():
36-
"""Clone sample tutorials repository into docs/tutorials."""
37-
tutorials_dir = os.path.join(DOCS_DIR, "tutorials")
38-
if os.path.exists(tutorials_dir):
39-
return
40-
41-
repo_url = "https://github.com/aws-samples/sample-aws-deep-learning-containers"
42-
subprocess.run(["git", "clone", "--depth", "1", repo_url, tutorials_dir], check=True)
28+
TUTORIALS_DIR = os.path.join(DOCS_DIR, "tutorials")
4329

4430

4531
# MkDocs hook entry point
4632
def on_startup(command=["build", "gh-deploy", "serve"], dirty=False):
4733
"""MkDocs hook - runs before build."""
4834
yaml_data = load_yaml(DATA_FILE)
49-
clone_tutorials()
35+
tutorials_repo = "https://github.com/aws-samples/sample-aws-deep-learning-containers"
36+
37+
clone_git_repository(tutorials_repo, TUTORIALS_DIR)
5038
generate_all(yaml_data, dry_run=False)

docs/src/main.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
# Copyright 2018-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2-
#
3-
# Licensed under the Apache License, Version 2.0 (the "License"). You
4-
# may not use this file except in compliance with the License. A copy of
5-
# the License is located at
6-
#
7-
# http://aws.amazon.com/apache2.0/
8-
#
9-
# or in the "license" file accompanying this file. This file is
10-
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11-
# ANY KIND, either express or implied. See the License for the specific
12-
# language governing permissions and limitations under the License.
131
"""Documentation generation entry point.
142
153
Usage:
@@ -19,11 +7,22 @@
197
import argparse
208
import logging
219
import os
10+
import sys
2211

2312
from generate import generate_all, generate_available_images, generate_support_policy
13+
from logger import ColoredFormatter
2414
from utils import load_yaml
2515

26-
logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")
16+
# Configure root logger - all child loggers inherit this
17+
root_logger = logging.getLogger()
18+
root_logger.setLevel(logging.INFO)
19+
20+
console_handler = logging.StreamHandler(sys.stdout)
21+
console_handler.setFormatter(ColoredFormatter())
22+
console_handler.setLevel(logging.DEBUG)
23+
24+
root_logger.addHandler(console_handler)
25+
2726
LOGGER = logging.getLogger(__name__)
2827

2928
# Resolve paths relative to this file
@@ -49,7 +48,7 @@ def main():
4948
yaml_data = load_yaml(DATA_FILE)
5049

5150
if args.verbose:
52-
logging.getLogger().setLevel(logging.DEBUG)
51+
root_logger.setLevel(logging.DEBUG)
5352

5453
LOGGER.info(f"Loaded data from {DATA_FILE}")
5554

docs/src/utils.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
# language governing permissions and limitations under the License.
1313
"""Common utilities for documentation generation."""
1414

15+
import os
16+
import subprocess
17+
1518
import yaml
1619

1720

@@ -41,3 +44,11 @@ def write_output(path: str, content: str) -> None:
4144
"""Write generated markdown to file."""
4245
with open(path, "w") as f:
4346
f.write(content)
47+
48+
49+
def clone_git_repository(git_repository: str, target_dir: str) -> None:
50+
"""Clone sample tutorials repository into docs/tutorials."""
51+
if os.path.exists(target_dir):
52+
return
53+
54+
subprocess.run(["git", "clone", "--depth", "1", git_repository, target_dir], check=True)

0 commit comments

Comments
 (0)