From f9723cfdfc65766d4e2e9f8dcb81901c4f05bf05 Mon Sep 17 00:00:00 2001 From: Elifarley Date: Sat, 12 Oct 2024 11:44:27 -0300 Subject: [PATCH 001/110] cedarscript-ast-parser>=0.2.0 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 4d629ee..b9d2e73 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.1.6", + "cedarscript-ast-parser>=0.2.0", "rope>=1.13.0" ] requires-python = ">=3.8" From 4ae12e622940666cce87641bb981d7d6c2fd6142 Mon Sep 17 00:00:00 2001 From: Elifarley Date: Sat, 12 Oct 2024 12:22:23 -0300 Subject: [PATCH 002/110] Small fixes --- src/cedarscript_editor/cedarscript_editor.py | 22 ++++++++++++-------- src/text_manipulation/indentation_kit.py | 6 ++++-- src/text_manipulation/range_spec.py | 10 +++++++-- src/text_manipulation/text_editor_kit.py | 12 +++++++++-- 4 files changed, 35 insertions(+), 15 deletions(-) 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: From 61e8945e9e2514c1f0b4a98ffd3096c81a650c4a Mon Sep 17 00:00:00 2001 From: Elifarley Date: Sat, 12 Oct 2024 15:20:14 -0300 Subject: [PATCH 003/110] Updated dependency: cedarscript-ast-parser>=0.2.1 #2 --- pyproject.toml | 2 +- src/cedarscript_editor/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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"] From f3e7320f40c16d7e3f16da1f14d8113ba64777ff Mon Sep 17 00:00:00 2001 From: Elifarley Date: Sat, 12 Oct 2024 15:43:53 -0300 Subject: [PATCH 004/110] Updated dependency: cedarscript-ast-parser>=0.2.2 --- pyproject.toml | 2 +- src/cedarscript_editor/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 64612d7..76cff4d 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.1", + "cedarscript-ast-parser>=0.2.2", "rope>=1.13.0" ] requires-python = ">=3.8" diff --git a/src/cedarscript_editor/__init__.py b/src/cedarscript_editor/__init__.py index cf7c7f3..22a64b8 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.1" +__version__ = "0.2.2" __all__ = ["CEDARScriptEditor"] From 737cfb38b5ca0956586e1f5f053ec3ad533c11cb Mon Sep 17 00:00:00 2001 From: Elifarley Date: Sat, 12 Oct 2024 17:13:54 -0300 Subject: [PATCH 005/110] fix: Correct relative import for 'text_manipulation' in `cedarscript_editor.py` --- src/cedarscript_editor/__init__.py | 2 +- src/cedarscript_editor/cedarscript_editor.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cedarscript_editor/__init__.py b/src/cedarscript_editor/__init__.py index 22a64b8..8cef6dc 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.2" +__version__ = "0.2.3" __all__ = ["CEDARScriptEditor"] diff --git a/src/cedarscript_editor/cedarscript_editor.py b/src/cedarscript_editor/cedarscript_editor.py index 2313c35..4d84147 100644 --- a/src/cedarscript_editor/cedarscript_editor.py +++ b/src/cedarscript_editor/cedarscript_editor.py @@ -7,9 +7,9 @@ InsertClause, ReplaceClause, EditingAction, BodyOrWhole, RegionClause, MarkerType from cedarscript_ast_parser.cedarscript_ast_parser import MarkerCompatible, RelativeMarker, \ RelativePositionType -from text_manipulation.indentation_kit import IndentationInfo -from text_manipulation.range_spec import IdentifierBoundaries, RangeSpec -from text_manipulation.text_editor_kit import read_file, write_file, bow_to_search_range +from ..text_manipulation.indentation_kit import IndentationInfo +from ..text_manipulation.range_spec import IdentifierBoundaries, RangeSpec +from ..text_manipulation.text_editor_kit import read_file, write_file, bow_to_search_range from .identifier_selector import select_finder From 0cfa8e9604f74d697f79c359a5484b3543c0934a Mon Sep 17 00:00:00 2001 From: Elifarley Date: Thu, 17 Oct 2024 00:03:22 -0300 Subject: [PATCH 006/110] Use setuptools_scm --- pyproject.toml | 32 ++++++++++++++++++------------ src/cedarscript_editor/__init__.py | 10 ++++++++-- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 76cff4d..6896877 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,16 +1,15 @@ [build-system] -requires = ["setuptools>=61.0", "wheel"] +requires = ["setuptools>=61.0", "wheel", "setuptools_scm[toml]>=6.2"] build-backend = "setuptools.build_meta" [project] name = "cedarscript-editor" dynamic = ["version"] description = "A library for executing CEDARScript, a SQL-like language for code analysis and transformations" +authors = [{ name = "Elifarley", email = "cedarscript@orgecc.com" }] readme = "README.md" -authors = [{ name = "Elifarley", email = "elifarley@example.com" }] -license = { file = "LICENSE" } +license = {text = "MIT"} classifiers = [ - "Development Status :: 3 - Alpha", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.12", "License :: OSI Approved :: MIT License", @@ -23,10 +22,10 @@ classifiers = [ ] keywords = ["cedarscript", "code-editing", "refactoring", "code-analysis", "sql-like", "ai-assisted-development"] dependencies = [ - "cedarscript-ast-parser>=0.2.2", + "cedarscript-ast-parser>=0.2.3", "rope>=1.13.0" ] -requires-python = ">=3.8" +requires-python = ">=3.11" [project.urls] Homepage = "https://github.com/CEDARScript/cedarscript-editor-python" @@ -47,15 +46,20 @@ dev = [ [tool.setuptools] package-dir = {"" = "src"} -py-modules = ["cedarscript_editor", "text_manipulaiton"] -[tool.setuptools.dynamic] -version = {attr = "cedarscript_editor.__version__"} +[tool.setuptools_scm] +# To override version: +# >>> SETUPTOOLS_SCM_PRETEND_VERSION=0.0.2 python -m build +# To dry-run and see version: +# >>> python -m setuptools_scm +write_to = "src/cedarscript_editor/_version.py" +# Append .post{number of commits} to your version if there are commits after the last tag. +version_scheme = "post-release" [tool.setuptools.packages.find] where = ["src"] -include = ["cedarscript_editor*", "text_editor*", "identifier_selector*", "*identifier_finder*", -"indentation_*", "range_*"] +include = ["cedarscript_editor*", "text_manipulaiton*"] +exclude = ["cedarscript_ast_parser.tests*"] namespaces = false [tool.setuptools.package-data] @@ -63,15 +67,17 @@ namespaces = false [tool.black] line-length = 100 -target-version = ['py312'] +target-version = ['py311'] [tool.isort] profile = "black" line_length = 100 [tool.mypy] -ignore_missing_imports = true +python_version = "3.11" strict = true +warn_return_any = true +warn_unused_configs = true [tool.pytest.ini_options] minversion = "6.0" diff --git a/src/cedarscript_editor/__init__.py b/src/cedarscript_editor/__init__.py index 8cef6dc..9c42812 100644 --- a/src/cedarscript_editor/__init__.py +++ b/src/cedarscript_editor/__init__.py @@ -1,6 +1,12 @@ -from cedarscript_editor.cedarscript_editor import CEDARScriptEditor +from ._version import __version__ +import re +from .cedarscript_editor import CEDARScriptEditor +from text_manipulation import IndentationInfo, IdentifierBoundaries, RangeSpec, read_file, write_file, bow_to_search_range -__version__ = "0.2.3" +__all__ = [ + "__version__", "find_commands", "CEDARScriptEditor", "IndentationInfo", "IdentifierBoundaries", "RangeSpec", + "read_file", "write_file", "bow_to_search_range" +] __all__ = ["CEDARScriptEditor"] From 9f5f65552a621951de7ecdd60545313ffb22a6d5 Mon Sep 17 00:00:00 2001 From: Elifarley Date: Thu, 17 Oct 2024 00:08:50 -0300 Subject: [PATCH 007/110] Reorganization --- src/cedarscript_editor/__init__.py | 20 ++++++++++++++++++-- src/cedarscript_editor/cedarscript_editor.py | 6 +++--- src/text_manipulation/__init__.py | 12 ++++++++++++ src/text_manipulation/indentation_kit.py | 4 ++-- src/text_manipulation/range_spec.py | 14 +++++++------- src/text_manipulation/text_editor_kit.py | 2 +- 6 files changed, 43 insertions(+), 15 deletions(-) diff --git a/src/cedarscript_editor/__init__.py b/src/cedarscript_editor/__init__.py index 9c42812..a675862 100644 --- a/src/cedarscript_editor/__init__.py +++ b/src/cedarscript_editor/__init__.py @@ -8,5 +8,21 @@ "read_file", "write_file", "bow_to_search_range" ] -__all__ = ["CEDARScriptEditor"] - +def find_commands(content: str): + # Regex pattern to match CEDARScript blocks + pattern = r'```CEDARScript\n(.*?)```' + cedar_script_blocks = re.findall(pattern, content, re.DOTALL) + print(f'[find_cedar_commands] Script block count: {len(cedar_script_blocks)}') + if len(cedar_script_blocks) == 0: + raise ValueError( + "No CEDARScript block detected. " + "Perhaps you forgot to enclose the block using ```CEDARScript and ``` ? " + "Or was that intentional? If so, just write tag