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/samples/colab/test_notebooks.py b/samples/colab/test_notebooks.py
index a714bae..8dbbba2 100755
--- a/samples/colab/test_notebooks.py
+++ b/samples/colab/test_notebooks.py
@@ -24,36 +24,37 @@
class ColabNotebookTests(unittest.TestCase):
- """Tests running all Colab notebooks in this directory."""
+ """Tests running all Colab notebooks in this directory."""
- @classmethod
- def generateTests(cls):
- repo_root = os.path.dirname(
- os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
- script_path = os.path.join(repo_root,
- "build_tools/testing/run_python_notebook.sh")
+ @classmethod
+ def generateTests(cls):
+ repo_root = os.path.dirname(
+ os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+ )
+ script_path = os.path.join(
+ repo_root, "build_tools/testing/run_python_notebook.sh"
+ )
- # Create a test case for each notebook in this folder.
- notebooks_path = os.path.join(repo_root, "samples/colab/")
- for notebook_path in glob.glob(notebooks_path + "*.ipynb"):
- notebook_name = os.path.basename(notebook_path)
+ # Create a test case for each notebook in this folder.
+ notebooks_path = os.path.join(repo_root, "samples/colab/")
+ for notebook_path in glob.glob(notebooks_path + "*.ipynb"):
+ notebook_name = os.path.basename(notebook_path)
- def unit_test(self, notebook_path=notebook_path):
+ def unit_test(self, notebook_path=notebook_path):
+ completed_process = subprocess.run([script_path, notebook_path])
+ self.assertEqual(completed_process.returncode, 0)
- completed_process = subprocess.run([script_path, notebook_path])
- self.assertEqual(completed_process.returncode, 0)
+ if notebook_name in NOTEBOOKS_TO_SKIP:
+ unit_test = unittest.skip("Skip requested")(unit_test)
+ elif notebook_name in NOTEBOOKS_EXPECTED_TO_FAIL:
+ unit_test = unittest.expectedFailure(unit_test)
- if notebook_name in NOTEBOOKS_TO_SKIP:
- unit_test = unittest.skip("Skip requested")(unit_test)
- elif notebook_name in NOTEBOOKS_EXPECTED_TO_FAIL:
- unit_test = unittest.expectedFailure(unit_test)
-
- # Add 'unit_test' to this class, so the test runner runs it.
- unit_test.__name__ = f"test_{notebook_name}"
- setattr(cls, unit_test.__name__, unit_test)
+ # Add 'unit_test' to this class, so the test runner runs it.
+ unit_test.__name__ = f"test_{notebook_name}"
+ setattr(cls, unit_test.__name__, unit_test)
if __name__ == "__main__":
- ColabNotebookTests.generateTests()
- logging.basicConfig(level=logging.DEBUG)
- unittest.main()
+ ColabNotebookTests.generateTests()
+ logging.basicConfig(level=logging.DEBUG)
+ unittest.main()