Files
pytorch/.github/scripts/export_pytorch_labels.py
Huy Do 4c0dce50fd [BE] Apply ufmt to run_test and GitHub Python util scripts (#97588)
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
2023-03-26 04:52:55 +00:00

41 lines
1.1 KiB
Python
Executable File

#!/usr/bin/env python3
"""
Test ownership was introduced in https://github.com/pytorch/pytorch/issues/66232.
As a part of enforcing test ownership, we want to maintain a list of existing PyTorch labels
to verify the owners' existence. This script outputs a file containing a list of existing
pytorch/pytorch labels so that the file could be uploaded to S3.
This script assumes the correct env vars are set for AWS permissions.
"""
import json
from typing import Any
import boto3 # type: ignore[import]
from label_utils import gh_get_labels
def parse_args() -> Any:
from argparse import ArgumentParser
parser = ArgumentParser("Export PR labels")
parser.add_argument("org", type=str)
parser.add_argument("repo", type=str)
return parser.parse_args()
def main() -> None:
args = parse_args()
print(f"Exporting labels for {args.org}/{args.repo}")
labels_file_name = "pytorch_labels.json"
obj = boto3.resource("s3").Object("ossci-metrics", labels_file_name)
obj.put(Body=json.dumps(gh_get_labels(args.org, args.repo)).encode())
if __name__ == "__main__":
main()