Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 37 additions & 8 deletions src/colablinter/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
"--unsafe-fixes",
"--select",
"B,E,F,I,UP,SIM",
"--ignore",
"F401,E501",
"--stdin-filename=tmp.py",
]
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",
Expand Down
7 changes: 4 additions & 3 deletions src/colablinter/magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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. "
Expand All @@ -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}")
Expand Down
Loading