diff --git a/pyproject.toml b/pyproject.toml index b9d2e73..64612d7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,7 +23,7 @@ classifiers = [ ] keywords = ["cedarscript", "code-editing", "refactoring", "code-analysis", "sql-like", "ai-assisted-development"] dependencies = [ - "cedarscript-ast-parser>=0.2.0", + "cedarscript-ast-parser>=0.2.1", "rope>=1.13.0" ] requires-python = ">=3.8" diff --git a/src/cedarscript_editor/__init__.py b/src/cedarscript_editor/__init__.py index 6f0f36e..cf7c7f3 100644 --- a/src/cedarscript_editor/__init__.py +++ b/src/cedarscript_editor/__init__.py @@ -1,6 +1,6 @@ from cedarscript_editor.cedarscript_editor import CEDARScriptEditor -__version__ = "0.2.0" +__version__ = "0.2.1" __all__ = ["CEDARScriptEditor"] diff --git a/src/cedarscript_editor/cedarscript_editor.py b/src/cedarscript_editor/cedarscript_editor.py index 39eeebe..2313c35 100644 --- a/src/cedarscript_editor/cedarscript_editor.py +++ b/src/cedarscript_editor/cedarscript_editor.py @@ -38,20 +38,23 @@ def __init__(self, command_ordinal: int, description: str): if 'syntax' in description.casefold(): probability_indicator = "most probably" else: - probability_indicator= "might have" + probability_indicator = "might have" note = ( - f"*ALL* commands *before* command #{command_ordinal} were applied and *their changes are already committed*. " + f"*ALL* commands *before* command #{command_ordinal} " + "were applied and *their changes are already committed*. " f"Re-read the file to catch up with the applied changes." - f"ATTENTION: The previous command (#{command_ordinal - 1}) {probability_indicator} caused command #{command_ordinal} to fail " + f"ATTENTION: The previous command (#{command_ordinal - 1}) {probability_indicator} " + f"caused command #{command_ordinal} to fail " f"due to changes that left the file in an invalid state (check that by re-analyzing the file!)" ) super().__init__( f"COMMAND #{command_ordinal}{note}" f"{description}" - "NEVER apologize; just relax, take a deep breath, think step-by-step and write an in-depth analysis of what went wrong " - "(specifying which command ordinal failed), then acknowledge which commands were already applied and concisely describe the state at which the file was left " - "(saying what needs to be done now), " + "NEVER apologize; just relax, take a deep breath, think step-by-step and write " + "an in-depth analysis of what went wrong (specifying which command ordinal failed), " + "then acknowledge which commands were already applied and concisely describe " + "the state at which the file was left (saying what needs to be done now), " f"then write new commands that will fix the problem{previous_cmd_notes} " "(you'll get a one-million dollar tip if you get it right!) " "Use descriptive comment before each command." @@ -85,9 +88,9 @@ def apply_commands(self, commands: Sequence[Command]): # result.append(self._create_command(cmd)) case RmFileCommand() as cmd: result.append(self._rm_command(cmd)) - case MvFileCommand() as cmd: + case MvFileCommand(): raise ValueError('Noy implemented: MV') - case SelectCommand() as cmd: + case SelectCommand(): raise ValueError('Noy implemented: SELECT') case _ as invalid: raise ValueError(f"Unknown command '{type(invalid)}'") @@ -208,7 +211,8 @@ def identifier_resolver(m: Marker): return f"Updated {target if target else 'file'} in {file_path}\n -> {action}" - def _apply_action(self, action: EditingAction, lines: Sequence[str], range_spec: RangeSpec, content: str | None = None): + @staticmethod + def _apply_action(action: EditingAction, lines: Sequence[str], range_spec: RangeSpec, content: str | None = None): match action: case MoveClause(insert_position=insert_position, to_other_file=other_file, relative_indentation=relindent): diff --git a/src/text_manipulation/indentation_kit.py b/src/text_manipulation/indentation_kit.py index f339dd0..1cf7d76 100644 --- a/src/text_manipulation/indentation_kit.py +++ b/src/text_manipulation/indentation_kit.py @@ -1,4 +1,3 @@ -import re from collections import Counter from collections.abc import Sequence from math import gcd @@ -225,7 +224,10 @@ def apply_relative_indents[S: Sequence[str]](self, content: str | S, context_ind if len(parts) == 2 and parts[0].startswith('@'): relative_indent_level = int(parts[0][1:]) absolute_indent_level = context_indent_level + relative_indent_level - assert absolute_indent_level >= 0, f"Final indentation for line `{line.strip()}` cannot be negative ({absolute_indent_level})" + assert absolute_indent_level >= 0, ( + f"Final indentation for line `{line.strip()}` cannot be negative " + f"({absolute_indent_level})" + ) lines[i] = self.level_to_chars(absolute_indent_level) + parts[1].lstrip() else: absolute_indent_level = context_indent_level diff --git a/src/text_manipulation/range_spec.py b/src/text_manipulation/range_spec.py index 5d882a4..eb6003a 100644 --- a/src/text_manipulation/range_spec.py +++ b/src/text_manipulation/range_spec.py @@ -106,8 +106,14 @@ def from_line_marker[T: RangeSpec]( if search_end_index < 0: search_end_index = len(lines) - assert search_start_index < len(lines), f"search start index ({search_start_index}) must be less than line count ({len(lines)})" - assert search_end_index <= len(lines), f"search end index ({search_end_index}) must be less than or equal to line count ({len(lines)})" + assert search_start_index < len(lines), ( + f"search start index ({search_start_index}) " + f"must be less than line count ({len(lines)})" + ) + assert search_end_index <= len(lines), ( + f"search end index ({search_end_index}) " + f"must be less than or equal to line count ({len(lines)})" + ) for i in range(search_start_index, search_end_index): line = lines[i] diff --git a/src/text_manipulation/text_editor_kit.py b/src/text_manipulation/text_editor_kit.py index 29e43f3..15e4d10 100644 --- a/src/text_manipulation/text_editor_kit.py +++ b/src/text_manipulation/text_editor_kit.py @@ -56,7 +56,11 @@ def marker_or_segment_to_search_range_impl( match self: case Marker(type=MarkerType.LINE): result = RangeSpec.from_line_marker(lines, self, search_range) - assert result is not None, f"Unable to find `{self}`; Try: 1) Double-checking the marker (maybe you specified the the wrong one); or 2) using *exactly* the same characters from source; or 3) using another marker" + assert result is not None, ( + f"Unable to find `{self}`; Try: 1) Double-checking the marker " + f"(maybe you specified the the wrong one); or 2) using *exactly* the same characters from source; " + f"or 3) using another marker" + ) # TODO check under which circumstances we should return a 1-line range instead of an empty range return result case Segment(start=s, end=e): @@ -77,7 +81,11 @@ def segment_to_search_range( assert len(lines), "`lines` is empty" start_match_result = RangeSpec.from_line_marker(lines, start_relpos, search_range) - assert start_match_result, f"Unable to find segment start `{start_relpos}`; Try: 1) Double-checking the marker (maybe you specified the the wrong one); or 2) using *exactly* the same characters from source; or 3) using a marker from above" + assert start_match_result, ( + f"Unable to find segment start `{start_relpos}`; Try: " + f"1) Double-checking the marker (maybe you specified the the wrong one); or " + f"2) using *exactly* the same characters from source; or 3) using a marker from above" + ) start_index_for_end_marker = start_match_result.as_index if start_relpos.qualifier == RelativePositionType.AFTER: