From 4bb88c3592735af0e3cac2371097acda8c2f469f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20de=20Menten?= Date: Thu, 1 Aug 2024 13:59:55 +0200 Subject: [PATCH 1/2] bump version to 0.34.6-dev --- doc/source/changes.rst | 8 +++++ doc/source/changes/version_0_34_6.rst.inc | 41 +++++++++++++++++++++++ larray_editor/__init__.py | 2 +- setup.py | 2 +- 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 doc/source/changes/version_0_34_6.rst.inc diff --git a/doc/source/changes.rst b/doc/source/changes.rst index e61aa4e..cd1efbb 100644 --- a/doc/source/changes.rst +++ b/doc/source/changes.rst @@ -1,6 +1,14 @@ Change log ########## +Version 0.34.6 +============== + +In development. + +.. include:: ./changes/version_0_34_6.rst.inc + + Version 0.34.5 ============== diff --git a/doc/source/changes/version_0_34_6.rst.inc b/doc/source/changes/version_0_34_6.rst.inc new file mode 100644 index 0000000..c4533eb --- /dev/null +++ b/doc/source/changes/version_0_34_6.rst.inc @@ -0,0 +1,41 @@ +.. py:currentmodule:: larray_editor + +Syntax changes +^^^^^^^^^^^^^^ + +* renamed ``MappingEditor.old_method_name()`` to :py:obj:`MappingEditor.new_method_name()` (closes :editor_issue:`1`). + +* renamed ``old_argument_name`` argument of :py:obj:`MappingEditor.method_name()` to ``new_argument_name``. + + +Backward incompatible changes +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +* other backward incompatible changes + + +New features +^^^^^^^^^^^^ + +* added a feature (see the :ref:`miscellaneous section ` for details). + +* added another feature in the editor (closes :editor_issue:`1`). + + .. note:: + + - It works for foo bar ! + - It does not work for foo baz ! + + +.. _misc_editor: + +Miscellaneous improvements +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +* improved something. + + +Fixes +^^^^^ + +* fixed something (closes :editor_issue:`1`). diff --git a/larray_editor/__init__.py b/larray_editor/__init__.py index 2d3b8ad..eaf1982 100644 --- a/larray_editor/__init__.py +++ b/larray_editor/__init__.py @@ -1,3 +1,3 @@ from larray_editor.api import * # noqa: F403 -__version__ = '0.34.5' +__version__ = '0.34.6-dev' diff --git a/setup.py b/setup.py index 9ad2837..09837f4 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ def readlocal(fname): DISTNAME = 'larray-editor' -VERSION = '0.34.5' +VERSION = '0.34.6-dev' AUTHOR = 'Gaetan de Menten, Geert Bryon, Johan Duyck, Alix Damman' AUTHOR_EMAIL = 'gdementen@gmail.com' DESCRIPTION = "Graphical User Interface for LArray library" From 57621eb12bb0c89c3fb0e582ed717048082cac44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20de=20Menten?= Date: Thu, 1 Aug 2024 10:09:16 +0200 Subject: [PATCH 2/2] FIX: fixed some plots not showing in the console expressions like "arr[anything].plot(arg=anything)" were mistakenly considered as inplace updates --- doc/source/changes/version_0_34_6.rst.inc | 40 ++----------------- larray_editor/editor.py | 16 +++++--- .../test_inplace_modification_pattern.py | 32 +++++++++++++++ 3 files changed, 46 insertions(+), 42 deletions(-) create mode 100644 larray_editor/tests/test_inplace_modification_pattern.py diff --git a/doc/source/changes/version_0_34_6.rst.inc b/doc/source/changes/version_0_34_6.rst.inc index c4533eb..3ea2746 100644 --- a/doc/source/changes/version_0_34_6.rst.inc +++ b/doc/source/changes/version_0_34_6.rst.inc @@ -1,41 +1,9 @@ .. py:currentmodule:: larray_editor -Syntax changes -^^^^^^^^^^^^^^ - -* renamed ``MappingEditor.old_method_name()`` to :py:obj:`MappingEditor.new_method_name()` (closes :editor_issue:`1`). - -* renamed ``old_argument_name`` argument of :py:obj:`MappingEditor.method_name()` to ``new_argument_name``. - - -Backward incompatible changes -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -* other backward incompatible changes - - -New features -^^^^^^^^^^^^ - -* added a feature (see the :ref:`miscellaneous section ` for details). - -* added another feature in the editor (closes :editor_issue:`1`). - - .. note:: - - - It works for foo bar ! - - It does not work for foo baz ! - - -.. _misc_editor: - -Miscellaneous improvements -^^^^^^^^^^^^^^^^^^^^^^^^^^ - -* improved something. - - Fixes ^^^^^ -* fixed something (closes :editor_issue:`1`). +* fixed some console plots (again) because a "fix" in the partially done + 0.34.5 release introduced other problems. Sadly, these new problems were + discovered after the release process for 0.34.5 was started, hence the + partial release. \ No newline at end of file diff --git a/larray_editor/editor.py b/larray_editor/editor.py index a06da13..24e2f2d 100644 --- a/larray_editor/editor.py +++ b/larray_editor/editor.py @@ -76,9 +76,13 @@ REOPEN_LAST_FILE = object() -assignment_pattern = re.compile(r'[^\[\]]+[^=]=[^=].+') -setitem_pattern = re.compile(r'(\w+)(\.i|\.iflat|\.points|\.ipoints)?\[.+\][^=]*=[^=].+') -history_vars_pattern = re.compile(r'_i?\d+') +ASSIGNMENT_PATTERN = re.compile(r'[^\[\]]+[^=]=[^=].+') +SUBSET_UPDATE_PATTERN = re.compile(r'(\w+)' + r'(\.i|\.iflat|\.points|\.ipoints)?' + r'\[.+\]\s*' + r'([-+*/%&|^><]|//|\*\*|>>|<<)?' + r'=\s*[^=].*') +HISTORY_VARS_PATTERN = re.compile(r'_i?\d+') # XXX: add all scalars except strings (from numpy or plain Python)? # (long) strings are not handled correctly so should NOT be in this list # tuple, list @@ -668,7 +672,7 @@ def delete_current_item(self): def line_edit_update(self): import larray as la last_input = self.eval_box.text() - if assignment_pattern.match(last_input): + if ASSIGNMENT_PATTERN.match(last_input): context = self.data._objects.copy() exec(last_input, la.__dict__, context) varname = self.update_mapping(context) @@ -690,13 +694,13 @@ def ipython_cell_executed(self): ip_keys = {'In', 'Out', '_', '__', '___', '__builtin__', '_dh', '_ih', '_oh', '_sh', '_i', '_ii', '_iii', 'exit', 'get_ipython', 'quit'} # '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', - clean_ns = {k: v for k, v in user_ns.items() if k not in ip_keys and not history_vars_pattern.match(k)} + clean_ns = {k: v for k, v in user_ns.items() if k not in ip_keys and not HISTORY_VARS_PATTERN.match(k)} # user_ns['_i'] is not updated yet (refers to the -2 item) # 'In' and '_ih' point to the same object (but '_ih' is supposed to be the non-overridden one) cur_input_num = len(user_ns['_ih']) - 1 last_input = user_ns['_ih'][-1] - setitem_match = setitem_pattern.match(last_input) + setitem_match = SUBSET_UPDATE_PATTERN.match(last_input) if setitem_match: varname = setitem_match.group(1) # setitem to (i)python special variables do not concern us diff --git a/larray_editor/tests/test_inplace_modification_pattern.py b/larray_editor/tests/test_inplace_modification_pattern.py new file mode 100644 index 0000000..d139809 --- /dev/null +++ b/larray_editor/tests/test_inplace_modification_pattern.py @@ -0,0 +1,32 @@ +from larray_editor.editor import SUBSET_UPDATE_PATTERN + + +def test_pattern(): + assert SUBSET_UPDATE_PATTERN.match('arr1[1] = 2') + assert SUBSET_UPDATE_PATTERN.match('arr1[1]= 2') + assert SUBSET_UPDATE_PATTERN.match('arr1[1]=2') + assert SUBSET_UPDATE_PATTERN.match("arr1['a'] = arr2") + assert SUBSET_UPDATE_PATTERN.match("arr1[func(mapping['a'])] = arr2") + assert SUBSET_UPDATE_PATTERN.match("arr1.i[0, 0] = arr2") + assert SUBSET_UPDATE_PATTERN.match("arr1.iflat[0, 0] = arr2") + assert SUBSET_UPDATE_PATTERN.match("arr1.points[0, 0] = arr2") + assert SUBSET_UPDATE_PATTERN.match("arr1.ipoints[0, 0] = arr2") + assert SUBSET_UPDATE_PATTERN.match("arr1[0] += arr2") + assert SUBSET_UPDATE_PATTERN.match("arr1[0] -= arr2") + assert SUBSET_UPDATE_PATTERN.match("arr1[0] *= arr2") + assert SUBSET_UPDATE_PATTERN.match("arr1[0] /= arr2") + assert SUBSET_UPDATE_PATTERN.match("arr1[0] %= arr2") + assert SUBSET_UPDATE_PATTERN.match("arr1[0] //= arr2") + assert SUBSET_UPDATE_PATTERN.match("arr1[0] **= arr2") + assert SUBSET_UPDATE_PATTERN.match("arr1[0] &= arr2") + assert SUBSET_UPDATE_PATTERN.match("arr1[0] |= arr2") + assert SUBSET_UPDATE_PATTERN.match("arr1[0] ^= arr2") + assert SUBSET_UPDATE_PATTERN.match("arr1[0] >>= arr2") + assert SUBSET_UPDATE_PATTERN.match("arr1[0] <<= arr2") + assert SUBSET_UPDATE_PATTERN.match("arr1[0]") is None + assert SUBSET_UPDATE_PATTERN.match("arr1.method()") is None + assert SUBSET_UPDATE_PATTERN.match("arr1[0].method()") is None + assert SUBSET_UPDATE_PATTERN.match("arr1[0].method(arg=thing)") is None + assert SUBSET_UPDATE_PATTERN.match("arr1[0].method(arg==thing)") is None + # this test fails but I don't think it is possible to fix it with regex + # assert SUBSET_UPDATE_PATTERN.match("arr1[func('[]=0')].method()") is None