diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 668e474..a17424b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ default_install_hook_types: - pre-commit -default_stages: [commit, push] +default_stages: [pre-commit, pre-push] repos: - repo: local @@ -14,7 +14,7 @@ repos: # files: .pre-commit-config.yaml - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v5.0.0 hooks: - id: check-symlinks - id: trailing-whitespace @@ -33,7 +33,7 @@ repos: - id: check-vcs-permalinks - repo: https://github.com/gitleaks/gitleaks - rev: v8.18.3 + rev: v8.26.0 hooks: - id: gitleaks diff --git a/mkdocs_exclude_unused_files/plugin.py b/mkdocs_exclude_unused_files/plugin.py index c99fe90..9d0cff7 100644 --- a/mkdocs_exclude_unused_files/plugin.py +++ b/mkdocs_exclude_unused_files/plugin.py @@ -15,6 +15,45 @@ log = logging.getLogger(f"mkdocs.plugins.{__name__}") +DEFAULT_FILES_TO_CHECK: list[str] = [ + "png", + "jpg", + "jpeg", + "gif", + "pdf", + "ico", + "drawio", + "tif", + "tiff", + "zip", + "rar", + "tar.gz", + "ogg", + "mp3", + "mp4", + "vtt ", + "ogv", + "mov", + "svg", + "pot", + "potx", + "ppsx", + "ppt", + "pptx", + "xlt", + "xltx", + "xls", + "xlsx", + "doc", + "docx", + "dot", + "dotx", + "vst", + "vstx", + "vsd", + "vsdx", +] + class ExcludeUnusedFilesPluginConfig(mkdocs.config.base.Config): enabled = mkdocs.config.config_options.Type(bool, default=True) @@ -32,59 +71,28 @@ class ExcludeUnusedFilesPluginConfig(mkdocs.config.base.Config): class ExcludeUnusedFilesPlugin(BasePlugin[ExcludeUnusedFilesPluginConfig]): - asset_files: Set[str] = set() - file_types_to_check = [ - "png", - "jpg", - "jpeg", - "gif", - "pdf", - "ico", - "drawio", - "tif", - "tiff", - "zip", - "rar", - "tar.gz", - "ogg", - "mp3", - "mp4", - "vtt ", - "ogv", - "mov", - "svg", - "pot", - "potx", - "ppsx", - "ppt", - "pptx", - "xlt", - "xltx", - "xls", - "xlsx", - "doc", - "docx", - "dot", - "dotx", - "vst", - "vstx", - "vsd", - "vsdx", - ] + def __init__(self): + self.asset_files: Set[str] = set() + self.file_types_to_check: list[str] = DEFAULT_FILES_TO_CHECK + + @mkdocs.plugins.event_priority(-100) + def on_startup(self, command, dirty) -> None: + self.mkdocs_command: str = command @mkdocs.plugins.event_priority(-100) - def on_startup(self, *, command, dirty) -> None: - self.mkdocs_command = command - self.is_enabled = self.config.enabled + def on_config(self, config: MkDocsConfig) -> MkDocsConfig: + self.is_enabled: bool = self.config.enabled + # Early exit if plugin is not enabled if not self.is_enabled: log.debug("exclude-unused-files plugin disabled") - return + return config + # Disable plugin when the documentation is served, i.e., "mkdocs serve" is used - if command == "serve" and not self.config.enabled_on_serve: + if self.mkdocs_command == "serve" and not self.config.enabled_on_serve: log.debug("exclude-unused-files plugin disabled while MkDocs is running in 'serve' mode.") self.is_enabled = False - return + return config if self.is_enabled: if self.config.file_types_override_mode == "append" and self.config.file_types_to_check != []: @@ -101,6 +109,8 @@ def on_startup(self, *, command, dirty) -> None: self.file_types_to_check = [*set(self.file_types_to_check)] log.debug("final file_types_to_check: %s", ", ".join(self.file_types_to_check)) + return config + @mkdocs.plugins.event_priority(-100) def on_files(self, files: Files, config: MkDocsConfig) -> Optional[Files]: if not self.is_enabled: diff --git a/pyproject.toml b/pyproject.toml index c850bbe..2ce1ace 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,7 +37,7 @@ bandit = "^1.7.7" types-beautifulsoup4 = "^4.12.0.20240106" mkdocs-material = "^9.5.5" -[tool.poetry.plugins."poetry-plugin-up"] +# [tool.poetry.plugins."poetry-plugin-up"] # https://github.com/MousaZeidBaker/poetry-plugin-up#usage [tool.poetry-dynamic-versioning]