Skip to content

Commit d4850c2

Browse files
authored
Merge pull request #2 from CEDARScript/updated-upstream
Updated dependency: cedarscript-ast-parser>=0.2.1
2 parents f9723cf + 61e8945 commit d4850c2

File tree

6 files changed

+37
-17
lines changed

6 files changed

+37
-17
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ classifiers = [
2323
]
2424
keywords = ["cedarscript", "code-editing", "refactoring", "code-analysis", "sql-like", "ai-assisted-development"]
2525
dependencies = [
26-
"cedarscript-ast-parser>=0.2.0",
26+
"cedarscript-ast-parser>=0.2.1",
2727
"rope>=1.13.0"
2828
]
2929
requires-python = ">=3.8"

src/cedarscript_editor/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from cedarscript_editor.cedarscript_editor import CEDARScriptEditor
22

3-
__version__ = "0.2.0"
3+
__version__ = "0.2.1"
44

55
__all__ = ["CEDARScriptEditor"]
66

src/cedarscript_editor/cedarscript_editor.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,23 @@ def __init__(self, command_ordinal: int, description: str):
3838
if 'syntax' in description.casefold():
3939
probability_indicator = "most probably"
4040
else:
41-
probability_indicator= "might have"
41+
probability_indicator = "might have"
4242

4343
note = (
44-
f"<note>*ALL* commands *before* command #{command_ordinal} were applied and *their changes are already committed*. "
44+
f"<note>*ALL* commands *before* command #{command_ordinal} "
45+
"were applied and *their changes are already committed*. "
4546
f"Re-read the file to catch up with the applied changes."
46-
f"ATTENTION: The previous command (#{command_ordinal - 1}) {probability_indicator} caused command #{command_ordinal} to fail "
47+
f"ATTENTION: The previous command (#{command_ordinal - 1}) {probability_indicator} "
48+
f"caused command #{command_ordinal} to fail "
4749
f"due to changes that left the file in an invalid state (check that by re-analyzing the file!)</note>"
4850
)
4951
super().__init__(
5052
f"<error-details><error-location>COMMAND #{command_ordinal}</error-location>{note}"
5153
f"<description>{description}</description>"
52-
"<suggestion>NEVER apologize; just relax, take a deep breath, think step-by-step and write an in-depth analysis of what went wrong "
53-
"(specifying which command ordinal failed), then acknowledge which commands were already applied and concisely describe the state at which the file was left "
54-
"(saying what needs to be done now), "
54+
"<suggestion>NEVER apologize; just relax, take a deep breath, think step-by-step and write "
55+
"an in-depth analysis of what went wrong (specifying which command ordinal failed), "
56+
"then acknowledge which commands were already applied and concisely describe "
57+
"the state at which the file was left (saying what needs to be done now), "
5558
f"then write new commands that will fix the problem{previous_cmd_notes} "
5659
"(you'll get a one-million dollar tip if you get it right!) "
5760
"Use descriptive comment before each command.</suggestion></error-details>"
@@ -85,9 +88,9 @@ def apply_commands(self, commands: Sequence[Command]):
8588
# result.append(self._create_command(cmd))
8689
case RmFileCommand() as cmd:
8790
result.append(self._rm_command(cmd))
88-
case MvFileCommand() as cmd:
91+
case MvFileCommand():
8992
raise ValueError('Noy implemented: MV')
90-
case SelectCommand() as cmd:
93+
case SelectCommand():
9194
raise ValueError('Noy implemented: SELECT')
9295
case _ as invalid:
9396
raise ValueError(f"Unknown command '{type(invalid)}'")
@@ -208,7 +211,8 @@ def identifier_resolver(m: Marker):
208211

209212
return f"Updated {target if target else 'file'} in {file_path}\n -> {action}"
210213

211-
def _apply_action(self, action: EditingAction, lines: Sequence[str], range_spec: RangeSpec, content: str | None = None):
214+
@staticmethod
215+
def _apply_action(action: EditingAction, lines: Sequence[str], range_spec: RangeSpec, content: str | None = None):
212216
match action:
213217

214218
case MoveClause(insert_position=insert_position, to_other_file=other_file, relative_indentation=relindent):

src/text_manipulation/indentation_kit.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import re
21
from collections import Counter
32
from collections.abc import Sequence
43
from math import gcd
@@ -225,7 +224,10 @@ def apply_relative_indents[S: Sequence[str]](self, content: str | S, context_ind
225224
if len(parts) == 2 and parts[0].startswith('@'):
226225
relative_indent_level = int(parts[0][1:])
227226
absolute_indent_level = context_indent_level + relative_indent_level
228-
assert absolute_indent_level >= 0, f"Final indentation for line `{line.strip()}` cannot be negative ({absolute_indent_level})"
227+
assert absolute_indent_level >= 0, (
228+
f"Final indentation for line `{line.strip()}` cannot be negative "
229+
f"({absolute_indent_level})"
230+
)
229231
lines[i] = self.level_to_chars(absolute_indent_level) + parts[1].lstrip()
230232
else:
231233
absolute_indent_level = context_indent_level

src/text_manipulation/range_spec.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,14 @@ def from_line_marker[T: RangeSpec](
106106
if search_end_index < 0:
107107
search_end_index = len(lines)
108108

109-
assert search_start_index < len(lines), f"search start index ({search_start_index}) must be less than line count ({len(lines)})"
110-
assert search_end_index <= len(lines), f"search end index ({search_end_index}) must be less than or equal to line count ({len(lines)})"
109+
assert search_start_index < len(lines), (
110+
f"search start index ({search_start_index}) "
111+
f"must be less than line count ({len(lines)})"
112+
)
113+
assert search_end_index <= len(lines), (
114+
f"search end index ({search_end_index}) "
115+
f"must be less than or equal to line count ({len(lines)})"
116+
)
111117

112118
for i in range(search_start_index, search_end_index):
113119
line = lines[i]

src/text_manipulation/text_editor_kit.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ def marker_or_segment_to_search_range_impl(
5656
match self:
5757
case Marker(type=MarkerType.LINE):
5858
result = RangeSpec.from_line_marker(lines, self, search_range)
59-
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"
59+
assert result is not None, (
60+
f"Unable to find `{self}`; Try: 1) Double-checking the marker "
61+
f"(maybe you specified the the wrong one); or 2) using *exactly* the same characters from source; "
62+
f"or 3) using another marker"
63+
)
6064
# TODO check under which circumstances we should return a 1-line range instead of an empty range
6165
return result
6266
case Segment(start=s, end=e):
@@ -77,7 +81,11 @@ def segment_to_search_range(
7781
assert len(lines), "`lines` is empty"
7882

7983
start_match_result = RangeSpec.from_line_marker(lines, start_relpos, search_range)
80-
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"
84+
assert start_match_result, (
85+
f"Unable to find segment start `{start_relpos}`; Try: "
86+
f"1) Double-checking the marker (maybe you specified the the wrong one); or "
87+
f"2) using *exactly* the same characters from source; or 3) using a marker from above"
88+
)
8189

8290
start_index_for_end_marker = start_match_result.as_index
8391
if start_relpos.qualifier == RelativePositionType.AFTER:

0 commit comments

Comments
 (0)