Mercurial > cpython-lru_cache-weakref
comparison Tools/scripts/patchcheck.py @ 71026:39fadb0255cd
general cleaning up
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Mon, 27 Jun 2011 18:25:06 -0500 |
| parents | 45e7c067332e |
| children | 5467abaaf5eb |
comparison
equal
deleted
inserted
replaced
| 71025:45e7c067332e | 71026:39fadb0255cd |
|---|---|
| 34 @status("Getting the list of files that have been added/changed", | 34 @status("Getting the list of files that have been added/changed", |
| 35 info=lambda x: n_files_str(len(x))) | 35 info=lambda x: n_files_str(len(x))) |
| 36 def changed_files(): | 36 def changed_files(): |
| 37 """Get the list of changed or added files from the VCS.""" | 37 """Get the list of changed or added files from the VCS.""" |
| 38 if os.path.isdir('.hg'): | 38 if os.path.isdir('.hg'): |
| 39 vcs = 'hg' | |
| 40 cmd = 'hg status --added --modified --no-status' | 39 cmd = 'hg status --added --modified --no-status' |
| 41 else: | 40 else: |
| 42 sys.exit('need a checkout to get modified files') | 41 sys.exit('need a checkout to get modified files') |
| 43 | 42 |
| 44 st = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) | 43 st = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) |
| 45 try: | 44 try: |
| 46 st.wait() | 45 st.wait() |
| 47 if vcs == 'hg': | 46 return [x.decode().rstrip() for x in st.stdout] |
| 48 return [x.decode().rstrip() for x in st.stdout] | |
| 49 else: | |
| 50 output = (x.decode().rstrip().rsplit(None, 1)[-1] | |
| 51 for x in st.stdout if x[0] in b'AM') | |
| 52 return set(path for path in output if os.path.isfile(path)) | |
| 53 finally: | 47 finally: |
| 54 st.stdout.close() | 48 st.stdout.close() |
| 55 | 49 |
| 56 | 50 |
| 57 def report_modified_files(file_paths): | 51 def report_modified_files(file_paths): |
| 67 | 61 |
| 68 @status("Fixing whitespace", info=report_modified_files) | 62 @status("Fixing whitespace", info=report_modified_files) |
| 69 def normalize_whitespace(file_paths): | 63 def normalize_whitespace(file_paths): |
| 70 """Make sure that the whitespace for .py files have been normalized.""" | 64 """Make sure that the whitespace for .py files have been normalized.""" |
| 71 reindent.makebackup = False # No need to create backups. | 65 reindent.makebackup = False # No need to create backups. |
| 72 fixed = [] | 66 fixed = [path for path in file_paths if path.endswith('.py') and |
| 73 for path in (x for x in file_paths if x.endswith('.py')): | 67 reindent.check(path)] |
| 74 if reindent.check(path): | |
| 75 fixed.append(path) | |
| 76 return fixed | 68 return fixed |
| 77 | 69 |
| 78 | 70 |
| 79 @status("Fixing C file whitespace", info=report_modified_files) | 71 @status("Fixing C file whitespace", info=report_modified_files) |
| 80 def normalize_c_whitespace(file_paths): | 72 def normalize_c_whitespace(file_paths): |
