Skip to content

Commit f280d9f

Browse files
committed
FIX #205
1 parent 257c315 commit f280d9f

File tree

3 files changed

+36
-37
lines changed

3 files changed

+36
-37
lines changed

CHANGES.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
Change History
55
##############
66

7+
:1.1.10: release *tba* : updates & bug fix
8+
9+
* `#205 <https://github.com/BCDA-APS/apstools/issues/205>`_
10+
``show_ophyd_symbols`` uses ipython shell's namespace
11+
* `#202 <https://github.com/BCDA-APS/apstools/issues/202>`_
12+
add ``labels`` attribute to enable ``wa`` and ``ct`` magic commands
13+
714
:1.1.9: released *2019-07-28* : updates & bug fix
815

916
* `#203 <https://github.com/BCDA-APS/apstools/issues/203>`_

apstools/utils.py

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,11 @@ def print_RE_md(dictionary=None, fmt="simple", printing=True):
210210
======================== ===================================
211211
212212
"""
213-
global RE
213+
try:
214+
from IPython import get_ipython
215+
RE = get_ipython().user_ns["RE"]
216+
except AttributeError as _exc:
217+
RE = None
214218
dictionary = dictionary or RE.md
215219
md = dict(dictionary) # copy of input for editing
216220
v = dictionary_table(md["versions"], fmt=fmt) # sub-table
@@ -279,29 +283,7 @@ def show_ophyd_symbols(show_pv=True, printing=True, verbose=False, symbols=None)
279283
If True, also show ``str(obj``.
280284
symbols: dict (default: `globals()`)
281285
If None, use global symbol table.
282-
If not None, use provided dictionary.
283-
284-
**TIP** ``globals()`` only gets the module's globals
285-
286-
To get ``globals()`` from the global namespace, need to
287-
pass that from the global namespace into this function.
288-
Define this function *in* the global namespace::
289-
290-
from apstools import utils as APS_utils
291-
292-
def show_ophyd_symbols(
293-
show_pv=True,
294-
printing=True,
295-
verbose=False,
296-
symbols=None
297-
):
298-
symbols = symbols or globals()
299-
return APS_utils.show_ophyd_symbols(
300-
show_pv=show_pv,
301-
printing=printing,
302-
verbose=verbose,
303-
symbols=symbols
304-
)
286+
If not None, use provided dictionary.
305287
306288
EXAMPLE::
307289
@@ -333,7 +315,12 @@ def show_ophyd_symbols(
333315
table.addLabel("EPICS PV")
334316
if verbose:
335317
table.addLabel("object representation")
336-
g = symbols or globals()
318+
try:
319+
from IPython import get_ipython
320+
g = get_ipython().user_ns
321+
except AttributeError as _exc:
322+
g = globals()
323+
g = symbols or g
337324
for k, v in sorted(g.items()):
338325
if isinstance(v, (ophyd.Signal, ophyd.Device)):
339326
row = [k, v.__class__.__name__]

tests/test_utils.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,21 +108,26 @@ def test_print_RE_md(self):
108108

109109
expected = [
110110
'RunEngine metadata dictionary:',
111-
'========= ================================',
112-
'key value ',
113-
'========= ================================',
114-
'purpose testing ',
115-
'something else ',
116-
'versions ======== =======================',
117-
' key value ',
118-
' ======== =======================',
111+
'========= ===============================',
112+
'key value ',
113+
'========= ===============================',
114+
'purpose testing ',
115+
'something else ',
116+
'versions ======== ======================',
117+
' key value ',
118+
' ======== ======================',
119119
f' apstools {APS__version__}',
120-
' ======== =======================',
121-
'========= ================================',
120+
' ======== ======================',
121+
'========= ===============================',
122122
''
123123
]
124-
for r, e in zip(received, expected):
125-
self.assertEqual(r, e)
124+
self.assertEqual(len(received), len(expected))
125+
self.assertEqual(received[4].strip(), expected[4].strip())
126+
self.assertEqual(received[5].strip(), expected[5].strip())
127+
self.assertEqual(
128+
received[9].strip(),
129+
expected[9].strip()
130+
)
126131

127132
def test_pairwise(self):
128133
items = [1.0, 1.1, 1.01, 1.001, 1.0001, 1.00001, 2]

0 commit comments

Comments
 (0)