about summary refs log tree commit diff
diff options
context:
space:
mode:
authorflip1995 <philipp.krones@embecosm.com>2021-07-28 14:15:34 +0200
committerflip1995 <philipp.krones@embecosm.com>2021-07-28 14:18:40 +0200
commitfe25282aaa656dda273d5913430a20a450cf11a3 (patch)
treecd9ee3b884c219b3bce9e12b89f4e85729deafad
parent6c5d199d57ee937dc8f4f036c38aa594751250ce (diff)
downloadrust-fe25282aaa656dda273d5913430a20a450cf11a3.tar.gz
rust-fe25282aaa656dda273d5913430a20a450cf11a3.zip
Remove old python lint doc generation scripts
-rwxr-xr-xutil/export.py84
-rw-r--r--util/lintlib.py115
-rwxr-xr-xutil/versions.py6
3 files changed, 3 insertions, 202 deletions
diff --git a/util/export.py b/util/export.py
deleted file mode 100755
index 1248e6b6a26..00000000000
--- a/util/export.py
+++ /dev/null
@@ -1,84 +0,0 @@
-#!/usr/bin/env python
-
-# Build the gh-pages
-
-from collections import OrderedDict
-import re
-import sys
-import json
-
-from lintlib import parse_all, log
-
-lint_subheadline = re.compile(r'''^\*\*([\w\s]+?)[:?.!]?\*\*(.*)''')
-rust_code_block = re.compile(r'''```rust.+?```''', flags=re.DOTALL)
-
-CONF_TEMPLATE = """\
-This lint has the following configuration variables:
-
-* `%s: %s`: %s (defaults to `%s`)."""
-
-
-def parse_code_block(match):
-    lines = []
-
-    for line in match.group(0).split('\n'):
-        # fix syntax highlighting for headers like ```rust,ignore
-        if line.startswith('```rust'):
-            lines.append('```rust')
-        elif not line.startswith('# '):
-            lines.append(line)
-
-    return '\n'.join(lines)
-
-
-def parse_lint_def(lint):
-    lint_dict = {}
-    lint_dict['id'] = lint.name
-    lint_dict['group'] = lint.group
-    lint_dict['level'] = lint.level
-    lint_dict['docs'] = OrderedDict()
-
-    last_section = None
-
-    for line in lint.doc:
-        match = re.match(lint_subheadline, line)
-        if match:
-            last_section = match.groups()[0]
-            text = match.groups()[1]
-        else:
-            text = line
-
-        if not last_section:
-            log.warning("Skipping comment line as it was not preceded by a heading")
-            log.debug("in lint `%s`, line `%s`", lint.name, line)
-
-        if last_section not in lint_dict['docs']:
-            lint_dict['docs'][last_section] = ""
-
-        lint_dict['docs'][last_section] += text + "\n"
-
-    for section in lint_dict['docs']:
-        lint_dict['docs'][section] = re.sub(rust_code_block, parse_code_block, lint_dict['docs'][section].strip())
-
-    return lint_dict
-
-
-def main():
-    lintlist, configs = parse_all()
-    lints = {}
-    for lint in lintlist:
-        lints[lint.name] = parse_lint_def(lint)
-        if lint.name in configs:
-            lints[lint.name]['docs']['Configuration'] = \
-                CONF_TEMPLATE % configs[lint.name]
-
-    outfile = sys.argv[1] if len(sys.argv) > 1 else "util/gh-pages/lints.json"
-    with open(outfile, "w") as fp:
-        lints = list(lints.values())
-        lints.sort(key=lambda x: x['id'])
-        json.dump(lints, fp, indent=2)
-        log.info("wrote JSON for great justice")
-
-
-if __name__ == "__main__":
-    main()
diff --git a/util/lintlib.py b/util/lintlib.py
deleted file mode 100644
index 9cefb2dbb19..00000000000
--- a/util/lintlib.py
+++ /dev/null
@@ -1,115 +0,0 @@
-# Common utils for the several housekeeping scripts.
-
-import os
-import re
-import collections
-
-import logging as log
-log.basicConfig(level=log.INFO, format='%(levelname)s: %(message)s')
-
-Lint = collections.namedtuple('Lint', 'name level doc sourcefile group')
-Config = collections.namedtuple('Config', 'name ty doc default')
-
-lintname_re = re.compile(r'''pub\s+([A-Z_][A-Z_0-9]*)''')
-group_re = re.compile(r'''\s*([a-z_][a-z_0-9]+)''')
-conf_re = re.compile(r'''define_Conf! {\n((?!\n})[\s\S])*\n}''', re.MULTILINE)
-confvar_re = re.compile(
-    r'''/// Lint: ([\w,\s]+)\. (.*)\n\s*\(([^:]+):\s*([^\s=]+)\s*=\s*([^\.\)]+).*\),''', re.MULTILINE)
-comment_re = re.compile(r'''\s*/// ?(.*)''')
-
-lint_levels = {
-    "correctness": 'Deny',
-    "suspicious": 'Warn',
-    "style": 'Warn',
-    "complexity": 'Warn',
-    "perf": 'Warn',
-    "restriction": 'Allow',
-    "pedantic": 'Allow',
-    "nursery": 'Allow',
-    "cargo": 'Allow',
-}
-
-
-def parse_lints(lints, filepath):
-    comment = []
-    clippy = False
-    deprecated = False
-    name = ""
-
-    with open(filepath) as fp:
-        for line in fp:
-            if clippy or deprecated:
-                m = lintname_re.search(line)
-                if m:
-                    name = m.group(1).lower()
-                    line = next(fp)
-
-                    if deprecated:
-                        level = "Deprecated"
-                        group = "deprecated"
-                    else:
-                        while True:
-                            g = group_re.search(line)
-                            if g:
-                                group = g.group(1).lower()
-                                level = lint_levels.get(group, None)
-                                break
-                            line = next(fp)
-
-                    if level is None:
-                        continue
-
-                    log.info("found %s with level %s in %s",
-                             name, level, filepath)
-                    lints.append(Lint(name, level, comment, filepath, group))
-                    comment = []
-
-                    clippy = False
-                    deprecated = False
-                    name = ""
-                else:
-                    m = comment_re.search(line)
-                    if m:
-                        comment.append(m.group(1))
-            elif line.startswith("declare_clippy_lint!"):
-                clippy = True
-                deprecated = False
-            elif line.startswith("declare_deprecated_lint!"):
-                clippy = False
-                deprecated = True
-            elif line.startswith("declare_lint!"):
-                import sys
-                print(
-                    "don't use `declare_lint!` in Clippy, "
-                    "use `declare_clippy_lint!` instead"
-                )
-                sys.exit(42)
-
-
-def parse_configs(path):
-    configs = {}
-    with open(os.path.join(path, 'utils/conf.rs')) as fp:
-        contents = fp.read()
-
-    match = re.search(conf_re, contents)
-    confvars = re.findall(confvar_re, match.group(0))
-
-    for (lints, doc, name, ty, default) in confvars:
-        for lint in lints.split(','):
-            configs[lint.strip().lower()] = Config(name.replace("_", "-"), ty, doc, default)
-    return configs
-
-
-def parse_all(path="clippy_lints/src"):
-    lints = []
-    for root, dirs, files in os.walk(path):
-        for fn in files:
-            if fn.endswith('.rs'):
-                parse_lints(lints, os.path.join(root, fn))
-
-    log.info("got %s lints", len(lints))
-
-    configs = parse_configs(path)
-    log.info("got %d configs", len(configs))
-
-    return lints, configs
diff --git a/util/versions.py b/util/versions.py
index 5cdc7313f54..0cfa007d1b2 100755
--- a/util/versions.py
+++ b/util/versions.py
@@ -3,8 +3,8 @@
 import json
 import os
 import sys
-
-from lintlib import log
+import logging as log
+log.basicConfig(level=log.INFO, format='%(levelname)s: %(message)s')
 
 
 def key(v):
@@ -26,7 +26,7 @@ def key(v):
 
 def main():
     if len(sys.argv) < 2:
-        print("Error: specify output directory")
+        log.error("specify output directory")
         return
 
     outdir = sys.argv[1]