From a19914eab31045c0ce5ce9c32c5bc17141df7b2c Mon Sep 17 00:00:00 2001 From: Simeon Widdis Date: Fri, 13 Jun 2025 17:31:38 +0000 Subject: [PATCH 1/3] Add --client arg --- pre_commit_hooks/runner.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pre_commit_hooks/runner.py b/pre_commit_hooks/runner.py index ea9d472..17c7dcf 100644 --- a/pre_commit_hooks/runner.py +++ b/pre_commit_hooks/runner.py @@ -9,6 +9,7 @@ class Opts: project_dir: str | None = None clean: bool = True varargs: dict = field(default_factory=dict) + client: bool = False def default_argparse( @@ -28,12 +29,19 @@ def default_argparse( default=False, help="Turn off sbt clean. Default: False", ) + arg_p.add_argument( + "--client", + action="store_true", + default=False, + help="Run sbt in --client mode, persisting sessions across commits. Default: False", + ) for fn in additional_args: fn(arg_p) varags = vars(arg_p.parse_args(argv)) return Opts( project_dir=varags.pop("project_dir", None), clean=not varags.pop("no_clean", False), + client=varags.pop("client", False), varargs=varags, ) @@ -50,7 +58,7 @@ def run_sbt_command( else: task_def = f"; {task_def}" sbt_process = subprocess.run( - [f"sbt '{task_def}'"], + ["sbt", task_def, "--client" if opts.client else ""], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True, From b0a9f5250295ec66fe3f5cdc56d4a139837e543d Mon Sep 17 00:00:00 2001 From: Simeon Widdis Date: Fri, 13 Jun 2025 17:43:36 +0000 Subject: [PATCH 2/3] Update readme --- README.adoc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.adoc b/README.adoc index d35a7ab..9849c07 100644 --- a/README.adoc +++ b/README.adoc @@ -62,8 +62,9 @@ are relevant for the hook's check. The default is `{defaultScope}`. [NOTE] -- -All hooks have an optional `project-dir` arugument, which is useful for monorepos that do not have a `build.sbt` in their root. -All hooks have an optional `no-clean` arugument, which won't automatically run an `sbt clean` before executing the command. +All hooks have an optional `project-dir` argument, which is useful for monorepos that do not have a `build.sbt` in their root. +All hooks have an optional `no-clean` argument, which won't automatically run an `sbt clean` before executing the command. +All hooks have an optional `client` argument, which will persist the SBT session across invocations on newer SBT versions. -- [IMPORTANT] From e51db1845c66c1b9a278be320dbaa345bd52fb9a Mon Sep 17 00:00:00 2001 From: Simeon Widdis Date: Fri, 13 Jun 2025 17:55:53 +0000 Subject: [PATCH 3/3] Revert to the task_def style that was there before --- pre_commit_hooks/runner.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pre_commit_hooks/runner.py b/pre_commit_hooks/runner.py index 17c7dcf..541b068 100644 --- a/pre_commit_hooks/runner.py +++ b/pre_commit_hooks/runner.py @@ -53,12 +53,13 @@ def run_sbt_command( opts: Opts = Opts(), ): print(f"Running SBT command: {task_def} with options: {opts}") + sbt_args = "--client" if opts.client else "" if opts.clean: task_def = f"; clean ; {task_def}" else: task_def = f"; {task_def}" sbt_process = subprocess.run( - ["sbt", task_def, "--client" if opts.client else ""], + [f"sbt {sbt_args} '{task_def}'"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True,