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..3ea2746 --- /dev/null +++ b/doc/source/changes/version_0_34_6.rst.inc @@ -0,0 +1,9 @@ +.. py:currentmodule:: larray_editor + +Fixes +^^^^^ + +* 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/__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/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 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"