From ad2c86fe05b43135ddc67465220c7b5f1663d3f0 Mon Sep 17 00:00:00 2001 From: Jeremy Stein Date: Tue, 5 Dec 2023 10:48:27 +0000 Subject: [PATCH 1/2] Fix some ruff errors --- bin/pixldc | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/bin/pixldc b/bin/pixldc index 455ec8a88..023284004 100755 --- a/bin/pixldc +++ b/bin/pixldc @@ -12,10 +12,12 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +"""A wrapper around docker compose that sets the correct directory and environment""" import argparse +import logging import os +from pathlib import Path -# A wrapper around docker compose that sets the correct directory and environment ALLOWED_PROJECT_NAMES = ["pixl_dev", "pixl_test", "pixl_prod"] parser = argparse.ArgumentParser(description="Wrapper around docker compose for pixl") parser.add_argument( @@ -29,10 +31,13 @@ parser.add_argument( parser.add_argument("command", help="Which docker compose command to run") args, unknown_args = parser.parse_known_args() -BIN_DIR = os.path.dirname(__file__) +if args.debug: + logging.basicConfig(level=logging.DEBUG) + +BIN_DIR = Path(__file__).parent.absolute() os.chdir(BIN_DIR) -PROJECT_DIR = os.path.dirname(BIN_DIR) -COMPOSE_FILE = os.path.join(PROJECT_DIR, "docker-compose.yml") +PROJECT_DIR = BIN_DIR.parent.absolute() +COMPOSE_FILE = PROJECT_DIR / "docker-compose.yml" # The first arg is necessary even if it looks repetitive! Equivalent to bash's $0. docker_args = [ @@ -52,9 +57,8 @@ if args.command == "up": # add on the user's extra args docker_args.extend(unknown_args) -if args.debug: - print(f"args = {args}") - print(f"extra args = {unknown_args}") - print(f"about to run with docker: {docker_args}") +logging.debug(f"args = {args}") +logging.debug(f"extra args = {unknown_args}") +logging.debug(f"about to run with docker: {docker_args}") -os.execvp("docker", docker_args) +os.execvp("docker", docker_args) # noqa: S606, S607 this is what the previous script was doing From 251fb3078a810ed8c0857c53e03a7793db17e9e3 Mon Sep 17 00:00:00 2001 From: Jeremy Stein Date: Tue, 5 Dec 2023 11:42:58 +0000 Subject: [PATCH 2/2] Fix f strings in logging for ruff --- bin/pixldc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/pixldc b/bin/pixldc index 023284004..ce4577b70 100755 --- a/bin/pixldc +++ b/bin/pixldc @@ -57,8 +57,8 @@ if args.command == "up": # add on the user's extra args docker_args.extend(unknown_args) -logging.debug(f"args = {args}") -logging.debug(f"extra args = {unknown_args}") -logging.debug(f"about to run with docker: {docker_args}") +logging.debug("args = %s", args) +logging.debug("extra args = %s", unknown_args) +logging.debug("about to run with docker: %s", docker_args) os.execvp("docker", docker_args) # noqa: S606, S607 this is what the previous script was doing