8000 FEAT: added support for Path objects in edit() and view() (see larray… · larray-project/larray-editor@bb77a65 · GitHub
[go: up one dir, main page]

Skip to content

Commit bb77a65

Browse files
committed
FEAT: added support for Path objects in edit() and view() (see larray-project/larray#896)
1 parent 40024a2 commit bb77a65

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

doc/source/changes/version_0_34.rst.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ Miscellaneous improvements
4343
* when displaying an expression (computed array), the window title includes the actual expression
4444
instead of using '<expr>'.
4545

46+
* added support for Path objects (in addition to str representing paths) in :py:obj:`view()` and :py:obj:`edit()`.
47+
See :issue:`896`.
48+
4649
* When the editor displays currently defined variables (via `debug()` `edit()` or
4750
`view()` without argument within user code or via an exception when run_editor_on_exception is active),
4851
LArray functions are not made available systematically in the console anymore (what is available in the console is

larray_editor/api.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import sys
33
import traceback
44
from inspect import getframeinfo
5+
from pathlib import Path
56

67
from qtpy.QtWidgets import QApplication
78
import larray as la
@@ -125,7 +126,7 @@ def _edit_dialog(parent, obj=None, title='', minvalue=None, maxvalue=None, reado
125126
if not title and obj is not REOPEN_LAST_FILE:
126127
title = _get_title(obj, depth=depth + 1)
127128

128-
if obj is REOPEN_LAST_FILE or isinstance(obj, (str, la.Session)):
129+
if obj is REOPEN_LAST_FILE or isinstance(obj, (str, Path, la.Session)):
129130
dlg = MappingEditor(parent)
130131
assert minvalue is None and maxvalue is None
131132
setup_ok = dlg.setup_and_check(obj, title=title, readonly=readonly, caller_info=caller_info,
@@ -147,8 +148,8 @@ def edit(obj=None, title='', minvalue=None, maxvalue=None, readonly=False, depth
147148
148149
Parameters
149150
----------
150-
obj : np.ndarray, Array, Session, dict, str, REOPEN_LAST_FILE or None, optional
151-
Object to visualize. If string, array(s) will be loaded from the file given as argument.
151+
obj : np.ndarray, Array, Session, dict, str, Path, REOPEN_LAST_FILE or None, optional
152+
Object to visualize. If string or Path, array(s) will be loaded from the file given as argument.
152153
Passing the constant REOPEN_LAST_FILE loads the last opened file.
153154
Defaults to None, which gathers all variables (global and local) where the function was called.
154155
title : str, optional
@@ -190,8 +191,8 @@ def view(obj=None, title='', depth=0, display_caller_info=True, add_larray_funct
190191
191192
Parameters
192193
----------
193-
obj : np.ndarray, Array, Session, dict or str, optional
194-
Object to visualize. If string, array(s) will be loaded from the file given as argument.
194+
obj : np.ndarray, Array, Session, dict, str or Path, optional
195+
Object to visualize. If string or Path, array(s) will be loaded from the file given as argument.
195196
Defaults to the collection of all local variables where the function was called.
196197
title : str, optional
197198
Title for the current object. Defaults to the name of the first object found in the caller namespace which

larray_editor/editor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ def void_formatter(array, *args, **kwargs):
475475
data = la.Session()
476476

477477
# load file if any
478-
if isinstance(data, str):
478+
if isinstance(data, (str, Path)):
479479
if os.path.isfile(data):
480480
self._open_file(data)
481481
else:

larray_editor/tests/test_api_larray.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Array editor test"""
22

33
import logging
4+
from pathlib import Path
45

56
import numpy as np
67
import larray as la
@@ -135,6 +136,7 @@ def make_demo(width=20, ball_radius=5, path_radius=5, steps=30):
135136
# 'c:\\tmp\\edit.profile')
136137
# debug()
137138
edit()
139+
# edit(Path('../test_object.h5'))
138140
# edit(ses)
139141
# edit(file)
140142
# edit('fake_path')

0 commit comments

Comments
 (0)
0