Skip to content

Commit

Permalink
improved autolink sorting logic
Browse files Browse the repository at this point in the history
  • Loading branch information
marzer committed May 7, 2021
1 parent f0a37c7 commit 8ffd81d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
21 changes: 14 additions & 7 deletions poxy/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,7 @@ class Context(object):
},
ignore_extra_keys=True
)
__namespace_qualified = re.compile(r"^[a-zA-Z_][a-zA-Z0-9_]*::.+$")

def is_verbose(self):
return self.__verbose
Expand Down Expand Up @@ -826,12 +827,15 @@ def verbose_value(self, name, val):
if val is not None:
if isinstance(val, dict):
if val:
rpad = 0
for k in val:
rpad = max(rpad, len(str(k)))
first = True
for k, v in val.items():
if not first:
print(f'\n{" ":<35}', file=buf, end='')
first = False
print(rf'{k:<35} => {v}', file=buf, end='')
print(rf'{k:<{rpad}} => {v}', file=buf, end='')
elif is_collection(val):
if val:
first = True
Expand Down Expand Up @@ -1261,16 +1265,19 @@ def __init__(self, config_path, output_dir, threads, cleanup, verbose, mcss_dir,
self.verbose_value(r'Context.defines', self.defines)

# autolinks
default_autolinks = [(k, v) for k, v in _Defaults.autolinks.items()]
user_autolinks = []
self.autolinks = [(k, v) for k, v in _Defaults.autolinks.items()]
if 'autolinks' in config:
for pattern, u in config['autolinks'].items():
uri = u.strip()
if pattern.strip() and uri:
user_autolinks.append((pattern, uri))
default_autolinks.sort(key = lambda v: len(v[0]), reverse=True)
user_autolinks.sort(key = lambda v: len(v[0]), reverse=True)
self.autolinks = tuple(user_autolinks + default_autolinks)
self.autolinks.append((pattern, uri))
self.autolinks.sort(key = lambda v: (
self.__namespace_qualified.fullmatch(v[0]) is None,
v[0].find(r'std::') == -1,
-len(v[0]),
v[0]
))
self.autolinks = tuple(self.autolinks)
self.verbose_value(r'Context.autolinks', self.autolinks)

# aliases (ALIASES)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def enum_subdirs(root):

setup_args = dict(
name=r'poxy',
version=r'0.2.0',
version=r'0.2.1',
description=r'Documentation generator for C++.',
long_description_content_type=r'text/markdown',
long_description=f'{README}\n\n{HISTORY}'.strip(),
Expand Down

0 comments on commit 8ffd81d

Please sign in to comment.