summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2010-07-04 22:05:34 (GMT)
committerBrett Cannon <bcannon@gmail.com>2010-07-04 22:05:34 (GMT)
commit058173e2b273263b91f2586d080324fbdb8b704b (patch)
tree73696844dbeafcdfcd5dec89b2e1fea527b729ba
parent5cca695ed64482c88c010964142ffad5e9104fe3 (diff)
downloadcpython-058173e2b273263b91f2586d080324fbdb8b704b.zip
cpython-058173e2b273263b91f2586d080324fbdb8b704b.tar.gz
cpython-058173e2b273263b91f2586d080324fbdb8b704b.tar.bz2
Do some basic refactoring. Along the way also list what files had their
whitespace cleaned up and do the proper plurality for "N file(s)" based on N. Refactoring closes issue8912. Thanks to Éric Araujo for the patch.
-rw-r--r--Tools/scripts/patchcheck.py46
1 files changed, 32 insertions, 14 deletions
diff --git a/Tools/scripts/patchcheck.py b/Tools/scripts/patchcheck.py
index 544b00e..7d001e8 100644
--- a/Tools/scripts/patchcheck.py
+++ b/Tools/scripts/patchcheck.py
@@ -5,6 +5,10 @@ import sys
import reindent
+def n_files_str(count):
+ """Return 'N file(s)' with the proper plurality on 'file'."""
+ return "{} file{}".format(count, "s" if count != 1 else "")
+
def status(message, modal=False, info=None):
"""Decorator to output status info to stdout."""
def decorated_fxn(fxn):
@@ -26,7 +30,7 @@ def status(message, modal=False, info=None):
return decorated_fxn
@status("Getting the list of files that have been added/changed",
- info=lambda x: "%s files" % len(x))
+ info=lambda x: n_files_str(len(x)))
def changed_files():
"""Run ``svn status`` and return a set of files that have been
changed/added."""
@@ -44,20 +48,30 @@ def changed_files():
files.add(path)
return files
-@status("Fixing whitespace", info=lambda x: "%s files" % x)
+def report_modified_files(file_paths):
+ count = len(file_paths)
+ if count == 0:
+ return n_files_str(count)
+ else:
+ lines = ["{}:".format(n_files_str(count))]
+ for path in file_paths:
+ lines.append(" {}".format(path))
+ return "\n".join(lines)
+
+@status("Fixing whitespace", info=report_modified_files)
def normalize_whitespace(file_paths):
"""Make sure that the whitespace for .py files have been normalized."""
reindent.makebackup = False # No need to create backups.
- result = list(map(reindent.check, (x for x in file_paths if x.endswith('.py'))))
- return sum(result)
+ fixed = []
+ for path in (x for x in file_paths if x.endswith('.py')):
+ if reindent.check(path):
+ fixed.append(path)
+ return fixed
@status("Docs modified", modal=True)
def docs_modified(file_paths):
- """Report if any files in the Docs directory."""
- for path in file_paths:
- if path.startswith("Doc"):
- return True
- return False
+ """Report if any file in the Doc directory has been changed."""
+ return bool(file_paths)
@status("Misc/ACKS updated", modal=True)
def credit_given(file_paths):
@@ -72,14 +86,18 @@ def reported_news(file_paths):
def main():
file_paths = changed_files()
- # PEP 7/8 verification.
- normalize_whitespace(file_paths)
+ python_files = [fn for fn in file_paths if fn.endswith('.py')]
+ c_files = [fn for fn in file_paths if fn.endswith(('.c', '.h'))]
+ docs = [fn for fn in file_paths if fn.startswith('Doc')]
+ special_files = {'Misc/ACKS', 'Misc/NEWS'} & set(file_paths)
+ # PEP 8 whitespace rules enforcement.
+ normalize_whitespace(python_files)
# Docs updated.
- docs_modified(file_paths)
+ docs_modified(docs)
# Misc/ACKS changed.
- credit_given(file_paths)
+ credit_given(special_files)
# Misc/NEWS changed.
- reported_news(file_paths)
+ reported_news(special_files)
# Test suite run and passed.
print()