Skip to content

Commit 92905f9

Browse files
committed
🎉 Init
1 parent 9c4e37c commit 92905f9

File tree

4 files changed

+38
-7
lines changed

4 files changed

+38
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Lazydocs makes it easy to generate beautiful markdown documentation for your Pyt
3838

3939
### Installation
4040

41-
> _Requirements: Python 3.6+._
41+
> _Requirements: Python 3.9+._
4242
4343
```bash
4444
pip install lazydocs

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
1616
AUTHOR = "ML Tooling Team"
1717
LICENSE = "MIT"
18-
REQUIRES_PYTHON = ">=3.6"
18+
REQUIRES_PYTHON = ">=3.9"
1919
VERSION = None # Only set version if you like to overwrite the version in _about.py
2020

2121
PWD = os.path.abspath(os.path.dirname(__file__))

src/lazydocs/generation.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,15 @@ def _lines_isvalid(lines: list, start_index: int, blockindent: int,
624624
prev_blank_line_count += 1
625625
return "".join(out)
626626

627+
628+
def get_module(loader, module_name: str) -> Optional[Any]:
629+
spec = loader.find_spec(module_name)
630+
if spec is None:
631+
raise ImportError(f"Cannot find module {module_name}")
632+
633+
return importlib.util.module_from_spec(spec)
634+
635+
627636
class MarkdownGenerator(object):
628637
"""Markdown generator class."""
629638

@@ -1250,8 +1259,7 @@ def generate_docs(
12501259
mod = importlib.util.module_from_spec(mod_spec)
12511260
mod_spec.loader.exec_module(mod)
12521261
except AttributeError:
1253-
# For older python version compatibility
1254-
mod = loader.find_module(module_name).load_module(module_name) # type: ignore
1262+
mod = get_module(loader, module_name)
12551263
module_md = generator.module2md(mod, is_mdx=is_mdx, include_toc=include_toc)
12561264
if not module_md:
12571265
# Module md is empty -> ignore module and all submodules
@@ -1334,8 +1342,7 @@ def generate_docs(
13341342
mod = importlib.util.module_from_spec(mod_spec)
13351343
mod_spec.loader.exec_module(mod)
13361344
except AttributeError:
1337-
# For older python version compatibility
1338-
mod = loader.find_module(module_name).load_module(module_name) # type: ignore
1345+
mod = get_module(loader, module_name)
13391346
module_md = generator.module2md(mod, is_mdx=is_mdx, include_toc=include_toc)
13401347

13411348
if not module_md:

tests/test_generation.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import hashlib
22

3-
from lazydocs import MarkdownGenerator
3+
from lazydocs import MarkdownGenerator, generate_docs
4+
from tempfile import TemporaryDirectory
45

56

67
def test_import2md() -> None:
@@ -35,3 +36,26 @@ def test_func2md() -> None:
3536
# Remove whitespaces: fix changes between py version 3.6 3.7 in signature method
3637
md_hash = hashlib.md5(markdown.replace(" ", "").encode("utf-8")).hexdigest()
3738
assert md_hash == "797bad8c00ee6f189cb6f578eaec02c4"
39+
40+
41+
def test_integration_generate_docs(capsys) -> None:
42+
with TemporaryDirectory() as d:
43+
test_module_name = "test_module"
44+
with open(f"{d}/{test_module_name}.py", "w") as f:
45+
f.write("")
46+
47+
overview_file_name = "DOCS.md"
48+
overview_file = f"{d}/output/{overview_file_name}"
49+
generate_docs(
50+
paths=[d],
51+
output_path=f"{d}/output/",
52+
overview_file=overview_file_name
53+
)
54+
55+
captured = capsys.readouterr()
56+
57+
with open(overview_file) as f:
58+
result = f.read()
59+
60+
assert test_module_name in result
61+
assert "Failed to generate docs for module" not in captured.out

0 commit comments

Comments
 (0)