Fixed info plugin to gather all files recursively

This commit is contained in:
Kamil Krzyśków 2024-02-16 19:48:19 +01:00 committed by Martin Donath
parent 15f15068d9
commit 712bc1c137
2 changed files with 8 additions and 16 deletions

View File

@ -30,7 +30,6 @@ from importlib.metadata import distributions, version
from io import BytesIO from io import BytesIO
from markdown.extensions.toc import slugify from markdown.extensions.toc import slugify
from mkdocs.plugins import BasePlugin, event_priority from mkdocs.plugins import BasePlugin, event_priority
from mkdocs.structure.files import get_files
from mkdocs.utils import get_theme_dir from mkdocs.utils import get_theme_dir
from zipfile import ZipFile, ZIP_DEFLATED from zipfile import ZipFile, ZIP_DEFLATED
@ -115,15 +114,12 @@ class InfoPlugin(BasePlugin[InfoConfig]):
# Create self-contained example from project # Create self-contained example from project
files: list[str] = [] files: list[str] = []
with ZipFile(archive, "a", ZIP_DEFLATED, False) as f: with ZipFile(archive, "a", ZIP_DEFLATED, False) as f:
for path in ["mkdocs.yml", "requirements.txt"]: for abs_root, dirnames, filenames in os.walk(os.getcwd()):
if os.path.isfile(path): for name in filenames:
path = os.path.join(abs_root, name)
path = os.path.relpath(path, os.path.curdir)
f.write(path, os.path.join(example, path)) f.write(path, os.path.join(example, path))
# Append all files visible to MkDocs
for file in get_files(config):
path = os.path.relpath(file.abs_src_path, os.path.curdir)
f.write(path, os.path.join(example, path))
# Add information on installed packages # Add information on installed packages
f.writestr( f.writestr(
os.path.join(example, "requirements.lock.txt"), os.path.join(example, "requirements.lock.txt"),

View File

@ -30,7 +30,6 @@ from importlib.metadata import distributions, version
from io import BytesIO from io import BytesIO
from markdown.extensions.toc import slugify from markdown.extensions.toc import slugify
from mkdocs.plugins import BasePlugin, event_priority from mkdocs.plugins import BasePlugin, event_priority
from mkdocs.structure.files import get_files
from mkdocs.utils import get_theme_dir from mkdocs.utils import get_theme_dir
from zipfile import ZipFile, ZIP_DEFLATED from zipfile import ZipFile, ZIP_DEFLATED
@ -115,15 +114,12 @@ class InfoPlugin(BasePlugin[InfoConfig]):
# Create self-contained example from project # Create self-contained example from project
files: list[str] = [] files: list[str] = []
with ZipFile(archive, "a", ZIP_DEFLATED, False) as f: with ZipFile(archive, "a", ZIP_DEFLATED, False) as f:
for path in ["mkdocs.yml", "requirements.txt"]: for abs_root, dirnames, filenames in os.walk(os.getcwd()):
if os.path.isfile(path): for name in filenames:
path = os.path.join(abs_root, name)
path = os.path.relpath(path, os.path.curdir)
f.write(path, os.path.join(example, path)) f.write(path, os.path.join(example, path))
# Append all files visible to MkDocs
for file in get_files(config):
path = os.path.relpath(file.abs_src_path, os.path.curdir)
f.write(path, os.path.join(example, path))
# Add information on installed packages # Add information on installed packages
f.writestr( f.writestr(
os.path.join(example, "requirements.lock.txt"), os.path.join(example, "requirements.lock.txt"),