mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
This has been bugging me for a while as I'm working on these Python scripts and they are not tracked by ufmt linter. So I add these script into that linter.
```
[[linter]]
code = 'UFMT'
include_patterns = [
'.github/**/*.py',
'test/run_test.py',
```
This change should just work and not break anything as ufmt (black + usort) linter is very safe to use for standalone util scripts.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/97588
Approved by: https://github.com/kit1980
30 lines
734 B
Python
Executable File
30 lines
734 B
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import os
|
|
import re
|
|
|
|
|
|
def set_output(name: str, val: str) -> None:
|
|
if os.getenv("GITHUB_OUTPUT"):
|
|
with open(str(os.getenv("GITHUB_OUTPUT")), "a") as env:
|
|
print(f"{name}={val}", file=env)
|
|
else:
|
|
print(f"::set-output name={name}::{val}")
|
|
|
|
|
|
def main() -> None:
|
|
ref = os.environ["GITHUB_REF"]
|
|
m = re.match(r"^refs/(\w+)/(.*)$", ref)
|
|
if m:
|
|
category, stripped = m.groups()
|
|
if category == "heads":
|
|
set_output("branch", stripped)
|
|
elif category == "pull":
|
|
set_output("branch", "pull/" + stripped.split("/")[0])
|
|
elif category == "tags":
|
|
set_output("tag", stripped)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|