Back to index

python3.2  3.2.2
Functions | Variables
patchcheck Namespace Reference

Functions

def n_files_str
def status
def changed_files
def report_modified_files
def normalize_whitespace
def normalize_c_whitespace
def normalize_docs_whitespace
def docs_modified
def credit_given
def reported_news
def main

Variables

tuple SRCDIR = sysconfig.get_config_var('srcdir')
tuple ws_re = re.compile(br'\s+(\r?\n)$')

Function Documentation

Get the list of changed or added files from the VCS.

Definition at line 41 of file patchcheck.py.

00041 
00042 def changed_files():
00043     """Get the list of changed or added files from the VCS."""
00044     if os.path.isdir(os.path.join(SRCDIR, '.hg')):
00045         vcs = 'hg'
00046         cmd = 'hg status --added --modified --no-status'
00047     elif os.path.isdir('.svn'):
00048         vcs = 'svn'
00049         cmd = 'svn status --quiet --non-interactive --ignore-externals'
00050     else:
00051         sys.exit('need a checkout to get modified files')
00052 
00053     st = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)
00054     try:
00055         st.wait()
00056         if vcs == 'hg':
00057             return [x.decode().rstrip() for x in st.stdout]
00058         else:
00059             output = (x.decode().rstrip().rsplit(None, 1)[-1]
00060                       for x in st.stdout if x[0] in b'AM')
00061         return set(path for path in output if os.path.isfile(path))
00062     finally:
00063         st.stdout.close()
00064 

Here is the call graph for this function:

Here is the caller graph for this function:

def patchcheck.credit_given (   file_paths)
Check if Misc/ACKS has been changed.

Definition at line 129 of file patchcheck.py.

00129 
00130 def credit_given(file_paths):
00131     """Check if Misc/ACKS has been changed."""
00132     return 'Misc/ACKS' in file_paths
00133 
00134 
@status("Misc/NEWS updated", modal=True)

Here is the call graph for this function:

Here is the caller graph for this function:

def patchcheck.docs_modified (   file_paths)
Report if any file in the Doc directory has been changed.

Definition at line 123 of file patchcheck.py.

00123 
00124 def docs_modified(file_paths):
00125     """Report if any file in the Doc directory has been changed."""
00126     return bool(file_paths)
00127 
00128 
@status("Misc/ACKS updated", modal=True)

Here is the call graph for this function:

Here is the caller graph for this function:

def patchcheck.main ( void  )

Definition at line 140 of file patchcheck.py.

00140 
00141 def main():
00142     file_paths = changed_files()
00143     python_files = [fn for fn in file_paths if fn.endswith('.py')]
00144     c_files = [fn for fn in file_paths if fn.endswith(('.c', '.h'))]
00145     doc_files = [fn for fn in file_paths if fn.startswith('Doc')]
00146     special_files = {'Misc/ACKS', 'Misc/NEWS'} & set(file_paths)
00147     # PEP 8 whitespace rules enforcement.
00148     normalize_whitespace(python_files)
00149     # C rules enforcement.
00150     normalize_c_whitespace(c_files)
00151     # Doc whitespace enforcement.
00152     normalize_docs_whitespace(doc_files)
00153     # Docs updated.
00154     docs_modified(doc_files)
00155     # Misc/ACKS changed.
00156     credit_given(special_files)
00157     # Misc/NEWS changed.
00158     reported_news(special_files)
00159 
00160     # Test suite run and passed.
00161     if python_files or c_files:
00162         print()
00163         print("Did you run the test suite?")
00164 

Here is the call graph for this function:

def patchcheck.n_files_str (   count)
Return 'N file(s)' with the proper plurality on 'file'.

Definition at line 16 of file patchcheck.py.

00016 
00017 def n_files_str(count):
00018     """Return 'N file(s)' with the proper plurality on 'file'."""
00019     return "{} file{}".format(count, "s" if count != 1 else "")
00020 

Here is the caller graph for this function:

def patchcheck.normalize_c_whitespace (   file_paths)
Report if any C files 

Definition at line 88 of file patchcheck.py.

00088 
00089 def normalize_c_whitespace(file_paths):
00090     """Report if any C files """
00091     fixed = []
00092     for path in file_paths:
00093         abspath = os.path.join(SRCDIR, path)
00094         with open(abspath, 'r') as f:
00095             if '\t' not in f.read():
00096                 continue
00097         untabify.process(abspath, 8, verbose=False)
00098         fixed.append(path)
00099     return fixed
00100 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 104 of file patchcheck.py.

00104 
00105 def normalize_docs_whitespace(file_paths):
00106     fixed = []
00107     for path in file_paths:
00108         abspath = os.path.join(SRCDIR, path)
00109         try:
00110             with open(abspath, 'rb') as f:
00111                 lines = f.readlines()
00112             new_lines = [ws_re.sub(br'\1', line) for line in lines]
00113             if new_lines != lines:
00114                 shutil.copyfile(abspath, abspath + '.bak')
00115                 with open(abspath, 'wb') as f:
00116                     f.writelines(new_lines)
00117                 fixed.append(path)
00118         except Exception as err:
00119             print('Cannot fix %s: %s' % (path, err))
00120     return fixed
00121 
00122 
@status("Docs modified", modal=True)

Here is the call graph for this function:

Here is the caller graph for this function:

def patchcheck.normalize_whitespace (   file_paths)
Make sure that the whitespace for .py files have been normalized.

Definition at line 77 of file patchcheck.py.

00077 
00078 def normalize_whitespace(file_paths):
00079     """Make sure that the whitespace for .py files have been normalized."""
00080     reindent.makebackup = False  # No need to create backups.
00081     fixed = []
00082     for path in (x for x in file_paths if x.endswith('.py')):
00083         if reindent.check(os.path.join(SRCDIR, path)):
00084             fixed.append(path)
00085     return fixed
00086 
00087 
@status("Fixing C file whitespace", info=report_modified_files)

Here is the call graph for this function:

Here is the caller graph for this function:

def patchcheck.report_modified_files (   file_paths)

Definition at line 65 of file patchcheck.py.

00065 
00066 def report_modified_files(file_paths):
00067     count = len(file_paths)
00068     if count == 0:
00069         return n_files_str(count)
00070     else:
00071         lines = ["{}:".format(n_files_str(count))]
00072         for path in file_paths:
00073             lines.append("  {}".format(path))
00074         return "\n".join(lines)
00075 
00076 
@status("Fixing whitespace", info=report_modified_files)

Here is the call graph for this function:

def patchcheck.reported_news (   file_paths)
Check if Misc/NEWS has been changed.

Definition at line 135 of file patchcheck.py.

00135 
00136 def reported_news(file_paths):
00137     """Check if Misc/NEWS has been changed."""
00138     return 'Misc/NEWS' in file_paths
00139 

Here is the caller graph for this function:

def patchcheck.status (   message,
  modal = False,
  info = None 
)
Decorator to output status info to stdout.

Definition at line 21 of file patchcheck.py.

00021 
00022 def status(message, modal=False, info=None):
00023     """Decorator to output status info to stdout."""
00024     def decorated_fxn(fxn):
00025         def call_fxn(*args, **kwargs):
00026             sys.stdout.write(message + ' ... ')
00027             sys.stdout.flush()
00028             result = fxn(*args, **kwargs)
00029             if not modal and not info:
00030                 print("done")
00031             elif info:
00032                 print(info(result))
00033             else:
00034                 print("yes" if result else "NO")
00035             return result
00036         return call_fxn
00037     return decorated_fxn
00038 
00039 
00040 @status("Getting the list of files that have been added/changed",
        info=lambda x: n_files_str(len(x)))

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 13 of file patchcheck.py.

tuple patchcheck.ws_re = re.compile(br'\s+(\r?\n)$')

Definition at line 101 of file patchcheck.py.