diff --git a/mknodes/basenodes/_mkdocstrings/__init__.py b/mknodes/basenodes/_mkdocstrings/__init__.py index 1b11f305..bbbc9238 100644 --- a/mknodes/basenodes/_mkdocstrings/__init__.py +++ b/mknodes/basenodes/_mkdocstrings/__init__.py @@ -1,15 +1,17 @@ from __future__ import annotations from collections.abc import Callable -import os import types import griffe -from typing import Any, Literal +from typing import Any, Literal, TYPE_CHECKING from mknodes.basenodes import mknode from mknodes.utils import classhelpers, log, reprhelpers, resources +if TYPE_CHECKING: + import os + logger = log.get_logger(__name__) diff --git a/mknodes/basenodes/mkadmonition/__init__.py b/mknodes/basenodes/mkadmonition/__init__.py index 7ad05690..f2c41f9a 100644 --- a/mknodes/basenodes/mkadmonition/__init__.py +++ b/mknodes/basenodes/mkadmonition/__init__.py @@ -2,12 +2,14 @@ import textwrap -from typing import Any, Literal +from typing import Any, Literal, TYPE_CHECKING from mknodes.basenodes import mkcontainer, mknode -from mknodes.data import datatypes from mknodes.utils import log, resources +if TYPE_CHECKING: + from mknodes.data import datatypes + logger = log.get_logger(__name__) diff --git a/mknodes/basenodes/mkbinaryimage/__init__.py b/mknodes/basenodes/mkbinaryimage/__init__.py index 158c1210..edcde1ed 100644 --- a/mknodes/basenodes/mkbinaryimage/__init__.py +++ b/mknodes/basenodes/mkbinaryimage/__init__.py @@ -1,16 +1,18 @@ from __future__ import annotations -import os import upath -from typing import Any, Literal, Self +from typing import Any, Literal, Self, TYPE_CHECKING from jinjarope import textfilters from mknodes.basenodes import mkimage -from mknodes.info import linkprovider from mknodes.utils import icons, log +if TYPE_CHECKING: + from mknodes.info import linkprovider + import os + logger = log.get_logger(__name__) diff --git a/mknodes/basenodes/mkclidoc/__init__.py b/mknodes/basenodes/mkclidoc/__init__.py index d38380d0..120cc60a 100644 --- a/mknodes/basenodes/mkclidoc/__init__.py +++ b/mknodes/basenodes/mkclidoc/__init__.py @@ -1,12 +1,14 @@ from __future__ import annotations -import argparse -from typing import Any +from typing import Any, TYPE_CHECKING from mknodes.templatenodes import mktemplate from mknodes.utils import log from mknodes.info.cli import clihelpers, commandinfo +if TYPE_CHECKING: + import argparse + logger = log.get_logger(__name__) diff --git a/mknodes/basenodes/mkcode/__init__.py b/mknodes/basenodes/mkcode/__init__.py index 720bcab8..bf6088e8 100644 --- a/mknodes/basenodes/mkcode/__init__.py +++ b/mknodes/basenodes/mkcode/__init__.py @@ -1,7 +1,6 @@ from __future__ import annotations import inspect -import os import textwrap import types @@ -16,6 +15,7 @@ if TYPE_CHECKING: + import os import mknodes as mk logger = log.get_logger(__name__) diff --git a/mknodes/basenodes/mkcompactadmonition/__init__.py b/mknodes/basenodes/mkcompactadmonition/__init__.py index d63b55de..b8ca3ded 100644 --- a/mknodes/basenodes/mkcompactadmonition/__init__.py +++ b/mknodes/basenodes/mkcompactadmonition/__init__.py @@ -1,11 +1,13 @@ from __future__ import annotations -from typing import Any +from typing import Any, TYPE_CHECKING from mknodes.basenodes import mknode -from mknodes.data import datatypes from mknodes.utils import log, resources, xmlhelpers +if TYPE_CHECKING: + from mknodes.data import datatypes + logger = log.get_logger(__name__) diff --git a/mknodes/basenodes/mkcontainer/__init__.py b/mknodes/basenodes/mkcontainer/__init__.py index 67afd218..adf6bd19 100644 --- a/mknodes/basenodes/mkcontainer/__init__.py +++ b/mknodes/basenodes/mkcontainer/__init__.py @@ -1,12 +1,14 @@ from __future__ import annotations -from collections.abc import Iterator -from typing import Any +from typing import Any, TYPE_CHECKING from mknodes.basenodes import mknode from mknodes.utils import log +if TYPE_CHECKING: + from collections.abc import Iterator + logger = log.get_logger(__name__) diff --git a/mknodes/basenodes/mkdetailsblock/__init__.py b/mknodes/basenodes/mkdetailsblock/__init__.py index f79ef820..620dafee 100644 --- a/mknodes/basenodes/mkdetailsblock/__init__.py +++ b/mknodes/basenodes/mkdetailsblock/__init__.py @@ -3,11 +3,11 @@ from typing import TYPE_CHECKING, Any from mknodes.basenodes import mkblock -from mknodes.data import datatypes from mknodes.utils import log, reprhelpers, resources if TYPE_CHECKING: + from mknodes.data import datatypes import mknodes as mk diff --git a/mknodes/basenodes/mklist/__init__.py b/mknodes/basenodes/mklist/__init__.py index 843344d9..16dea948 100644 --- a/mknodes/basenodes/mklist/__init__.py +++ b/mknodes/basenodes/mklist/__init__.py @@ -1,12 +1,14 @@ from __future__ import annotations -from collections.abc import Sequence -from typing import Any +from typing import Any, TYPE_CHECKING from mknodes.basenodes import mkcontainer, mknode from mknodes.info import linkprovider from mknodes.utils import log, resources +if TYPE_CHECKING: + from collections.abc import Sequence + logger = log.get_logger(__name__) diff --git a/mknodes/basenodes/mknode/__init__.py b/mknodes/basenodes/mknode/__init__.py index 30bc532b..ac44b6b7 100644 --- a/mknodes/basenodes/mknode/__init__.py +++ b/mknodes/basenodes/mknode/__init__.py @@ -6,7 +6,6 @@ from typing import TYPE_CHECKING, Any from mknodes.basenodes import processors -from mknodes.data import datatypes from mknodes.info import contexts, nodefile from mknodes.jinja import nodeenvironment from mknodes.nodemods.modmanager import ModManager @@ -15,6 +14,7 @@ if TYPE_CHECKING: + from mknodes.data import datatypes import mknodes as mk diff --git a/mknodes/basenodes/mktabcontainer.py b/mknodes/basenodes/mktabcontainer.py index 22992a79..68e5ffe8 100644 --- a/mknodes/basenodes/mktabcontainer.py +++ b/mknodes/basenodes/mktabcontainer.py @@ -1,12 +1,15 @@ from __future__ import annotations -from collections.abc import Mapping -from typing import Any +from typing import TYPE_CHECKING, Any from mknodes.basenodes import mkcontainer, mknode, mktabs, mktext from mknodes.utils import log, reprhelpers +if TYPE_CHECKING: + from collections.abc import Mapping + + logger = log.get_logger(__name__) diff --git a/mknodes/data/datatypes.py b/mknodes/data/datatypes.py index cf97bfb6..da7742a1 100644 --- a/mknodes/data/datatypes.py +++ b/mknodes/data/datatypes.py @@ -2,10 +2,13 @@ import collections from collections.abc import Callable, ItemsView, KeysView, ValuesView -from dataclasses import Field import types from types import MappingProxyType, SimpleNamespace -from typing import Any, ClassVar, Literal, Protocol, runtime_checkable +from typing import TYPE_CHECKING, Any, ClassVar, Literal, Protocol, runtime_checkable + + +if TYPE_CHECKING: + from dataclasses import Field AdmonitionTypeStr = Literal[ diff --git a/mknodes/data/fences.py b/mknodes/data/fences.py index 16a013cd..5649eb0f 100644 --- a/mknodes/data/fences.py +++ b/mknodes/data/fences.py @@ -1,11 +1,15 @@ from __future__ import annotations -from collections.abc import Callable import dataclasses +from typing import TYPE_CHECKING from pymdownx import superfences +if TYPE_CHECKING: + from collections.abc import Callable + + @dataclasses.dataclass(frozen=True) class Fences: """Class describing a superfence. diff --git a/mknodes/extranodes/mkcodeimage/__init__.py b/mknodes/extranodes/mkcodeimage/__init__.py index 15d1fc0a..26a841f1 100644 --- a/mknodes/extranodes/mkcodeimage/__init__.py +++ b/mknodes/extranodes/mkcodeimage/__init__.py @@ -1,17 +1,19 @@ from __future__ import annotations -import os import textwrap -from typing import Any, Self +from typing import Any, Self, TYPE_CHECKING from jinjarope import textfilters import upath from mknodes.basenodes import mknode -from mknodes.data import datatypes from mknodes.utils import classhelpers, inspecthelpers, log, richhelpers +if TYPE_CHECKING: + from mknodes.data import datatypes + import os + logger = log.get_logger(__name__) diff --git a/mknodes/extranodes/mkprettyprint/__init__.py b/mknodes/extranodes/mkprettyprint/__init__.py index a643ee75..c86f5f7e 100644 --- a/mknodes/extranodes/mkprettyprint/__init__.py +++ b/mknodes/extranodes/mkprettyprint/__init__.py @@ -1,11 +1,13 @@ from __future__ import annotations -from typing import Any +from typing import Any, TYPE_CHECKING from mknodes.templatenodes import mktemplate -from mknodes.data import datatypes from mknodes.utils import log +if TYPE_CHECKING: + from mknodes.data import datatypes + logger = log.get_logger(__name__) diff --git a/mknodes/extranodes/mkseedir/__init__.py b/mknodes/extranodes/mkseedir/__init__.py index d43d5ca6..22b05f68 100644 --- a/mknodes/extranodes/mkseedir/__init__.py +++ b/mknodes/extranodes/mkseedir/__init__.py @@ -1,13 +1,15 @@ from __future__ import annotations -import os import upath -from typing import Any, Literal +from typing import Any, Literal, TYPE_CHECKING from mknodes.basenodes import mkcode from mknodes.utils import helpers, log, resources +if TYPE_CHECKING: + import os + logger = log.get_logger(__name__) diff --git a/mknodes/extranodes/mksnippet/__init__.py b/mknodes/extranodes/mksnippet/__init__.py index beeb0bf0..7e3cd039 100644 --- a/mknodes/extranodes/mksnippet/__init__.py +++ b/mknodes/extranodes/mksnippet/__init__.py @@ -1,11 +1,13 @@ from __future__ import annotations -import os -from typing import Any +from typing import Any, TYPE_CHECKING from mknodes.basenodes import mknode from mknodes.utils import log, resources +if TYPE_CHECKING: + import os + logger = log.get_logger(__name__) diff --git a/mknodes/info/cli/commandinfo.py b/mknodes/info/cli/commandinfo.py index ecac0968..2138b1ad 100644 --- a/mknodes/info/cli/commandinfo.py +++ b/mknodes/info/cli/commandinfo.py @@ -1,11 +1,15 @@ from __future__ import annotations import dataclasses +from typing import TYPE_CHECKING -from mknodes.info.cli import param from mknodes.utils import reprhelpers +if TYPE_CHECKING: + from mknodes.info.cli import param + + @dataclasses.dataclass(frozen=True) class CommandInfo: name: str diff --git a/mknodes/info/cli/param.py b/mknodes/info/cli/param.py index 526ddb1a..0f75527d 100644 --- a/mknodes/info/cli/param.py +++ b/mknodes/info/cli/param.py @@ -1,6 +1,5 @@ from __future__ import annotations -from collections.abc import Callable import dataclasses from typing import TYPE_CHECKING, Any, Literal @@ -8,6 +7,8 @@ if TYPE_CHECKING: + from collections.abc import Callable + from click import types as clicktypes diff --git a/mknodes/info/configfile.py b/mknodes/info/configfile.py index 4c8c11e9..e66285c4 100644 --- a/mknodes/info/configfile.py +++ b/mknodes/info/configfile.py @@ -1,13 +1,16 @@ from __future__ import annotations -import os -from typing import Any +from typing import TYPE_CHECKING, Any import upath from mknodes.utils import superdict +if TYPE_CHECKING: + import os + + class ConfigFile(superdict.SuperDict): def __init__(self, path: str | os.PathLike | None = None): """Constructor. diff --git a/mknodes/info/contexts.py b/mknodes/info/contexts.py index 2c9b8cfa..7e07434b 100644 --- a/mknodes/info/contexts.py +++ b/mknodes/info/contexts.py @@ -3,12 +3,9 @@ import abc from collections.abc import Mapping, MutableMapping import dataclasses -import datetime import pathlib -import types -from typing import Any +from typing import TYPE_CHECKING, Any -from griffe.dataclasses import Alias, Module import jinjarope import mknodes as mk @@ -21,10 +18,18 @@ packageregistry, pyproject, ) -from mknodes.info.cli import commandinfo from mknodes.utils import log, superdict +if TYPE_CHECKING: + import datetime + import types + + from griffe.dataclasses import Alias, Module + + from mknodes.info.cli import commandinfo + + logger = log.get_logger(__name__) DEFAULT_LOADER = jinjarope.FileSystemLoader("docs") diff --git a/mknodes/info/folderinfo.py b/mknodes/info/folderinfo.py index 8bd7bb9b..51feca4a 100644 --- a/mknodes/info/folderinfo.py +++ b/mknodes/info/folderinfo.py @@ -4,10 +4,8 @@ import dataclasses import functools import importlib -import os import pathlib import re -import types from typing import TYPE_CHECKING from mknodes.data import commitconventions, installmethods, taskrunners, tools @@ -32,6 +30,9 @@ if TYPE_CHECKING: + import os + import types + import griffe from griffe.dataclasses import Alias diff --git a/mknodes/info/githubinfo.py b/mknodes/info/githubinfo.py index 8151c974..2997e10a 100644 --- a/mknodes/info/githubinfo.py +++ b/mknodes/info/githubinfo.py @@ -1,9 +1,9 @@ from __future__ import annotations import dataclasses -import datetime import functools import os +from typing import TYPE_CHECKING import github from github import Commit @@ -12,6 +12,10 @@ from mknodes.utils import downloadhelpers, log, pathhelpers, reprhelpers +if TYPE_CHECKING: + import datetime + + TOKEN = os.environ.get("GITHUB_TOKEN") auth = github.Auth.Token(TOKEN) if TOKEN else None logger = log.get_logger(__name__) diff --git a/mknodes/info/gitrepository.py b/mknodes/info/gitrepository.py index 6a872c70..f3b6bc96 100644 --- a/mknodes/info/gitrepository.py +++ b/mknodes/info/gitrepository.py @@ -1,9 +1,7 @@ from __future__ import annotations import functools -import os -import tempfile -from typing import Any, Self +from typing import TYPE_CHECKING, Any, Self from urllib import parse import git @@ -13,6 +11,11 @@ from mknodes.utils import log, reprhelpers +if TYPE_CHECKING: + import os + import tempfile + + logger = log.get_logger(__name__) diff --git a/mknodes/info/grifferegistry.py b/mknodes/info/grifferegistry.py index d7474c76..2cbb4672 100644 --- a/mknodes/info/grifferegistry.py +++ b/mknodes/info/grifferegistry.py @@ -3,15 +3,19 @@ from abc import ABCMeta from collections.abc import MutableMapping import types +from typing import TYPE_CHECKING -import griffe -from griffe.dataclasses import Alias from griffe.enumerations import Parser from griffe.loader import GriffeLoader from mknodes.utils import log +if TYPE_CHECKING: + import griffe + from griffe.dataclasses import Alias + + logger = log.get_logger(__name__) diff --git a/mknodes/info/linkprovider.py b/mknodes/info/linkprovider.py index 1f123181..03d60669 100644 --- a/mknodes/info/linkprovider.py +++ b/mknodes/info/linkprovider.py @@ -1,8 +1,6 @@ from __future__ import annotations -from collections.abc import Sequence from importlib import metadata -import os import sys import types from typing import TYPE_CHECKING @@ -19,6 +17,9 @@ if TYPE_CHECKING: + from collections.abc import Sequence + import os + import mknodes as mk LinkableType = str | mk.MkPage | mk.MkNav | mk.MkHeader | types.ModuleType | type diff --git a/mknodes/info/nodefile.py b/mknodes/info/nodefile.py index 12634cd3..c6bca6fe 100644 --- a/mknodes/info/nodefile.py +++ b/mknodes/info/nodefile.py @@ -1,9 +1,6 @@ from __future__ import annotations -from collections.abc import Generator import functools -import os -import pathlib from typing import TYPE_CHECKING from jinjarope import inspectfilters, textfilters @@ -13,6 +10,10 @@ if TYPE_CHECKING: + from collections.abc import Generator + import os + import pathlib + import mknodes as mk diff --git a/mknodes/info/pyproject.py b/mknodes/info/pyproject.py index 5b4ae5f3..6616ca69 100644 --- a/mknodes/info/pyproject.py +++ b/mknodes/info/pyproject.py @@ -2,8 +2,7 @@ import collections import functools -import os -from typing import Any +from typing import TYPE_CHECKING, Any import upath @@ -12,6 +11,10 @@ from mknodes.utils import pathhelpers, superdict +if TYPE_CHECKING: + import os + + class PyProject(tomlfile.TomlFile): """Class representing a PyProject config file.""" diff --git a/mknodes/info/yamlfile.py b/mknodes/info/yamlfile.py index 6c84f4c1..ab0b3be9 100644 --- a/mknodes/info/yamlfile.py +++ b/mknodes/info/yamlfile.py @@ -1,6 +1,6 @@ from __future__ import annotations -import os +from typing import TYPE_CHECKING from jinjarope import serializefilters import upath @@ -9,6 +9,10 @@ from mknodes.utils import log, yamlhelpers +if TYPE_CHECKING: + import os + + logger = log.get_logger(__name__) diff --git a/mknodes/jinja/filters.py b/mknodes/jinja/filters.py index 67ec0a9d..9e5b1b8d 100644 --- a/mknodes/jinja/filters.py +++ b/mknodes/jinja/filters.py @@ -6,7 +6,6 @@ from jinja2 import runtime from markupsafe import Markup -from mknodes.jinja import nodeenvironment from mknodes.utils import pathhelpers @@ -16,6 +15,7 @@ import griffe import mknodes as mk + from mknodes.jinja import nodeenvironment @jinja2.pass_environment diff --git a/mknodes/mdlib/markdownhelpers.py b/mknodes/mdlib/markdownhelpers.py index 6b9e3afc..cf47c822 100644 --- a/mknodes/mdlib/markdownhelpers.py +++ b/mknodes/mdlib/markdownhelpers.py @@ -1,10 +1,14 @@ from __future__ import annotations -import markdown +from typing import TYPE_CHECKING from mknodes.utils import log +if TYPE_CHECKING: + import markdown + + logger = log.get_logger(__name__) diff --git a/mknodes/mdlib/mdconverter.py b/mknodes/mdlib/mdconverter.py index b44103be..99d81c41 100644 --- a/mknodes/mdlib/mdconverter.py +++ b/mknodes/mdlib/mdconverter.py @@ -1,13 +1,16 @@ from __future__ import annotations -from collections.abc import Sequence -from typing import Any, Literal +from typing import TYPE_CHECKING, Any, Literal import markdown from mknodes.utils import log +if TYPE_CHECKING: + from collections.abc import Sequence + + logger = log.get_logger(__name__) DEFAULT_EXTS: Sequence[str | markdown.Extension] = [ diff --git a/mknodes/navs/mkdoc.py b/mknodes/navs/mkdoc.py index 358941a2..21d1041e 100644 --- a/mknodes/navs/mkdoc.py +++ b/mknodes/navs/mkdoc.py @@ -1,14 +1,17 @@ from __future__ import annotations -from collections.abc import Sequence -import types -from typing import Any +from typing import TYPE_CHECKING, Any from mknodes.navs import mknav from mknodes.pages import mkclasspage, mkmodulepage from mknodes.utils import classhelpers, log, reprhelpers +if TYPE_CHECKING: + from collections.abc import Sequence + import types + + logger = log.get_logger(__name__) diff --git a/mknodes/navs/mknav.py b/mknodes/navs/mknav.py index 691dad2b..2aae8b07 100644 --- a/mknodes/navs/mknav.py +++ b/mknodes/navs/mknav.py @@ -1,20 +1,21 @@ from __future__ import annotations -from collections.abc import Sequence import inspect import pathlib -import types from typing import TYPE_CHECKING, Any from mknodes.basenodes import mknode -from mknodes.data.datatypes import PageStatusStr from mknodes.navs import navigation, navparser, navrouter from mknodes.pages import metadata as metadata_, mkpage, pagetemplate from mknodes.utils import inspecthelpers, log, reprhelpers if TYPE_CHECKING: + from collections.abc import Sequence + import types + import mknodes as mk + from mknodes.data.datatypes import PageStatusStr logger = log.get_logger(__name__) diff --git a/mknodes/navs/navbuilder.py b/mknodes/navs/navbuilder.py index e2178cc8..01f87fca 100644 --- a/mknodes/navs/navbuilder.py +++ b/mknodes/navs/navbuilder.py @@ -1,8 +1,12 @@ from __future__ import annotations -from collections.abc import Iterable, Mapping import dataclasses import os +from typing import TYPE_CHECKING + + +if TYPE_CHECKING: + from collections.abc import Iterable, Mapping MD_ESCAPE_CHARS = tuple("!#()*+-[\\]_`{}") diff --git a/mknodes/navs/navrouter.py b/mknodes/navs/navrouter.py index 490738fd..86c8782b 100644 --- a/mknodes/navs/navrouter.py +++ b/mknodes/navs/navrouter.py @@ -1,6 +1,5 @@ from __future__ import annotations -from collections.abc import Callable from typing import TYPE_CHECKING, Any from mknodes.basenodes import mklink @@ -10,6 +9,8 @@ if TYPE_CHECKING: + from collections.abc import Callable + NavSubType = mknav.MkNav | mkpage.MkPage | mklink.MkLink logger = log.get_logger(__name__) diff --git a/mknodes/navs/router.py b/mknodes/navs/router.py index b2c0fc51..03ff1d3b 100644 --- a/mknodes/navs/router.py +++ b/mknodes/navs/router.py @@ -1,15 +1,17 @@ from __future__ import annotations -from collections.abc import Callable from typing import TYPE_CHECKING, Any -from mknodes.basenodes import mklink from mknodes.navs import mknav from mknodes.pages import mkpage from mknodes.utils import log if TYPE_CHECKING: + from collections.abc import Callable + + from mknodes.basenodes import mklink + NavSubType = mknav.MkNav | mkpage.MkPage | mklink.MkLink logger = log.get_logger(__name__) diff --git a/mknodes/pages/metadata.py b/mknodes/pages/metadata.py index e43b9000..0f1e213e 100644 --- a/mknodes/pages/metadata.py +++ b/mknodes/pages/metadata.py @@ -1,12 +1,15 @@ from __future__ import annotations import re -from typing import Literal, Self +from typing import TYPE_CHECKING, Literal, Self -from mknodes.data import datatypes from mknodes.utils import yamlhelpers +if TYPE_CHECKING: + from mknodes.data import datatypes + + HEADER = "---\n{options}---\n" HEADER_RE = re.compile(r"\A-{3}\n([\S\s]*)^-{3}(\n|$)", re.MULTILINE) diff --git a/mknodes/pages/mkmodulepage/__init__.py b/mknodes/pages/mkmodulepage/__init__.py index 08da9c1f..38be2c5d 100644 --- a/mknodes/pages/mkmodulepage/__init__.py +++ b/mknodes/pages/mkmodulepage/__init__.py @@ -1,14 +1,16 @@ from __future__ import annotations -import types import pathlib -from typing import Any +from typing import Any, TYPE_CHECKING from mknodes.info import grifferegistry from mknodes.pages import mktemplatepage from mknodes.utils import classhelpers, inspecthelpers, log, reprhelpers +if TYPE_CHECKING: + import types + logger = log.get_logger(__name__) diff --git a/mknodes/pages/mkpage.py b/mknodes/pages/mkpage.py index ea826afd..3393bb25 100644 --- a/mknodes/pages/mkpage.py +++ b/mknodes/pages/mkpage.py @@ -1,20 +1,24 @@ from __future__ import annotations -from collections.abc import Callable import inspect -import os import pathlib -from typing import Any, Self +from typing import TYPE_CHECKING, Any, Self from urllib import parse from jinjarope import textfilters from mknodes.basenodes import mkcontainer, mkfootnotes, mknode, processors -from mknodes.data import datatypes from mknodes.pages import metadata, pagetemplate from mknodes.utils import inspecthelpers, log, pathhelpers, reprhelpers +if TYPE_CHECKING: + from collections.abc import Callable + import os + + from mknodes.data import datatypes + + logger = log.get_logger(__name__) diff --git a/mknodes/templatenodes/mkcallable/__init__.py b/mknodes/templatenodes/mkcallable/__init__.py index 8bf59f5b..e391d2e6 100644 --- a/mknodes/templatenodes/mkcallable/__init__.py +++ b/mknodes/templatenodes/mkcallable/__init__.py @@ -1,6 +1,5 @@ from __future__ import annotations -from collections.abc import Callable from typing import TYPE_CHECKING, Any from mknodes.basenodes import mknode @@ -8,6 +7,7 @@ if TYPE_CHECKING: + from collections.abc import Callable import mknodes as mk diff --git a/mknodes/templatenodes/mkchangelog/__init__.py b/mknodes/templatenodes/mkchangelog/__init__.py index 8ec7d8fc..a5489736 100644 --- a/mknodes/templatenodes/mkchangelog/__init__.py +++ b/mknodes/templatenodes/mkchangelog/__init__.py @@ -3,15 +3,17 @@ import contextlib import functools import io -import os -from typing import Any, Literal +from typing import Any, Literal, TYPE_CHECKING from git_changelog import cli from mknodes.basenodes import mktext from mknodes.utils import helpers, log, resources +if TYPE_CHECKING: + import os + logger = log.get_logger(__name__) diff --git a/mknodes/templatenodes/mkclassdiagram/__init__.py b/mknodes/templatenodes/mkclassdiagram/__init__.py index 3f1b00fe..82797ec5 100644 --- a/mknodes/templatenodes/mkclassdiagram/__init__.py +++ b/mknodes/templatenodes/mkclassdiagram/__init__.py @@ -2,14 +2,16 @@ import itertools -from typing import Any, Literal +from typing import Any, Literal, TYPE_CHECKING from jinjarope import inspectfilters -import griffe from mknodes.basenodes import mkdiagram from mknodes.utils import classhelpers, connector, helpers, reprhelpers +if TYPE_CHECKING: + import griffe + DiagramModeStr = Literal["baseclasses", "subclasses", "mro"] diff --git a/mknodes/templatenodes/mkclasstable/__init__.py b/mknodes/templatenodes/mkclasstable/__init__.py index 43432f7d..b97782d0 100644 --- a/mknodes/templatenodes/mkclasstable/__init__.py +++ b/mknodes/templatenodes/mkclasstable/__init__.py @@ -1,11 +1,14 @@ from __future__ import annotations -from collections.abc import Sequence import griffe from mknodes.info import grifferegistry from mknodes.templatenodes import mktemplatetable from mknodes.utils import classhelpers, log +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from collections.abc import Sequence logger = log.get_logger(__name__) diff --git a/mknodes/templatenodes/mkcommandoutput/__init__.py b/mknodes/templatenodes/mkcommandoutput/__init__.py index b97819f6..9fc454c2 100644 --- a/mknodes/templatenodes/mkcommandoutput/__init__.py +++ b/mknodes/templatenodes/mkcommandoutput/__init__.py @@ -1,12 +1,14 @@ from __future__ import annotations -from collections.abc import Sequence -from typing import Any +from typing import Any, TYPE_CHECKING from mknodes.templatenodes import mktemplate from mknodes.utils import log, resources +if TYPE_CHECKING: + from collections.abc import Sequence + logger = log.get_logger(__name__) diff --git a/mknodes/templatenodes/mkcommentedcode/__init__.py b/mknodes/templatenodes/mkcommentedcode/__init__.py index 2e3e8136..7535c299 100644 --- a/mknodes/templatenodes/mkcommentedcode/__init__.py +++ b/mknodes/templatenodes/mkcommentedcode/__init__.py @@ -1,11 +1,13 @@ from __future__ import annotations -from typing import Any, Literal +from typing import Any, Literal, TYPE_CHECKING from mknodes.templatenodes import mktemplate -from mknodes.data import datatypes from mknodes.utils import inspecthelpers, log +if TYPE_CHECKING: + from mknodes.data import datatypes + logger = log.get_logger(__name__) diff --git a/mknodes/templatenodes/mkconfigsetting/__init__.py b/mknodes/templatenodes/mkconfigsetting/__init__.py index 6ed69f06..afe10b86 100644 --- a/mknodes/templatenodes/mkconfigsetting/__init__.py +++ b/mknodes/templatenodes/mkconfigsetting/__init__.py @@ -1,9 +1,11 @@ from __future__ import annotations -from typing import Any +from typing import Any, TYPE_CHECKING from mknodes.templatenodes import mktemplate -from mknodes.utils import superdict + +if TYPE_CHECKING: + from mknodes.utils import superdict class MkConfigSetting(mktemplate.MkTemplate): diff --git a/mknodes/templatenodes/mkdependencytable/__init__.py b/mknodes/templatenodes/mkdependencytable/__init__.py index a48ac6ad..75af2b62 100644 --- a/mknodes/templatenodes/mkdependencytable/__init__.py +++ b/mknodes/templatenodes/mkdependencytable/__init__.py @@ -1,11 +1,13 @@ from __future__ import annotations -from typing import Literal +from typing import Literal, TYPE_CHECKING from mknodes.templatenodes import mktemplatetable from mknodes.info import packageinfo, packageregistry from mknodes.utils import log -from mknodes.utils.packagehelpers import Dependency + +if TYPE_CHECKING: + from mknodes.utils.packagehelpers import Dependency logger = log.get_logger(__name__) diff --git a/mknodes/templatenodes/mkdevtools/__init__.py b/mknodes/templatenodes/mkdevtools/__init__.py index 692c35c3..6b3884b2 100644 --- a/mknodes/templatenodes/mkdevtools/__init__.py +++ b/mknodes/templatenodes/mkdevtools/__init__.py @@ -1,11 +1,13 @@ from __future__ import annotations -from typing import Any +from typing import Any, TYPE_CHECKING from mknodes.templatenodes import mktemplate -from mknodes.data import tools from mknodes.utils import log +if TYPE_CHECKING: + from mknodes.data import tools + logger = log.get_logger(__name__) diff --git a/mknodes/templatenodes/mkmoduletable/__init__.py b/mknodes/templatenodes/mkmoduletable/__init__.py index b3552eb4..464a530f 100644 --- a/mknodes/templatenodes/mkmoduletable/__init__.py +++ b/mknodes/templatenodes/mkmoduletable/__init__.py @@ -1,11 +1,14 @@ from __future__ import annotations -from collections.abc import Sequence -import types from mknodes.info import grifferegistry from mknodes.templatenodes import mktemplatetable from mknodes.utils import classhelpers, helpers, log +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + import types + from collections.abc import Sequence logger = log.get_logger(__name__) diff --git a/mknodes/templatenodes/mkpydeps/__init__.py b/mknodes/templatenodes/mkpydeps/__init__.py index 87e5c28c..40c5c415 100644 --- a/mknodes/templatenodes/mkpydeps/__init__.py +++ b/mknodes/templatenodes/mkpydeps/__init__.py @@ -1,15 +1,17 @@ from __future__ import annotations -from collections.abc import Mapping import functools import os import types -from typing import Any +from typing import Any, TYPE_CHECKING from mknodes.basenodes import mknode from mknodes.utils import inspecthelpers, log, resources +if TYPE_CHECKING: + from collections.abc import Mapping + logger = log.get_logger(__name__) diff --git a/mknodes/templatenodes/mkreprrawrendered/__init__.py b/mknodes/templatenodes/mkreprrawrendered/__init__.py index 3196dbc4..abcdef30 100644 --- a/mknodes/templatenodes/mkreprrawrendered/__init__.py +++ b/mknodes/templatenodes/mkreprrawrendered/__init__.py @@ -1,9 +1,11 @@ from __future__ import annotations -from typing import Any +from typing import Any, TYPE_CHECKING from mknodes.templatenodes import mktemplate -from mknodes.basenodes import mknode + +if TYPE_CHECKING: + from mknodes.basenodes import mknode class MkReprRawRendered(mktemplate.MkTemplate): diff --git a/mknodes/templatenodes/mkshields/__init__.py b/mknodes/templatenodes/mkshields/__init__.py index fcf76b25..c1854aa4 100644 --- a/mknodes/templatenodes/mkshields/__init__.py +++ b/mknodes/templatenodes/mkshields/__init__.py @@ -1,12 +1,14 @@ from __future__ import annotations -from collections.abc import Sequence -from typing import Any +from typing import Any, TYPE_CHECKING from mknodes.basenodes import mkcontainer, mkimage, mknode from mknodes.data import badges from mknodes.utils import log +if TYPE_CHECKING: + from collections.abc import Sequence + logger = log.get_logger(__name__) diff --git a/mknodes/templatenodes/mktreeview/__init__.py b/mknodes/templatenodes/mktreeview/__init__.py index 9b6cfb54..600e8fb1 100644 --- a/mknodes/templatenodes/mktreeview/__init__.py +++ b/mknodes/templatenodes/mktreeview/__init__.py @@ -1,16 +1,18 @@ from __future__ import annotations -from collections.abc import Callable import os import upath -from typing import Any +from typing import Any, TYPE_CHECKING from mknodes import treelib from mknodes.basenodes import mkcode, mknode -from mknodes.data import treestyles from mknodes.utils import log +if TYPE_CHECKING: + from mknodes.data import treestyles + from collections.abc import Callable + logger = log.get_logger(__name__) diff --git a/mknodes/theme/materialtheme/__init__.py b/mknodes/theme/materialtheme/__init__.py index 3b8dff0c..29bfe6a6 100644 --- a/mknodes/theme/materialtheme/__init__.py +++ b/mknodes/theme/materialtheme/__init__.py @@ -1,16 +1,18 @@ from __future__ import annotations -from collections.abc import MutableMapping import dataclasses import functools -from typing import Any, Literal +from typing import Any, Literal, TYPE_CHECKING -from mknodes.data import datatypes from mknodes.theme import colortheme, theme from mknodes.theme.materialtheme import palette from mknodes.utils import color as col, icons, log, reprhelpers +if TYPE_CHECKING: + from mknodes.data import datatypes + from collections.abc import MutableMapping + logger = log.get_logger(__name__) diff --git a/mknodes/theme/mkgitblog.py b/mknodes/theme/mkgitblog.py index c82d8ab8..dcc3ede5 100644 --- a/mknodes/theme/mkgitblog.py +++ b/mknodes/theme/mkgitblog.py @@ -1,9 +1,8 @@ from __future__ import annotations import dataclasses -import datetime import json -import os +from typing import TYPE_CHECKING import dateutil.parser @@ -11,6 +10,11 @@ from mknodes.utils import downloadhelpers +if TYPE_CHECKING: + import datetime + import os + + @dataclasses.dataclass(frozen=True) class Commit: """Class representing a single Git commit.""" diff --git a/mknodes/theme/theme.py b/mknodes/theme/theme.py index 95e6e7f9..14f757ed 100644 --- a/mknodes/theme/theme.py +++ b/mknodes/theme/theme.py @@ -1,7 +1,6 @@ from __future__ import annotations -from collections.abc import MutableMapping -from typing import Any +from typing import TYPE_CHECKING, Any import jinjarope @@ -11,6 +10,10 @@ from mknodes.utils import color, icons, log, reprhelpers, resources +if TYPE_CHECKING: + from collections.abc import MutableMapping + + logger = log.get_logger(__name__) diff --git a/mknodes/treelib/filetreenode.py b/mknodes/treelib/filetreenode.py index d0d8831a..4e9521a5 100644 --- a/mknodes/treelib/filetreenode.py +++ b/mknodes/treelib/filetreenode.py @@ -1,14 +1,18 @@ from __future__ import annotations -from collections.abc import Callable -import pathlib -from typing import Any, Self, cast +from typing import TYPE_CHECKING, Any, Self, cast -from mknodes.data import treestyles from mknodes.treelib import node from mknodes.utils import log +if TYPE_CHECKING: + from collections.abc import Callable + import pathlib + + from mknodes.data import treestyles + + logger = log.get_logger(__name__) diff --git a/mknodes/treelib/node.py b/mknodes/treelib/node.py index fe0663ba..417fa142 100644 --- a/mknodes/treelib/node.py +++ b/mknodes/treelib/node.py @@ -1,14 +1,17 @@ from __future__ import annotations -from collections.abc import Callable, Iterable, Iterator, Sequence import copy -import types -from typing import Self +from typing import TYPE_CHECKING, Self from mknodes.data import treestyles from mknodes.utils import log, reprhelpers +if TYPE_CHECKING: + from collections.abc import Callable, Iterable, Iterator, Sequence + import types + + logger = log.get_logger(__name__) diff --git a/mknodes/utils/classhelpers.py b/mknodes/utils/classhelpers.py index c868499e..b725d456 100644 --- a/mknodes/utils/classhelpers.py +++ b/mknodes/utils/classhelpers.py @@ -6,7 +6,6 @@ import importlib import importlib.util import inspect -import os import pathlib import sys import types @@ -17,6 +16,10 @@ from mknodes.utils import log +if typing.TYPE_CHECKING: + import os + + T = typing.TypeVar("T", bound=type) diff --git a/mknodes/utils/classproperty.py b/mknodes/utils/classproperty.py index 561ab5c3..9fe669f7 100644 --- a/mknodes/utils/classproperty.py +++ b/mknodes/utils/classproperty.py @@ -1,6 +1,10 @@ from __future__ import annotations -from collections.abc import Callable +from typing import TYPE_CHECKING + + +if TYPE_CHECKING: + from collections.abc import Callable class ClassPropertyDescriptor: diff --git a/mknodes/utils/color.py b/mknodes/utils/color.py index d36201b8..7e8973db 100644 --- a/mknodes/utils/color.py +++ b/mknodes/utils/color.py @@ -1,11 +1,14 @@ from __future__ import annotations -from collections.abc import Sequence -from typing import Any +from typing import TYPE_CHECKING, Any import coloraide +if TYPE_CHECKING: + from collections.abc import Sequence + + RGB_TUPLE_LEN = 3 ALPHA_DEFAULT = 1.0 diff --git a/mknodes/utils/connector.py b/mknodes/utils/connector.py index 4c906602..15d88431 100644 --- a/mknodes/utils/connector.py +++ b/mknodes/utils/connector.py @@ -1,11 +1,15 @@ from __future__ import annotations -from collections.abc import Hashable import textwrap +from typing import TYPE_CHECKING from mknodes.utils import log +if TYPE_CHECKING: + from collections.abc import Hashable + + logger = log.get_logger(__name__) diff --git a/mknodes/utils/helpers.py b/mknodes/utils/helpers.py index 0d6ba09f..c74bb761 100644 --- a/mknodes/utils/helpers.py +++ b/mknodes/utils/helpers.py @@ -1,12 +1,15 @@ from __future__ import annotations -from collections.abc import Callable, Iterable import itertools -from typing import ParamSpec, TypeVar +from typing import TYPE_CHECKING, ParamSpec, TypeVar from mknodes.utils import log +if TYPE_CHECKING: + from collections.abc import Callable, Iterable + + logger = log.get_logger(__name__) diff --git a/mknodes/utils/icons.py b/mknodes/utils/icons.py index 9d0cdc78..efe15480 100644 --- a/mknodes/utils/icons.py +++ b/mknodes/utils/icons.py @@ -1,15 +1,18 @@ from __future__ import annotations -from collections.abc import Sequence import functools -from typing import Any, Literal +from typing import TYPE_CHECKING, Any, Literal import xml.etree.ElementTree as etree -import markdown - from mknodes import paths +if TYPE_CHECKING: + from collections.abc import Sequence + + import markdown + + PYCONIFY_TO_PREFIXES = { "mdi": "material", "simple-icons": "simple", diff --git a/mknodes/utils/inspecthelpers.py b/mknodes/utils/inspecthelpers.py index c9e43b1b..a456d975 100644 --- a/mknodes/utils/inspecthelpers.py +++ b/mknodes/utils/inspecthelpers.py @@ -3,13 +3,17 @@ import dataclasses import functools import inspect -import pathlib -import types +from typing import TYPE_CHECKING import griffe from jinjarope import inspectfilters -from mknodes.data import datatypes + +if TYPE_CHECKING: + import pathlib + import types + + from mknodes.data import datatypes def iter_code_sections(code_string: str, start_line: int | None = None): diff --git a/mknodes/utils/inventorymanager.py b/mknodes/utils/inventorymanager.py index 486c55e8..e98933a2 100644 --- a/mknodes/utils/inventorymanager.py +++ b/mknodes/utils/inventorymanager.py @@ -8,13 +8,16 @@ import pathlib import posixpath import re -import types -from typing import BinaryIO, Self +from typing import TYPE_CHECKING, BinaryIO, Self import zlib from mknodes.utils import downloadhelpers, helpers, log +if TYPE_CHECKING: + import types + + logger = log.get_logger(__name__) diff --git a/mknodes/utils/packagehelpers.py b/mknodes/utils/packagehelpers.py index 55256895..73f3fbf5 100644 --- a/mknodes/utils/packagehelpers.py +++ b/mknodes/utils/packagehelpers.py @@ -1,13 +1,11 @@ from __future__ import annotations import collections -from collections.abc import Mapping import dataclasses import functools import importlib from importlib import metadata -import types -from typing import Any +from typing import TYPE_CHECKING, Any from packaging.markers import Marker from packaging.requirements import Requirement @@ -16,6 +14,11 @@ from mknodes.utils import log +if TYPE_CHECKING: + from collections.abc import Mapping + import types + + logger = log.get_logger(__name__) diff --git a/mknodes/utils/pathhelpers.py b/mknodes/utils/pathhelpers.py index 80507069..0e06993d 100644 --- a/mknodes/utils/pathhelpers.py +++ b/mknodes/utils/pathhelpers.py @@ -1,11 +1,11 @@ from __future__ import annotations -from collections.abc import Mapping import functools import os import pathlib import posixpath import shutil +from typing import TYPE_CHECKING import upath from upath import core, registry @@ -13,6 +13,10 @@ from mknodes.utils import log +if TYPE_CHECKING: + from collections.abc import Mapping + + logger = log.get_logger(__name__) diff --git a/mknodes/utils/reprhelpers.py b/mknodes/utils/reprhelpers.py index 75fd795b..1be4d4ea 100644 --- a/mknodes/utils/reprhelpers.py +++ b/mknodes/utils/reprhelpers.py @@ -2,14 +2,17 @@ import os import reprlib -from typing import Any +from typing import TYPE_CHECKING, Any from jinjarope import inspectfilters, textfilters, utils -from mknodes.data import datatypes from mknodes.utils import log +if TYPE_CHECKING: + from mknodes.data import datatypes + + logger = log.get_logger(__name__) diff --git a/mknodes/utils/superdict.py b/mknodes/utils/superdict.py index 7de55f86..83b6c06f 100644 --- a/mknodes/utils/superdict.py +++ b/mknodes/utils/superdict.py @@ -2,14 +2,17 @@ from abc import ABCMeta from collections.abc import Iterator, MutableMapping -import os -from typing import Any, Literal, Self, TypeVar +from typing import TYPE_CHECKING, Any, Literal, Self, TypeVar from jinjarope import serializefilters from mknodes.utils import pathhelpers, reprhelpers +if TYPE_CHECKING: + import os + + MarkupTypeStr = Literal["yaml", "json", "toml"] diff --git a/pyproject.toml b/pyproject.toml index 69df86f4..9094273a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -218,7 +218,7 @@ select = [ # "TD", # flake8-todos "T10", # flake8-debugger # "T20", # flake8-print - # "TCH", # flake8-type-checking + "TCH", # flake8-type-checking "TID", # flake8-tidy-imports "TRY", # tryceratops "UP", # PyUpgrade