Skip to content

Commit

Permalink
Preserve leading slash; deduplicate recursion warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
oprypin committed May 24, 2021
1 parent 1b02eb7 commit 4391a9c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
6 changes: 4 additions & 2 deletions mkdocs_literate_nav/parser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import copy
import functools
import itertools
import logging
import posixpath
Expand Down Expand Up @@ -36,6 +37,7 @@ def __init__(
self.globber = globber
self.implicit_index = implicit_index
self.seen_items = set()
self._warn = functools.lru_cache()(log.warning)

def markdown_to_nav(self, roots: Tuple[str, ...] = (".",)) -> Nav:
root = roots[0]
Expand Down Expand Up @@ -102,7 +104,7 @@ def _list_element_to_nav(
return result

def _maybe_directory_wildcard(self, root: str, link: str) -> Union["Wildcard", str]:
abs_link = posixpath.normpath(posixpath.join(root, link).lstrip("/"))
abs_link = posixpath.normpath(posixpath.join(root, link))
self.seen_items.add(abs_link)
if link.endswith("/") and self.globber.isdir(abs_link):
return DirectoryWildcard(root, link)
Expand All @@ -112,7 +114,7 @@ def _resolve_wildcards(self, nav, roots: RootStack = (".",)) -> Nav:
def can_recurse(new_root):
if new_root in roots:
rec = " -> ".join(repr(r) for r in reversed((new_root,) + roots))
log.warning(f"Disallowing recursion {rec}")
self._warn(f"Disallowing recursion {rec}")
return False
return True

Expand Down
2 changes: 1 addition & 1 deletion tests/nav/hybrid/test_keeps_original_nav.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ nav:
- Test: foo.md
files: {}
output:
- hi-hi: ho-ho
- hi-hi: /ho-ho
- test: test
- sub:
- Test: foo.md
4 changes: 0 additions & 4 deletions tests/nav/nested/test_recursion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,8 @@ output:
- Section 1: .
logs:
- WARNING:Disallowing recursion '.' -> 'section2' -> '.'
- WARNING:Disallowing recursion '.' -> 'section2' -> '.'
- WARNING:Disallowing recursion '.' -> 'section2' -> 'section2'
- WARNING:Disallowing recursion '.' -> 'section2' -> 'section2'
- WARNING:Disallowing recursion '.' -> 'section2' -> 'section3' -> 'section2'
- WARNING:Disallowing recursion '.' -> 'section3' -> 'section2' -> '.'
- WARNING:Disallowing recursion '.' -> 'section3' -> 'section2' -> '.'
- WARNING:Disallowing recursion '.' -> 'section3' -> 'section2' -> 'section2'
- WARNING:Disallowing recursion '.' -> 'section3' -> 'section2' -> 'section2'
- WARNING:Disallowing recursion '.' -> 'section3' -> 'section2' -> 'section3'

0 comments on commit 4391a9c

Please sign in to comment.