Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/mkdocs_git_revision_date_localized_plugin/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.4.1"
__version__ = "1.4.2"
17 changes: 14 additions & 3 deletions src/mkdocs_git_revision_date_localized_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,21 @@ def parallel_compute_commit_timestamps(self, files, original_source: Optional[Di
pool = multiprocessing.Pool(processes=min(10, multiprocessing.cpu_count()))
results = []
for f in files:
if f.is_documentation_page():
print(f.abs_src_path)
if not f.is_documentation_page():
continue
elif getattr(f, "generated_by", None):
continue
elif f.abs_src_path is None:
continue
elif exclude(f.src_path, self.config.get("exclude", [])):
continue
else:
abs_src_path = f.abs_src_path
# Support plugins like monorep that might have moved the files from the original source that is under git
# Support plugins like monorepo that might have moved the files from the original source that is under git
if original_source and abs_src_path in original_source:
abs_src_path = original_source[abs_src_path]

assert Path(abs_src_path).exists()
abs_src_path = str(Path(abs_src_path).absolute())
result = pool.apply_async(self.util.get_git_commit_timestamp, args=(abs_src_path, is_first_commit))
Expand Down Expand Up @@ -182,11 +192,12 @@ def on_files(self, files: Files, config: MkDocsConfig):

try:
if not self.last_revision_commits:
self.parallel_compute_commit_timestamps(files=files, original_source=original_source, is_first_commit=False)
self.parallel_compute_commit_timestamps(files=files, original_source=original_source, is_first_commit=False)
if not self.created_commits:
self.parallel_compute_commit_timestamps(files=files, original_source=original_source, is_first_commit=True)
except Exception as e:
logging.warning(f"Parallel processing failed: {str(e)}.\n To fall back to serial processing, use 'enable_parallel_processing: False' setting.")
raise e


def on_page_markdown(self, markdown: str, page: Page, config: config_options.Config, files, **kwargs) -> str:
Expand Down
5 changes: 5 additions & 0 deletions tests/fixtures/basic_project/gen_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# for testing with generated files. See mkdocs_plugin_genfiles.yml
import mkdocs_gen_files

with mkdocs_gen_files.open("foo.md", "w") as f:
print("Bar, world!", file=f)
9 changes: 9 additions & 0 deletions tests/fixtures/basic_project/mkdocs_plugin_genfiles.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
site_name: test gitrevisiondatelocalized_plugin
use_directory_urls: true

plugins:
- search
- gen-files:
scripts:
- gen_files.py # or any other name or path
- git-revision-date-localized
14 changes: 14 additions & 0 deletions tests/test_builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,10 @@ def setup_clean_mkdocs_folder(mkdocs_yml_path, output_path):
else:
shutil.copytree("tests/fixtures/basic_project/docs", str(testproject_path / "docs"))

shutil.copyfile("tests/fixtures/basic_project/gen_files.py", str(testproject_path / "gen_files.py"))
shutil.copyfile(mkdocs_yml_path, str(testproject_path / "mkdocs.yml"))


if "gen-files" in mkdocs_yml_path:
shutil.copyfile(str(Path(mkdocs_yml_path).parent / "gen_pages.py"), str(testproject_path / "gen_pages.py"))

Expand Down Expand Up @@ -694,3 +696,15 @@ def test_monorepo_compat_reverse_order(tmp_path):
setup_commit_history(testproject_path)
result = build_docs_setup(testproject_path)
assert result.exit_code == 0, f"'mkdocs build' command failed with:\n\n{result.stdout}"


def test_genfiles_plugin(tmp_path):
testproject_path = setup_clean_mkdocs_folder("tests/fixtures/basic_project/mkdocs_plugin_genfiles.yml", tmp_path)
setup_commit_history(testproject_path)

result = build_docs_setup(testproject_path)
assert result.exit_code == 0, f"'mkdocs build' command failed with:\n\n{result.stdout}"

page_with_tag = testproject_path / "site/foo/index.html"
contents = page_with_tag.read_text(encoding="utf8")
assert "Bar, world!" in contents