From 7baa03225e6c34cc85d17f79c47e42eb2c2e359e Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Sat, 27 Apr 2024 12:07:14 +0200 Subject: [PATCH] Fix types and compatibility with MkDocs 1.6 --- mkdocs_gen_files/editor.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mkdocs_gen_files/editor.py b/mkdocs_gen_files/editor.py index 7bdf25f..f62594c 100644 --- a/mkdocs_gen_files/editor.py +++ b/mkdocs_gen_files/editor.py @@ -49,6 +49,7 @@ def _get_file(self, name: str, new: bool = False) -> str: use_directory_urls=self.config.use_directory_urls, ) new_f.generated_by = "mkdocs-gen-files" # type: ignore[attr-defined] + assert new_f.abs_src_path is not None normname = pathlib.PurePath(name).as_posix() if new or normname not in self._files: @@ -62,7 +63,10 @@ def _get_file(self, name: str, new: bool = False) -> str: os.makedirs(os.path.dirname(new_f.abs_src_path), exist_ok=True) self._files[normname] = new_f self.edit_paths.setdefault(normname, None) - shutil.copyfile(f.abs_src_path, new_f.abs_src_path) + if f.abs_src_path: + shutil.copyfile(f.abs_src_path, new_f.abs_src_path) + else: # MkDocs 1.6+ + pathlib.Path(new_f.abs_src_path).write_bytes(f.content_bytes) return new_f.abs_src_path return f.abs_src_path