Skip to content

Commit 5c752ea

Browse files
Print non-breaking space directly in lint.yml (pytorch#56726)
Summary: After some fun investigating, samestep found that `\u1234` to produce a unicode character is only supported in bash > 4.2, but MacOS ship with bash/sh 3.2, so it was searching for the literal string `u1234`. This fixes the issue by printing out the char directly via its UTF-8 bytes and `printf`. ](https://our.intern.facebook.com/intern/diff/27952866/) Pull Request resolved: pytorch#56726 Pulled By: driazati Reviewed By: SplitInfinity Differential Revision: D27952866 fbshipit-source-id: 35871e959e250dfdbbdf8b121fc92212bc0614e8
1 parent 08ce230 commit 5c752ea

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

.github/workflows/lint.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ jobs:
6363
- name: Ensure no non-breaking spaces
6464
if: always()
6565
run: |
66-
(! git --no-pager grep -In $'\u00a0' -- . || (echo "The above lines have non-breaking spaces (U+00A0); please convert them to spaces (U+0020)"; false))
66+
# NB: We use 'printf' below rather than '\u000a' since bash pre-4.2
67+
# does not support the '\u000a' syntax (which is relevant for local linters)
68+
(! git --no-pager grep -In "$(printf '\xC2\xA0')" -- . || (echo "The above lines have non-breaking spaces (U+00A0); please convert them to spaces (U+0020)"; false))
6769
- name: Ensure canonical include
6870
if: always()
6971
run: |

tools/actions_local_runner.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def git(args: List[str]) -> List[str]:
4545
return [line.strip() for line in lines]
4646

4747

48-
def find_changed_files(merge_base: str = "origin/master") -> List[str]:
48+
def find_changed_files() -> List[str]:
4949
untracked = []
5050

5151
for line in git(["status", "--porcelain"]):
@@ -60,7 +60,8 @@ def find_changed_files(merge_base: str = "origin/master") -> List[str]:
6060
cached = git(["diff", "--cached", "--name-only"])
6161

6262
# Committed
63-
diff_with_origin = git(["diff", "--name-only", "--merge-base", merge_base, "HEAD"])
63+
merge_base = git(["merge-base", "origin/master", "HEAD"])[0]
64+
diff_with_origin = git(["diff", "--name-only", merge_base, "HEAD"])
6465

6566
# De-duplicate
6667
all_files = set(untracked + cached + modified + diff_with_origin)
@@ -163,14 +164,25 @@ def main() -> None:
163164
)
164165
args = parser.parse_args()
165166

166-
changed_files = None
167+
relevant_files = None
168+
167169
if args.changed_only:
168-
changed_files = []
169-
for f in find_changed_files():
170-
for file_filter in args.file_filter:
171-
if f.endswith(file_filter):
172-
changed_files.append(f)
173-
break
170+
changed_files: Optional[List[str]] = None
171+
try:
172+
changed_files = find_changed_files()
173+
except Exception:
174+
# If the git commands failed for some reason, bail out and use the whole list
175+
print(
176+
"Could not query git for changed files, falling back to testing all files instead",
177+
file=sys.stderr
178+
)
179+
if changed_files is not None:
180+
relevant_files = []
181+
for f in changed_files:
182+
for file_filter in args.file_filter:
183+
if f.endswith(file_filter):
184+
relevant_files.append(f)
185+
break
174186

175187
if args.step is None and args.all_steps_after is None:
176188
raise RuntimeError("1+ --steps or --all-steps-after must be provided")
@@ -193,7 +205,10 @@ def main() -> None:
193205
else:
194206
relevant_steps = grab_all_steps_after(args.all_steps_after, job)
195207

196-
asyncio.run(run_steps(relevant_steps, args.job, changed_files)) # type: ignore[attr-defined]
208+
if sys.version_info > (3, 7):
209+
asyncio.run(run_steps(relevant_steps, args.job, relevant_files))
210+
else:
211+
raise RuntimeError("Only Python >3.7 is supported")
197212

198213

199214
if __name__ == "__main__":

0 commit comments

Comments
 (0)