Skip to content

Commit

Permalink
Fix keep docs dir (#89)
Browse files Browse the repository at this point in the history
* Make the global keep_docs_dir have an effect

Previously this value didn't matter, only the setting on each import had
an effect. Now we use the global value (False by default) unless a
repo overrides the value with either True or False.

* Extend keep_docs_dir test

Now we test all possible combinations of settings instead
  • Loading branch information
Sebastian-0 authored Mar 29, 2023
1 parent b5fd5c0 commit bec2b1f
Show file tree
Hide file tree
Showing 6 changed files with 333 additions and 291 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.6.1

### Prs in Release

- [Fix keep docs dir](https://github.com/jdoiro3/mkdocs-multirepo-plugin/pull/89)

## 0.6.0

### Prs in Release
Expand Down
2 changes: 1 addition & 1 deletion mkdocs_multirepo_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def handle_repos_import(self, config: Config, repos: List[RepoConfig]) -> Config
or derived_edit_uri,
multi_docs=bool(import_stmt.get("multi_docs", False)),
extra_imports=import_stmt.get("extra_imports", []),
keep_docs_dir=import_stmt.get("keep_docs_dir", False),
keep_docs_dir=import_stmt.get("keep_docs_dir"),
)
)
asyncio_run(batch_import(docs_repo_objs))
Expand Down
19 changes: 12 additions & 7 deletions mkdocs_multirepo_plugin/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import shutil
import time
from pathlib import Path
from typing import Callable, Dict, List, Tuple, Union
from typing import Callable, Dict, List, Optional, Tuple, Union

from mkdocs.config import Config
from mkdocs.structure.files import File, Files, _filter_paths, _sort_files
Expand Down Expand Up @@ -149,7 +149,7 @@ def get_import_stmts(
multi_docs=bool(import_stmt.get("multi_docs", False)),
config=import_stmt.get("config", "mkdocs.yml"),
extra_imports=import_stmt.get("extra_imports", []),
keep_docs_dir=import_stmt.get("keep_docs_dir", False),
keep_docs_dir=import_stmt.get("keep_docs_dir"),
)
imports.append(NavImport(section, nav[index], repo))
path_to_section.pop()
Expand Down Expand Up @@ -231,6 +231,9 @@ class DocsRepo(Repo):
multi_docs (bool): If this is True, it means the repo has multiple docs directories that the user
wants to be pulled into the site.
extra_imports (list): Extra directories to import along with the docs.
keep_docs_dir (bool): If `True` the docs directory will be kept when importing docs from this repo,
if `False` it will be removed, and if `None` (default) it will fall back to
the global setting.
"""

def _fix_edit_uri(self, edit_uri: str) -> str:
Expand Down Expand Up @@ -259,7 +262,7 @@ def __init__(
multi_docs: bool = False,
config: str = "mkdocs.yml",
extra_imports: List[str] = None,
keep_docs_dir: bool = False,
keep_docs_dir: Optional[bool] = None,
*args,
**kwargs,
):
Expand Down Expand Up @@ -297,8 +300,10 @@ def __eq__(self, other):
def name_length(self):
return len(Path(self.name).parts)

def keep_docs_dir(self, global_config_val: bool = False):
return self._keep_docs_dir and (self._keep_docs_dir or global_config_val)
def keep_docs_dir(self, global_keep_docs_dir: bool = False):
if self._keep_docs_dir is None:
return global_keep_docs_dir
return self._keep_docs_dir

def get_edit_url(
self, src_path, keep_docs_dir: bool = False, nav_repos: bool = False
Expand All @@ -323,7 +328,7 @@ def get_edit_url(
]
elif (
is_extra_import
or self.keep_docs_dir(global_config_val=keep_docs_dir)
or self.keep_docs_dir(global_keep_docs_dir=keep_docs_dir)
or nav_repos
):
url_parts = [self.url, self.edit_uri, src_path]
Expand Down Expand Up @@ -377,7 +382,7 @@ async def import_docs(
self.transform_docs_dir()
else:
await self.sparse_clone([self.docs_dir, self.config] + self.extra_imports)
if not self.keep_docs_dir(global_config_val=keep_docs_dir):
if not self.keep_docs_dir(global_keep_docs_dir=keep_docs_dir):
await execute_bash_script(
"mv_docs_up.sh",
[self.docs_dir.replace("/*", "")],
Expand Down
Loading

0 comments on commit bec2b1f

Please sign in to comment.