Skip to content

Commit a37e655

Browse files
authored
Merge pull request #171 from timvink/fix_for_generated_files
Fix for generated files when using parallel proc
2 parents 6caf88c + 232fe7a commit a37e655

File tree

5 files changed

+43
-4
lines changed

5 files changed

+43
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.4.1"
1+
__version__ = "1.4.2"

src/mkdocs_git_revision_date_localized_plugin/plugin.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,21 @@ def parallel_compute_commit_timestamps(self, files, original_source: Optional[Di
149149
pool = multiprocessing.Pool(processes=min(10, multiprocessing.cpu_count()))
150150
results = []
151151
for f in files:
152-
if f.is_documentation_page():
152+
print(f.abs_src_path)
153+
if not f.is_documentation_page():
154+
continue
155+
elif getattr(f, "generated_by", None):
156+
continue
157+
elif f.abs_src_path is None:
158+
continue
159+
elif exclude(f.src_path, self.config.get("exclude", [])):
160+
continue
161+
else:
153162
abs_src_path = f.abs_src_path
154-
# Support plugins like monorep that might have moved the files from the original source that is under git
163+
# Support plugins like monorepo that might have moved the files from the original source that is under git
155164
if original_source and abs_src_path in original_source:
156165
abs_src_path = original_source[abs_src_path]
166+
157167
assert Path(abs_src_path).exists()
158168
abs_src_path = str(Path(abs_src_path).absolute())
159169
result = pool.apply_async(self.util.get_git_commit_timestamp, args=(abs_src_path, is_first_commit))
@@ -182,11 +192,12 @@ def on_files(self, files: Files, config: MkDocsConfig):
182192

183193
try:
184194
if not self.last_revision_commits:
185-
self.parallel_compute_commit_timestamps(files=files, original_source=original_source, is_first_commit=False)
195+
self.parallel_compute_commit_timestamps(files=files, original_source=original_source, is_first_commit=False)
186196
if not self.created_commits:
187197
self.parallel_compute_commit_timestamps(files=files, original_source=original_source, is_first_commit=True)
188198
except Exception as e:
189199
logging.warning(f"Parallel processing failed: {str(e)}.\n To fall back to serial processing, use 'enable_parallel_processing: False' setting.")
200+
raise e
190201

191202

192203
def on_page_markdown(self, markdown: str, page: Page, config: config_options.Config, files, **kwargs) -> str:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# for testing with generated files. See mkdocs_plugin_genfiles.yml
2+
import mkdocs_gen_files
3+
4+
with mkdocs_gen_files.open("foo.md", "w") as f:
5+
print("Bar, world!", file=f)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
site_name: test gitrevisiondatelocalized_plugin
2+
use_directory_urls: true
3+
4+
plugins:
5+
- search
6+
- gen-files:
7+
scripts:
8+
- gen_files.py # or any other name or path
9+
- git-revision-date-localized

tests/test_builds.py

+14
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,10 @@ def setup_clean_mkdocs_folder(mkdocs_yml_path, output_path):
119119
else:
120120
shutil.copytree("tests/fixtures/basic_project/docs", str(testproject_path / "docs"))
121121

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

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

@@ -694,3 +696,15 @@ def test_monorepo_compat_reverse_order(tmp_path):
694696
setup_commit_history(testproject_path)
695697
result = build_docs_setup(testproject_path)
696698
assert result.exit_code == 0, f"'mkdocs build' command failed with:\n\n{result.stdout}"
699+
700+
701+
def test_genfiles_plugin(tmp_path):
702+
testproject_path = setup_clean_mkdocs_folder("tests/fixtures/basic_project/mkdocs_plugin_genfiles.yml", tmp_path)
703+
setup_commit_history(testproject_path)
704+
705+
result = build_docs_setup(testproject_path)
706+
assert result.exit_code == 0, f"'mkdocs build' command failed with:\n\n{result.stdout}"
707+
708+
page_with_tag = testproject_path / "site/foo/index.html"
709+
contents = page_with_tag.read_text(encoding="utf8")
710+
assert "Bar, world!" in contents

0 commit comments

Comments
 (0)