From cc6b720799cbc744103d9c60a3c6be8078800b3a Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 20 Apr 2026 18:36:00 +0900 Subject: [PATCH 1/2] set command as list[str] --- src/colablinter/command.py | 45 +++++++++++++++++++++++++++++++------- src/colablinter/magics.py | 7 +++--- 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/src/colablinter/command.py b/src/colablinter/command.py index a10f4d4..1545609 100644 --- a/src/colablinter/command.py +++ b/src/colablinter/command.py @@ -2,20 +2,49 @@ from colablinter.logger import logger -CELL_CHECK_COMMAND = ( - "ruff check --select B,E,F,I,UP,SIM --ignore F401,E501 --stdin-filename=tmp.py" -) -CELL_CHECK_FIX_COMMAND = "ruff check --fix --select B,E,F,I,UP,SIM --ignore F401,E501 --stdin-filename=tmp.py" -CELL_CHECK_UNSAFE_FIX_COMMAND = "ruff check --fix --select B,E,F,I,UP,SIM --ignore F401,E501 --stdin-filename=tmp.py --unsafe-fixes" -CELL_FORMAT_COMMAND = "ruff format --stdin-filename=tmp.py" +CELL_CHECK_COMMAND = [ + "ruff", + "check", + "--select", + "B,E,F,I,UP,SIM", + "--ignore", + "F401,E501", + "--stdin-filename=tmp.py", +] +CELL_CHECK_FIX_COMMAND = [ + "ruff", + "check", + "--fix", + "--select", + "B,E,F,I,UP,SIM", + "--ignore", + "F401,E501", + "--stdin-filename=tmp.py", +] +CELL_CHECK_UNSAFE_FIX_COMMAND = [ + "ruff", + "check", + "--fix", + "--select", + "B,E,F,I,UP,SIM", + "--ignore", + "F401,E501", + "--stdin-filename=tmp.py", + "--unsafe-fixes", +] +CELL_FORMAT_COMMAND = [ + "ruff", + "format", + "--stdin-filename=tmp.py", +] -def execute_command(command: str, input_data: str) -> str | None: +def execute_command(command: list[str], input_data: str) -> str | None: try: result = subprocess.run( command, input=input_data, - shell=True, + shell=False, capture_output=True, text=True, encoding="utf-8", diff --git a/src/colablinter/magics.py b/src/colablinter/magics.py index fa2f0d1..9874fb8 100644 --- a/src/colablinter/magics.py +++ b/src/colablinter/magics.py @@ -29,7 +29,7 @@ def clcheck(self, line: str, cell: str) -> None: @cell_magic def clunsafefix(self, line: str, cell: str) -> None: if self.shell is None: - raise Exception + raise RuntimeError("IPython shell is not initialized.") stripped_cell = cell.strip() fixed_code = cell_check_unsafe_fix(stripped_cell) @@ -54,6 +54,9 @@ def clautofix(self, line: str) -> None: logger.info("Usage: %clautofix on or %clautofix off.") def __execute(self, cell: str) -> None: + if self.shell is None: + raise RuntimeError("IPython shell is not initialized.") + if self._is_autofix_active: logger.info( "autofix is temporarily suppressed to prevent dual execution. " @@ -62,8 +65,6 @@ def __execute(self, cell: str) -> None: self.__unregister() try: - if self.shell is None: - raise Exception self.shell.run_cell(cell, silent=False, store_history=True) except Exception as e: logger.exception(f"Code execution failed: {e}") From 925fb995bb2f4356089539ad26fb01fb95e4a10a Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 21 Apr 2026 09:11:24 +0900 Subject: [PATCH 2/2] unsafe fix order switch --- src/colablinter/command.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/colablinter/command.py b/src/colablinter/command.py index 1545609..ad2c1e4 100644 --- a/src/colablinter/command.py +++ b/src/colablinter/command.py @@ -25,12 +25,12 @@ "ruff", "check", "--fix", + "--unsafe-fixes", "--select", "B,E,F,I,UP,SIM", "--ignore", "F401,E501", "--stdin-filename=tmp.py", - "--unsafe-fixes", ] CELL_FORMAT_COMMAND = [ "ruff",