From 789573a72a5c481481f621e327aaa0b49afe2fe4 Mon Sep 17 00:00:00 2001
From: Reid 'arrdem' McKenzie <me@arrdem.com>
Date: Sun, 29 Aug 2021 22:17:57 -0600
Subject: [PATCH] More breaking out

---
 tools/fmt.sh                                  | 18 ++++++++++-----
 tools/lint.sh                                 | 22 ++++++++++++-------
 tools/openapi/BUILD                           |  7 ++++++
 .../openapi_shim.py => openapi/__main__.py}   |  2 --
 tools/python/BUILD                            |  8 -------
 tools/python/requirements.txt                 |  5 -----
 6 files changed, 34 insertions(+), 28 deletions(-)
 create mode 100644 tools/openapi/BUILD
 rename tools/{python/openapi_shim.py => openapi/__main__.py} (91%)

diff --git a/tools/fmt.sh b/tools/fmt.sh
index e51f6e3..bb5fc35 100755
--- a/tools/fmt.sh
+++ b/tools/fmt.sh
@@ -2,11 +2,19 @@
 set -euox pipefail
 cd "$(git rev-parse --show-toplevel)"
 
-bazel build //tools/python/... //projects/reqman
+bazel build //tools/... //projects/reqman
 
 DIRS=(projects tools)
 
-bazel-bin/tools/python/autoflake -ir "${DIRS[@]}"
-bazel-bin/tools/python/isort "${DIRS[@]}"
-bazel-bin/tools/python/unify --quote '"' -ir "${DIRS[@]}"
-bazel-bin/projects/reqman/reqman clean tools/python/requirements.txt
+function brl() {
+    bin="$1"
+    shift
+    bazel build "//${bin}"
+    "bazel-bin/${bin}/$(basename ${bin})" "$@"
+    return "$?"
+}
+
+brl tools/autoflake -ir "${DIRS[@]}"
+brl tools/isort     "${DIRS[@]}"
+brl tools/unify     --quote '"' -ir "${DIRS[@]}"
+brl projects/reqman clean tools/python/requirements.txt
diff --git a/tools/lint.sh b/tools/lint.sh
index 038073b..768283f 100755
--- a/tools/lint.sh
+++ b/tools/lint.sh
@@ -5,15 +5,21 @@ bazel build //tools/python/...
 
 DIRS=(tools projects)
 
-bazel-bin/tools/python/autoflake -r "${DIRS[@]}"
-bazel-bin/tools/python/isort --check "${DIRS[@]}"
-bazel-bin/tools/python/unify --quote '"' -cr "${DIRS[@]}"
-bazel-bin/projects/reqman/reqman lint tools/python/requirements.txt
+function brl() {
+    bin="$1"
+    shift
+    bazel build "//${bin}"
+    "bazel-bin/${bin}/$(basename ${bin})" "$@"
+    return "$?"
+}
 
-for f in $(find . -type f -name "openapi.yaml"); do
-  bazel-bin/tools/python/openapi "${f}" && echo "Schema $f OK"
-done
+brl tools/autoflake -r "${DIRS[@]}"
+brl tools/isort --check "${DIRS[@]}"
+brl tools/unify --quote '"' -cr "${DIRS[@]}"
+brl tools/reqman lint tools/python/requirements.txt
 
+# OpenAPI specific junk
 for f in $(find . -type f -name "openapi.yaml"); do
-  bazel-bin/tools/python/yamllint -c tools/yamllint/yamllintrc "${f}"
+  brl tools/openapi "${f}" && echo "Schema $f OK"
+  brl tools/yamllint -c tools/yamllint/yamllintrc "${f}"
 done
diff --git a/tools/openapi/BUILD b/tools/openapi/BUILD
new file mode 100644
index 0000000..a163d91
--- /dev/null
+++ b/tools/openapi/BUILD
@@ -0,0 +1,7 @@
+py_binary(
+    name = "openapi",
+    main = "__main__.py",
+    deps = [
+        py_requirement("openapi-spec-validator"),
+    ]
+)
diff --git a/tools/python/openapi_shim.py b/tools/openapi/__main__.py
similarity index 91%
rename from tools/python/openapi_shim.py
rename to tools/openapi/__main__.py
index bddcae1..828ca7d 100644
--- a/tools/python/openapi_shim.py
+++ b/tools/openapi/__main__.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python3
-
 """Shim for executing the openapi spec validator."""
 
 import re
diff --git a/tools/python/BUILD b/tools/python/BUILD
index 9181e39..024e500 100644
--- a/tools/python/BUILD
+++ b/tools/python/BUILD
@@ -45,11 +45,3 @@ py_pytest(
         py_requirement("requirements-parser"),
     ]
 )
-
-py_binary(
-    name = "openapi",
-    main = "openapi_shim.py",
-    deps = [
-        py_requirement("openapi-spec-validator"),
-    ]
-)
diff --git a/tools/python/requirements.txt b/tools/python/requirements.txt
index 7dd9708..8983238 100644
--- a/tools/python/requirements.txt
+++ b/tools/python/requirements.txt
@@ -5,7 +5,6 @@ attrs==20.3.0
 autoflake==1.4
 Babel==2.9.0
 beautifulsoup4==4.9.3
-bleach==4.0.0
 certifi==2020.12.5
 chardet==4.0.0
 click==7.1.2
@@ -40,7 +39,6 @@ openapi-spec-validator==0.3.0
 packaging==20.9
 parso==0.8.2
 pathspec==0.8.1
-pep517==0.11.0
 pip-tools==6.2.0
 pluggy==0.13.1
 port-for==0.6.1
@@ -80,7 +78,6 @@ sphinxcontrib-programoutput==0.17
 sphinxcontrib-qthelp==1.0.3
 sphinxcontrib-serializinghtml==1.1.4
 toml==0.10.2
-tomli==1.2.1
 tornado==6.1
 typed-ast==1.4.2
 typing-extensions==3.7.4.3
@@ -89,9 +86,7 @@ untokenize==0.1.1
 urllib3==1.26.4
 urwid==2.1.2
 wcwidth==0.2.5
-webencodings==0.5.1
 Werkzeug==2.0.1
 yamllint==1.26.1
 yarl==1.6.3
 yaspin==1.5.0
-zipp==3.5.0