Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-109408: Revert pre-commit whitespace checks pending portable solution #110726

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Don't revert too much
  • Loading branch information
hugovk committed Oct 11, 2023
commit 105b86c819214ca2ce165f37eac55cc45ff1c4be
37 changes: 7 additions & 30 deletions Tools/patchcheck/patchcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ def report_modified_files(file_paths):
if count == 0:
return n_files_str(count)
else:
lines = ["{}:".format(n_files_str(count))]
lines = [f"{n_files_str(count)}:"]
for path in file_paths:
lines.append(" {}".format(path))
lines.append(f" {path}")
return "\n".join(lines)


Expand Down Expand Up @@ -213,27 +213,6 @@ def normalize_c_whitespace(file_paths):
return fixed


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

@status("Fixing docs whitespace", info=report_modified_files)
def normalize_docs_whitespace(file_paths):
fixed = []
for path in file_paths:
abspath = os.path.join(SRCDIR, path)
try:
with open(abspath, 'rb') as f:
lines = f.readlines()
new_lines = [ws_re.sub(br'\1', line) for line in lines]
if new_lines != lines:
shutil.copyfile(abspath, abspath + '.bak')
with open(abspath, 'wb') as f:
f.writelines(new_lines)
fixed.append(path)
except Exception as err:
print('Cannot fix %s: %s' % (path, err))
return fixed


@status("Docs modified", modal=True)
def docs_modified(file_paths):
"""Report if any file in the Doc directory has been changed."""
Expand Down Expand Up @@ -270,6 +249,7 @@ def regenerated_pyconfig_h_in(file_paths):
else:
return "not needed"


def ci(pull_request):
if pull_request == 'false':
print('Not a pull request; skipping')
Expand All @@ -278,19 +258,18 @@ def ci(pull_request):
file_paths = changed_files(base_branch)
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'))]
doc_files = [fn for fn in file_paths if fn.startswith('Doc') and
fn.endswith(('.rst', '.inc'))]
fixed = []
fixed.extend(normalize_whitespace(python_files))
fixed.extend(normalize_c_whitespace(c_files))
fixed.extend(normalize_docs_whitespace(doc_files))
if not fixed:
print('No whitespace issues found')
else:
print(f'Please fix the {len(fixed)} file(s) with whitespace issues')
print('(on UNIX you can run `make patchcheck` to make the fixes)')
count = len(fixed)
print(f'Please fix the {n_files_str(count)} with whitespace issues')
print('(on Unix you can run `make patchcheck` to make the fixes)')
sys.exit(1)


def main():
base_branch = get_base_branch()
file_paths = changed_files(base_branch)
Expand All @@ -303,8 +282,6 @@ def main():
normalize_whitespace(python_files)
# C rules enforcement.
normalize_c_whitespace(c_files)
# Doc whitespace enforcement.
normalize_docs_whitespace(doc_files)
# Docs updated.
docs_modified(doc_files)
# Misc/ACKS changed.
Expand Down
Loading