From 182e394139f209e1b911b16c8e94db51bd7ee180 Mon Sep 17 00:00:00 2001 From: Chris Mayo Date: Tue, 26 May 2020 20:20:57 +0100 Subject: [PATCH 1/5] Set max-line-length to 88 as recommended by Black https://black.readthedocs.io/en/stable/the_black_code_style.html#line-length --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index eedced86..328d1896 100644 --- a/setup.cfg +++ b/setup.cfg @@ -25,7 +25,7 @@ filename = builtins = _ _n -max-line-length = 80 +max-line-length = 88 per-file-ignores = # In several files imports intentionally cause: # E402: module level import not at top of file From fbf3a8ab20b3a8e170582e2452f2edab4e14b15b Mon Sep 17 00:00:00 2001 From: Chris Mayo Date: Tue, 26 May 2020 20:20:57 +0100 Subject: [PATCH 2/5] Run black on doc/ --- doc/examples/filter_xml_output.py | 15 +++++++++------ doc/web/hooks/__hooks__.py | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/doc/examples/filter_xml_output.py b/doc/examples/filter_xml_output.py index de75b9c6..c2ae67a1 100644 --- a/doc/examples/filter_xml_output.py +++ b/doc/examples/filter_xml_output.py @@ -28,21 +28,24 @@ def main(args): with open(filename) as fd: tree = parse(fd) filter_tree(tree) - tree.write(sys.stdout, encoding='utf-8') + tree.write(sys.stdout, encoding="utf-8") def filter_tree(tree): """Filter all 401 errors.""" to_remove = [] - for elem in tree.findall('urldata'): - valid = elem.find('valid') - if valid is not None and valid.text == '0' and \ - valid.attrib.get('result', '').startswith('401'): + for elem in tree.findall("urldata"): + valid = elem.find("valid") + if ( + valid is not None + and valid.text == "0" + and valid.attrib.get("result", "").startswith("401") + ): to_remove.append(elem) root = tree.getroot() for elem in to_remove: root.remove(elem) -if __name__ == '__main__': +if __name__ == "__main__": main(sys.argv[1:]) diff --git a/doc/web/hooks/__hooks__.py b/doc/web/hooks/__hooks__.py index a6831329..91b04888 100644 --- a/doc/web/hooks/__hooks__.py +++ b/doc/web/hooks/__hooks__.py @@ -34,6 +34,6 @@ def chmod(config): hooks = { - 'site.output.post': [compress_javascript, compress_css], - 'site.done': [chmod], + "site.output.post": [compress_javascript, compress_css], + "site.done": [chmod], } From abbe301b82790380a6f326aeaf75f9edb815b5c7 Mon Sep 17 00:00:00 2001 From: Chris Mayo Date: Tue, 26 May 2020 20:20:57 +0100 Subject: [PATCH 3/5] Run black on scripts/ --- scripts/analyze_memdump.py | 30 ++++++++++++++++---- scripts/removeafter.py | 4 ++- scripts/update_iana_uri_schemes.py | 45 +++++++++++++++++++----------- scripts/viewprof.py | 6 ++-- 4 files changed, 58 insertions(+), 27 deletions(-) diff --git a/scripts/analyze_memdump.py b/scripts/analyze_memdump.py index 62649964..3f0f9cf9 100755 --- a/scripts/analyze_memdump.py +++ b/scripts/analyze_memdump.py @@ -23,6 +23,7 @@ import codecs import html from linkcheck import strformat + def main(filename): om = print_memorydump(filename) dirname, basename = os.path.split(filename) @@ -32,13 +33,16 @@ def main(filename): os.mkdir(basedir) write_htmlfiles(om, basedir) + def print_memorydump(filename): from meliae import loader + om = loader.load(filename, collapse=True) om.remove_expensive_references() print om.summarize() return om + def write_htmlfiles(om, basedir): om.compute_parents() open_files = {} @@ -47,21 +51,24 @@ def write_htmlfiles(om, basedir): write_html_obj(fp, obj, om.objs) close_files(open_files) + def get_file(type_str, open_files, basedir): """Get already opened file, or open and initialize a new one.""" if type_str not in open_files: - filename = type_str+".html" - encoding = 'utf-8' - fd = codecs.open(os.path.join(basedir, filename), 'w', encoding) + filename = type_str + ".html" + encoding = "utf-8" + fd = codecs.open(os.path.join(basedir, filename), "w", encoding) open_files[type_str] = fd write_html_header(fd, type_str, encoding) return open_files[type_str] + def close_files(open_files): for fp in open_files.values(): write_html_footer(fp) fp.close() + HtmlHeader = """ @@ -70,10 +77,14 @@ HtmlHeader = """ """ + def write_html_header(fp, type_str, encoding): fp.write(HtmlHeader % encoding) fp.write("

Type %s

\n" % type_str) - fp.write("\n") + fp.write( + "
AddressNameSizeParentsReferences
\n" + ) + def get_children(obj, objs): res = [] @@ -89,6 +100,7 @@ def get_children(obj, objs): res.append(entry) return res + def get_parents(obj, objs): res = [] for address in obj.parents: @@ -103,6 +115,7 @@ def get_parents(obj, objs): res.append(entry) return res + def write_html_obj(fp, obj, objs): if obj.value is None: value = "None" @@ -115,11 +128,16 @@ def write_html_obj(fp, obj, objs): parents=",".join(get_parents(obj, objs)), value=value, ) - fp.write("\n" % attrs) + fp.write( + "\n" + % attrs + ) + def write_html_footer(fp): fp.write("
AddressNameSizeParentsReferences
%(address)d%(value)s%(size)s%(children)s
%(address)d%(value)s%(size)s%(children)s
") -if __name__ == '__main__': + +if __name__ == "__main__": filename = sys.argv[1] main(filename) diff --git a/scripts/removeafter.py b/scripts/removeafter.py index 1c0fab70..f6386d0b 100755 --- a/scripts/removeafter.py +++ b/scripts/removeafter.py @@ -6,6 +6,7 @@ from __future__ import print_function import fileinput import sys + def main(args): """Remove lines after marker.""" filename = args[0] @@ -15,5 +16,6 @@ def main(args): if line.startswith(marker): break -if __name__ == '__main__': + +if __name__ == "__main__": main(sys.argv[1:]) diff --git a/scripts/update_iana_uri_schemes.py b/scripts/update_iana_uri_schemes.py index c54c31d3..967f0a77 100644 --- a/scripts/update_iana_uri_schemes.py +++ b/scripts/update_iana_uri_schemes.py @@ -5,17 +5,23 @@ import requests iana_uri_schemes = "https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml" # CSV format: URI Scheme,Template,Description,Reference -csv_iana_uri_schemes_permanent = 'https://www.iana.org/assignments/uri-schemes/uri-schemes-1.csv' -csv_iana_uri_schemes_provisional = 'https://www.iana.org/assignments/uri-schemes/uri-schemes-2.csv' -csv_iana_uri_schemes_historical = 'https://www.iana.org/assignments/uri-schemes/uri-schemes-3.csv' +csv_iana_uri_schemes_permanent = ( + "https://www.iana.org/assignments/uri-schemes/uri-schemes-1.csv" +) +csv_iana_uri_schemes_provisional = ( + "https://www.iana.org/assignments/uri-schemes/uri-schemes-2.csv" +) +csv_iana_uri_schemes_historical = ( + "https://www.iana.org/assignments/uri-schemes/uri-schemes-3.csv" +) iana_uri_schemes_permanent = {} iana_uri_schemes_provisional = {} iana_uri_schemes_historical = {} iana_uri_schemes_other = { - "clsid": "Microsoft specific", - "find" : "Mozilla specific", - "isbn" : "ISBN (int. book numbers)", + "clsid": "Microsoft specific", + "find": "Mozilla specific", + "isbn": "ISBN (int. book numbers)", "javascript": "JavaScript", } @@ -58,24 +64,27 @@ ignored_schemes_re = re.compile(ignored_schemes, re.VERBOSE) is_unknown_scheme = ignored_schemes_re.match ''' + def main(args): parse_csv_file(csv_iana_uri_schemes_permanent, iana_uri_schemes_permanent) parse_csv_file(csv_iana_uri_schemes_provisional, iana_uri_schemes_provisional) parse_csv_file(csv_iana_uri_schemes_historical, iana_uri_schemes_historical) for scheme in iana_uri_schemes_other: - if (scheme in iana_uri_schemes_permanent or - scheme in iana_uri_schemes_provisional or - scheme in iana_uri_schemes_historical): + if ( + scheme in iana_uri_schemes_permanent + or scheme in iana_uri_schemes_provisional + or scheme in iana_uri_schemes_historical + ): raise ValueError(scheme) for scheme in filter_uri_schemes_permanent: if scheme in iana_uri_schemes_permanent: del iana_uri_schemes_permanent[scheme] args = dict( - uri = iana_uri_schemes, - permanent = get_regex(iana_uri_schemes_permanent), - provisional = get_regex(iana_uri_schemes_provisional), - historical = get_regex(iana_uri_schemes_historical), - other = get_regex(iana_uri_schemes_other), + uri=iana_uri_schemes, + permanent=get_regex(iana_uri_schemes_permanent), + provisional=get_regex(iana_uri_schemes_provisional), + historical=get_regex(iana_uri_schemes_historical), + other=get_regex(iana_uri_schemes_other), ) res = template % args print res @@ -83,8 +92,10 @@ def main(args): def get_regex(schemes): - expr = ["|%s # %s" % (re.escape(scheme).ljust(10), description) - for scheme, description in sorted(schemes.items())] + expr = [ + "|%s # %s" % (re.escape(scheme).ljust(10), description) + for scheme, description in sorted(schemes.items()) + ] return "\n".join(expr) @@ -102,5 +113,5 @@ def parse_csv_file(url, res): res[scheme] = description -if __name__ == '__main__': +if __name__ == "__main__": sys.exit(main(sys.argv[1:])) diff --git a/scripts/viewprof.py b/scripts/viewprof.py index 2c604a97..4220f96a 100755 --- a/scripts/viewprof.py +++ b/scripts/viewprof.py @@ -7,6 +7,7 @@ Usage: $0 import sys import yappi + def main(args): filename = args[0] stats = yappi.YFuncStats() @@ -14,6 +15,5 @@ def main(args): stats.print_all() -if __name__ == '__main__': - main(sys.argv[1:]) - +if __name__ == "__main__": + main(sys.argv[1:]) From cf7aff277073947e7488f796e84f1322dfdd4a5c Mon Sep 17 00:00:00 2001 From: Chris Mayo Date: Tue, 26 May 2020 20:20:57 +0100 Subject: [PATCH 4/5] Fix remaining flake8 violations in doc/ and scripts/ doc/web/hooks/__hooks__.py:31:57: E999 SyntaxError: invalid token scripts/analyze_memdump.py:42:12: E999 SyntaxError: invalid syntax scripts/analyze_memdump.py:85:89: E501 line too long (105 > 88 characters) scripts/analyze_memdump.py:132:89: E501 line too long (97 > 88 characters) scripts/update_iana_uri_schemes.py:90:13: E999 SyntaxError: invalid syntax --- doc/web/hooks/__hooks__.py | 4 ++-- scripts/analyze_memdump.py | 9 +++++---- scripts/update_iana_uri_schemes.py | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/doc/web/hooks/__hooks__.py b/doc/web/hooks/__hooks__.py index 91b04888..522f0a88 100644 --- a/doc/web/hooks/__hooks__.py +++ b/doc/web/hooks/__hooks__.py @@ -28,9 +28,9 @@ def chmod(config): output_dir = config["output_dir"] for dirpath, dirnames, filenames in os.walk(output_dir): for dirname in dirnames: - os.chmod(os.path.join(dirpath, dirname), 0755) + os.chmod(os.path.join(dirpath, dirname), 0o755) for filename in filenames: - os.chmod(os.path.join(dirpath, filename), 0644) + os.chmod(os.path.join(dirpath, filename), 0o644) hooks = { diff --git a/scripts/analyze_memdump.py b/scripts/analyze_memdump.py index 3f0f9cf9..cfcebf22 100755 --- a/scripts/analyze_memdump.py +++ b/scripts/analyze_memdump.py @@ -39,7 +39,7 @@ def print_memorydump(filename): om = loader.load(filename, collapse=True) om.remove_expensive_references() - print om.summarize() + print(om.summarize()) return om @@ -82,7 +82,8 @@ def write_html_header(fp, type_str, encoding): fp.write(HtmlHeader % encoding) fp.write("

Type %s

\n" % type_str) fp.write( - "\n" + "
AddressNameSizeParentsReferences
" + "\n" ) @@ -129,8 +130,8 @@ def write_html_obj(fp, obj, objs): value=value, ) fp.write( - "\n" - % attrs + "" + "\n" % attrs ) diff --git a/scripts/update_iana_uri_schemes.py b/scripts/update_iana_uri_schemes.py index 967f0a77..db23b36f 100644 --- a/scripts/update_iana_uri_schemes.py +++ b/scripts/update_iana_uri_schemes.py @@ -87,7 +87,7 @@ def main(args): other=get_regex(iana_uri_schemes_other), ) res = template % args - print res + print(res) return 0 From de5dccb0ce552ec294786685e7e98f536580de66 Mon Sep 17 00:00:00 2001 From: Chris Mayo Date: Tue, 26 May 2020 20:20:57 +0100 Subject: [PATCH 5/5] Enable tox flake8 checking for all Python files --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index f82596ea..6c36f827 100644 --- a/tox.ini +++ b/tox.ini @@ -35,7 +35,7 @@ deps = [testenv:flake8] deps = flake8 skip_install = true -commands = flake8 linkchecker setup.py linkcheck {posargs} +commands = flake8 {posargs} [testenv:check-manifest] deps = check-manifest
AddressNameSizeParentsReferences
%(address)d%(value)s%(size)s%(children)s
%(address)d%(value)s%(size)s%(children)s