Use Black to format Python files (#14161)
Switch from yapf to Black to better align with the LLVM and broader
Python community. I decided not to go with Pyink as it seems much less
popular and differs in formatting style beyond indentation.
- Reformat all python files outside of `third_party` with black.
- Update the lint workflow to use black. This only considers files
modified by the PR.
- Delete old dotfiles.
The command used to reformat all files at once:
```shell
fd -e py --exclude third_party | xargs black
```
To learn more about Back, see: https://black.readthedocs.io/en/stable/
and https://github.com/psf/black.
In the next PR, once the commit SHA of this PR is finalized, I plan to
add this commit to `.git-blame-ignore-revs` to keep the blame history
clean.
Issue: https://github.com/openxla/iree/issues/14135
diff --git a/build_tools/scripts/generate_release_index.py b/build_tools/scripts/generate_release_index.py
index 0e7ea94..70a4eeb 100755
--- a/build_tools/scripts/generate_release_index.py
+++ b/build_tools/scripts/generate_release_index.py
@@ -19,63 +19,74 @@
def parse_arguments():
- parser = argparse.ArgumentParser()
- parser.add_argument("--repo",
- "--repository",
- default="openxla/iree",
- help="The GitHub repository to fetch releases from.")
- parser.add_argument(
- "--output",
- default="-",
- help="The file to write the HTML to or '-' for stdout (the default)")
- return parser.parse_args()
+ parser = argparse.ArgumentParser()
+ parser.add_argument(
+ "--repo",
+ "--repository",
+ default="openxla/iree",
+ help="The GitHub repository to fetch releases from.",
+ )
+ parser.add_argument(
+ "--output",
+ default="-",
+ help="The file to write the HTML to or '-' for stdout (the default)",
+ )
+ return parser.parse_args()
class ReleaseFetcher:
+ def __init__(self, repo, per_page=100):
+ self._session = requests.Session()
+ self._repo = repo
+ self._per_page = per_page
- def __init__(self, repo, per_page=100):
- self._session = requests.Session()
- self._repo = repo
- self._per_page = per_page
+ def get_all(self):
+ url = f"https://api.github.com/repos/{self._repo}/releases"
+ page = 1
- def get_all(self):
- url = f"https://api.github.com/repos/{self._repo}/releases"
- page = 1
-
- while True:
- response = self._session.get(url,
- params={
- "page": page,
- "per_page": self._per_page,
- })
- for release in response.json():
- yield release
- if "next" not in response.links:
- break
- page += 1
+ while True:
+ response = self._session.get(
+ url,
+ params={
+ "page": page,
+ "per_page": self._per_page,
+ },
+ )
+ for release in response.json():
+ yield release
+ if "next" not in response.links:
+ break
+ page += 1
def main(args):
- fetcher = ReleaseFetcher(repo=args.repo)
- with (sys.stdout if args.output == "-" else open(args.output, "w")) as f:
- f.write(
- textwrap.dedent("""\
+ fetcher = ReleaseFetcher(repo=args.repo)
+ with sys.stdout if args.output == "-" else open(args.output, "w") as f:
+ f.write(
+ textwrap.dedent(
+ """\
<!DOCTYPE html>
<html>
<body>
- """))
- for release in fetcher.get_all():
- if release["draft"]:
- continue
- for asset in release["assets"]:
- url = html.escape(asset['browser_download_url'])
- name = html.escape(asset['name'])
- f.write(f" <a href={url}>{name}</a><br />\n")
- f.write(textwrap.dedent("""\
+ """
+ )
+ )
+ for release in fetcher.get_all():
+ if release["draft"]:
+ continue
+ for asset in release["assets"]:
+ url = html.escape(asset["browser_download_url"])
+ name = html.escape(asset["name"])
+ f.write(f" <a href={url}>{name}</a><br />\n")
+ f.write(
+ textwrap.dedent(
+ """\
</body>
</html>
- """))
+ """
+ )
+ )
if __name__ == "__main__":
- main(parse_arguments())
+ main(parse_arguments())