From 8ffd81d407c698d6329944bc40a7721618498f0e Mon Sep 17 00:00:00 2001 From: Mark Gillard Date: Fri, 7 May 2021 17:04:35 +0300 Subject: [PATCH] improved autolink sorting logic --- poxy/project.py | 21 ++++++++++++++------- setup.py | 2 +- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/poxy/project.py b/poxy/project.py index 58e3b04..46f6f94 100644 --- a/poxy/project.py +++ b/poxy/project.py @@ -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 @@ -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 @@ -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) diff --git a/setup.py b/setup.py index 106b343..1ed415b 100644 --- a/setup.py +++ b/setup.py @@ -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(),