diff --git a/README.md b/README.md index 73ffc38..882c082 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ Lazydocs makes it easy to generate beautiful markdown documentation for your Pyt ### Installation -> _Requirements: Python 3.6+._ +> _Requirements: Python 3.9+._ ```bash pip install lazydocs diff --git a/setup.py b/setup.py index b036aa2..332fb4b 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ EMAIL = "team@mltooling.org" AUTHOR = "ML Tooling Team" LICENSE = "MIT" -REQUIRES_PYTHON = ">=3.6" +REQUIRES_PYTHON = ">=3.9" VERSION = None # Only set version if you like to overwrite the version in _about.py PWD = os.path.abspath(os.path.dirname(__file__)) diff --git a/src/lazydocs/generation.py b/src/lazydocs/generation.py index e773445..7013dd9 100755 --- a/src/lazydocs/generation.py +++ b/src/lazydocs/generation.py @@ -624,6 +624,14 @@ def _lines_isvalid(lines: list, start_index: int, blockindent: int, prev_blank_line_count += 1 return "".join(out) + +def get_module(loader, module_name: str) -> Optional[Any]: + spec = loader.find_spec(module_name) + if spec is None: + raise ImportError(f"Cannot find module {module_name}") + return spec.loader.load_module(spec.name) + + class MarkdownGenerator(object): """Markdown generator class.""" @@ -1250,8 +1258,7 @@ def generate_docs( mod = importlib.util.module_from_spec(mod_spec) mod_spec.loader.exec_module(mod) except AttributeError: - # For older python version compatibility - mod = loader.find_module(module_name).load_module(module_name) # type: ignore + mod = get_module(loader, module_name) module_md = generator.module2md(mod, is_mdx=is_mdx, include_toc=include_toc) if not module_md: # Module md is empty -> ignore module and all submodules @@ -1334,8 +1341,7 @@ def generate_docs( mod = importlib.util.module_from_spec(mod_spec) mod_spec.loader.exec_module(mod) except AttributeError: - # For older python version compatibility - mod = loader.find_module(module_name).load_module(module_name) # type: ignore + mod = get_module(loader, module_name) module_md = generator.module2md(mod, is_mdx=is_mdx, include_toc=include_toc) if not module_md: diff --git a/tests/test_generation.py b/tests/test_generation.py index c53f489..1c81d9e 100644 --- a/tests/test_generation.py +++ b/tests/test_generation.py @@ -1,6 +1,7 @@ import hashlib -from lazydocs import MarkdownGenerator +from lazydocs import MarkdownGenerator, generate_docs +from tempfile import TemporaryDirectory def test_import2md() -> None: @@ -35,3 +36,31 @@ def test_func2md() -> None: # Remove whitespaces: fix changes between py version 3.6 3.7 in signature method md_hash = hashlib.md5(markdown.replace(" ", "").encode("utf-8")).hexdigest() assert md_hash == "797bad8c00ee6f189cb6f578eaec02c4" + + +def test_integration_generate_docs(capsys) -> None: + test_class = """ +class TestClass: + \"\"\"just a test class\"\"\" + """ + with TemporaryDirectory() as d: + test_module_name = "test_module" + with open(f"{d}/{test_module_name}.py", "w") as f: + f.write(test_class) + + overview_file_name = "DOCS.md" + overview_file = f"{d}/output/{overview_file_name}" + generate_docs( + paths=[d], + output_path=f"{d}/output/", + overview_file=overview_file_name + ) + + captured = capsys.readouterr() + + with open(overview_file) as f: + result = f.read() + + assert test_module_name in result + assert f"{test_module_name}.TestClass" in result + assert "Failed to generate docs for module" not in captured.out