Skip to content

Commit 730da2b

Browse files
committed
refactor: move imports to function level for lazy loading
Move module imports inside functions to defer loading until needed. This improves startup performance by reducing initial import overhead.
1 parent 550a7f9 commit 730da2b

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

md_exporter/services/svc_md_to_html.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
from pathlib import Path
88

9-
from pypandoc import convert_text
10-
119
from ..utils.markdown_utils import get_md_text
1210

1311

@@ -24,6 +22,8 @@ def convert_md_to_html(md_text: str, output_path: Path, is_strip_wrapper: bool =
2422
ValueError: If input processing fails
2523
Exception: If conversion fails
2624
"""
25+
from pypandoc import convert_text # noqa: PLC0415
26+
2727
# Process Markdown text
2828
processed_md = get_md_text(md_text, is_strip_wrapper=is_strip_wrapper)
2929

md_exporter/services/svc_md_to_pdf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
from pathlib import Path
88

9-
from xhtml2pdf import pisa
10-
119
from ..utils.markdown_utils import convert_markdown_to_html, get_md_text
1210
from ..utils.text_utils import contains_chinese, contains_japanese
1311

@@ -65,6 +63,8 @@ def convert_md_to_pdf(md_text: str, output_path: Path, is_strip_wrapper: bool =
6563
ValueError: If input processing fails
6664
Exception: If conversion fails
6765
"""
66+
from xhtml2pdf import pisa # noqa: PLC0415
67+
6868
# Process Markdown text
6969
processed_md = get_md_text(md_text, is_strip_wrapper=is_strip_wrapper)
7070

md_exporter/services/svc_md_to_png.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
from pathlib import Path
99
from tempfile import NamedTemporaryFile
1010

11-
import pymupdf
12-
from PIL import Image
13-
from xhtml2pdf import pisa
14-
1511
from ..utils.logger_utils import get_logger
1612
from ..utils.markdown_utils import convert_markdown_to_html, get_md_text
1713
from ..utils.text_utils import contains_chinese, contains_japanese
@@ -68,6 +64,10 @@ def convert_md_to_png(
6864
ValueError: If input processing fails
6965
Exception: If conversion fails
7066
"""
67+
import pymupdf # noqa: PLC0415
68+
from PIL import Image # noqa: PLC0415
69+
from xhtml2pdf import pisa # noqa: PLC0415
70+
7171
# Process Markdown text
7272
processed_md = get_md_text(md_text, is_strip_wrapper=is_strip_wrapper)
7373

md_exporter/utils/pandoc_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import os
77
import tempfile
88

9-
from pypandoc import convert_file
10-
119
from md_exporter.utils import get_logger
1210

1311
DEFAULT_ENABLED_INPUT_EXTENSIONS = []
@@ -31,6 +29,8 @@ def pandoc_convert_file(
3129
"""
3230
Convert file using pandoc
3331
"""
32+
from pypandoc import convert_file # noqa: PLC0415
33+
3434
extra_args = extra_args or []
3535
enabled = enabled_input_extensions or []
3636
disabled = disabled_input_extensions or []

0 commit comments

Comments
 (0)