Skip to content

fix: Class attributes #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
default_install_hook_types:
- pre-commit

default_stages: [commit, push]
default_stages: [pre-commit, pre-push]

repos:
- repo: local
Expand All @@ -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
Expand All @@ -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

Expand Down
100 changes: 55 additions & 45 deletions mkdocs_exclude_unused_files/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 != []:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down