Skip to content

Commit c28bca2

Browse files
committed
REFACT(plot): rename installed_plotter --> active_plotter
1 parent c7b86f6 commit c28bca2

File tree

9 files changed

+77
-55
lines changed

9 files changed

+77
-55
lines changed

CHANGES.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ v6.0.0 (13 Apr 2020, @ankostis): New Plotting Device...
2121
+ ENH/REFACT(PLOT):
2222

2323
+ REFACT/BREAK: plots are now fully configurable with :term:`plot styles`
24-
through the use of :term:`installed plotter`.
24+
through the use of :term:`installed plotter <active plotter>`.
2525
+ ENH: Render operation nodes with Graphviz *HTML-Table Labels*.
2626

2727
.. graphtik::
2828
:hide:
2929

3030
>>> from graphtik import compose, operation, varargs
31-
>>> from graphtik.plot import get_installed_plotter
31+
>>> from graphtik.plot import get_active_plotter
3232
>>> netop = compose('', operation(print, name='print-something', needs=varargs("any"), provides="str")())
3333
>>> netop.net.graph.graph['label'] = None
3434
>>> dot = netop.plot(
3535
... name=None,
36-
... plotter=get_installed_plotter().with_styles(kw_legend=None),
36+
... plotter=get_active_plotter().with_styles(kw_legend=None),
3737
... )
3838

3939
+ ENH: Convey graph, node & edge ("non-private") attributes from the *networkx* graph

docs/source/arch.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -357,27 +357,27 @@ Architecture
357357

358358
plotter
359359
A :class:`.Plotter` is responsible for rendering `plottable`\s as images.
360-
It is the `installed plotter` that does that, unless overridden in a
360+
It is the `active plotter` that does that, unless overridden in a
361361
:meth:`.Plottable.plot()` call.
362362
Plotters can be customized by :ref:`various means <plot-customizations>`,
363363
such `plot styles`.
364364

365-
installed plotter
366-
default installed plotter
365+
active plotter
366+
default active plotter
367367
The `plotter` currently installed "in-context" of the respective `graphtik
368368
configuration` - this term implies also any :ref:`plot-customizations`
369-
done on the installed plotter (such as `plot styles`).
369+
done on the active plotter (such as `plot styles`).
370370

371-
Installation happens by calling one of :func:`.installed_plotter_plugged()` or
372-
:func:`.set_installed_plotter` functions.
371+
Installation happens by calling one of :func:`.active_plotter_plugged()` or
372+
:func:`.set_active_plotter` functions.
373373

374-
The **default** *installed plotter* is the plotter instance that this project
374+
The **default** *active plotter* is the plotter instance that this project
375375
comes pre-configured with, ie, when no *plot-customizations* have yet happened.
376376

377377
plot styles
378378
The attributes of :class:`.plot.Style` class.
379379
The actual styles in-use are those in the :attr:`.Plotter.style` attribute
380-
of the `installed plotter`.
380+
of the `active plotter`.
381381

382382

383383
.. default-role:: obj

docs/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@
105105
graphtik_save_dot_files = True
106106

107107
# Plot graphtik SVGs with links to docs.
108-
plot.set_installed_plotter(
109-
plot.get_installed_plotter().with_styles(
108+
plot.set_active_plotter(
109+
plot.get_active_plotter().with_styles(
110110
py_item_url_format="../reference.html#%(dot_path)s"
111111
)
112112
)

docs/source/plotting.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,18 +324,18 @@ Plot customizations
324324
You may customize the styles and/or *plotter* behavior with various methods,
325325
ordered by breadth of the effects (most broadly effecting method at the top):
326326

327-
1. Get and modify in-place the styles of the :term:`default installed plotter`,
327+
1. Get and modify in-place the styles of the :term:`default active plotter`,
328328
like that::
329329

330-
get_installed_plotter().style.kw_op["fillcolor"] = "purple"
330+
get_active_plotter().style.kw_op["fillcolor"] = "purple"
331331

332332
- This will affect all :meth:`.Plottable.plot()` calls for a python session.
333333
- You cannot change the *plotter* instance with this method - only styles
334334
(and monkeypatching plotter's methods).
335335

336336
2. Create a new :class:`.Plotter` with customized :attr:`.Plotter.style`, or
337337
clone and customize the styles of an existing plotter by the use of
338-
its :meth:`.Plotter.with_styles` method, and make that the new *installed plotter*.
338+
its :meth:`.Plotter.with_styles` method, and make that the new *active plotter*.
339339

340340
- This will affect all calls in :class:`context <contextvars.ContextVar>`.
341341
- If customizing style constants is not enough, you may subclass :class:`.Plotter`
@@ -344,7 +344,7 @@ Plot customizations
344344
3. Take any *plotter*, customize its clone, and then call :meth:`.Plottable.plot()`,
345345
with something like that::
346346

347-
netop.plot(plotter=get_installed_plotter().with_styles(kw_legend=None))
347+
netop.plot(plotter=get_active_plotter().with_styles(kw_legend=None))
348348

349349

350350
This project dogfoods (2) in its own :file:`docs/source/conf.py` sphinx file.

graphtik/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
tasks_marshalled,
4040
)
4141

42-
## SEE ALSO: `.plot.installed_plotter_plugged()`, `.plot.set_installed_plotter()` &
43-
# `.plot.get_installed_plotter()` configs, not imported, unless plot is needed..
42+
## SEE ALSO: `.plot.active_plotter_plugged()`, `.plot.set_active_plotter()` &
43+
# `.plot.get_active_plotter()` configs, not imported, unless plot is needed..
4444

4545
from .modifiers import * # noqa, on purpose to include any new modifiers
4646
from .netop import compose

graphtik/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -441,15 +441,15 @@ def plot(
441441
If it evaluates to true, opens the diagram in a matplotlib window.
442442
If it equals `-1`, it plots but does not open the Window.
443443
:param plotter:
444-
an instance to handle plotting; if none, the :term:`installed plotter`
444+
an instance to handle plotting; if none, the :term:`active plotter`
445445
is used by default.
446446
:param name:
447447
if not given, dot-lang graph would is named "G"; necessary to be unique
448448
when referring to generated CMAPs.
449449
No need to quote it, handled by the plotter, downstream.
450450
:param str graph:
451451
(optional) A :class:`nx.Digraph` with overrides to merge with the graph provided
452-
by underlying plottables (translated by the :term:`installed plotter`).
452+
by underlying plottables (translated by the :term:`active plotter`).
453453
454454
It may contain "public" or "private *graph*, *node* & *edge* attributes:
455455
@@ -576,11 +576,11 @@ def plot(
576576
del kw["self"]
577577
plot_args = PlotArgs(**kw)
578578

579-
from .plot import Plotter, get_installed_plotter
579+
from .plot import Plotter, get_active_plotter
580580

581581
if plotter and not isinstance(plotter, Plotter):
582582
raise ValueError(f"Invalid `plotter` argument given: {plotter}")
583-
plot_args = plot_args._replace(plotter=plotter or get_installed_plotter())
583+
plot_args = plot_args._replace(plotter=plotter or get_active_plotter())
584584

585585
plot_args = self.prepare_plot_args(plot_args)
586586
assert plot_args.graph, plot_args

graphtik/config.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# Copyright 2016, Yahoo Inc.
22
# Licensed under the terms of the Apache License, Version 2.0. See the LICENSE file associated with the project for terms.
3-
""":term:`configurations` for network execution, and utilities on them."""
3+
"""
4+
:term:`configurations` for network execution, and utilities on them.
5+
6+
.. seealso:: methods :func:`.plot.active_plotter_plugged()`, :func:`.plot.set_active_plotter()`,
7+
:func:`.plot.get_active_plotter()`
8+
9+
Plot configrations were not defined here, not to pollute import space early,
10+
until they are actually needed.
11+
"""
412
import ctypes
513
from contextlib import contextmanager
614
from contextvars import ContextVar
@@ -47,7 +55,9 @@ def _tristate_armed(context_var: ContextVar, enabled):
4755

4856

4957
debug = partial(_tristate_armed, _debug)
50-
"""Like :func:`set_debug()` as a context-manager to reset old value. """
58+
"""
59+
Like :func:`set_debug()` as a context-manager, resetting back to old value.
60+
"""
5161
is_debug = partial(_getter, _debug)
5262
"""see :func:`set_debug()`"""
5363
set_debug = partial(_tristate_set, _debug)
@@ -84,7 +94,9 @@ def is_abort():
8494

8595

8696
evictions_skipped = partial(_tristate_armed, _skip_evictions)
87-
"""Like :func:`set_skip_evictions()` as a context-manager to reset old value. """
97+
"""
98+
Like :func:`set_skip_evictions()` as a context-manager, resetting back to old value.
99+
"""
88100
is_skip_evictions = partial(_getter, _skip_evictions)
89101
"""see :func:`set_skip_evictions()`"""
90102
set_skip_evictions = partial(_tristate_set, _skip_evictions)
@@ -100,7 +112,9 @@ def is_abort():
100112

101113
@contextmanager
102114
def execution_pool_plugged(pool: "Optional[Pool]"):
103-
"""Like :func:`set_execution_pool()` as a context-manager to reset old value. """
115+
"""
116+
Like :func:`set_execution_pool()` as a context-manager, resetting back to old value.
117+
"""
104118
resetter = _execution_pool.set(pool)
105119
try:
106120
yield
@@ -124,7 +138,9 @@ def get_execution_pool() -> "Optional[Pool]":
124138

125139

126140
tasks_in_parallel = partial(_tristate_armed, _parallel_tasks)
127-
"""Like :func:`set_parallel_tasks()` as a context-manager to reset old value. """
141+
"""
142+
Like :func:`set_parallel_tasks()` as a context-manager, resetting back to old value.
143+
"""
128144
is_parallel_tasks = partial(_getter, _parallel_tasks)
129145
"""see :func:`set_parallel_tasks()`"""
130146
set_parallel_tasks = partial(_tristate_set, _parallel_tasks)
@@ -141,7 +157,9 @@ def get_execution_pool() -> "Optional[Pool]":
141157

142158

143159
tasks_marshalled = partial(_tristate_armed, _marshal_tasks)
144-
"""Like :func:`set_marshal_tasks()` as a context-manager to reset old value. """
160+
"""
161+
Like :func:`set_marshal_tasks()` as a context-manager, resetting back to old value.
162+
"""
145163
is_marshal_tasks = partial(_getter, _marshal_tasks)
146164
"""see :func:`set_marshal_tasks()`"""
147165
set_marshal_tasks = partial(_tristate_set, _marshal_tasks)
@@ -160,7 +178,9 @@ def get_execution_pool() -> "Optional[Pool]":
160178

161179

162180
operations_endured = partial(_tristate_armed, _endure_operations)
163-
"""Like :func:`set_endure_operations()` as a context-manager to reset old value. """
181+
"""
182+
Like :func:`set_endure_operations()` as a context-manager, resetting back to old value.
183+
"""
164184
is_endure_operations = partial(_getter, _endure_operations)
165185
"""see :func:`set_endure_operations()`"""
166186
set_endure_operations = partial(_tristate_set, _endure_operations)
@@ -178,7 +198,9 @@ def get_execution_pool() -> "Optional[Pool]":
178198

179199

180200
operations_reschedullled = partial(_tristate_armed, _reschedule_operations)
181-
"""Like :func:`set_reschedule_operations()` as a context-manager to reset old value. """
201+
"""
202+
Like :func:`set_reschedule_operations()` as a context-manager, resetting back to old value.
203+
"""
182204
is_reschedule_operations = partial(_getter, _reschedule_operations)
183205
"""see :func:`set_reschedule_operations()`"""
184206
set_reschedule_operations = partial(_tristate_set, _reschedule_operations)

graphtik/plot.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright 2016, Yahoo Inc.
22
# Licensed under the terms of the Apache License, Version 2.0. See the LICENSE file associated with the project for terms.
33
"""
4-
Plotting of graphtik graphs (see also plot-classes on :mod:`.base` module).
4+
Plotting of graph graphs handled by :term:`active plotter`.
55
66
Separate from `graphtik.base` to avoid too many imports too early.
77
from contextlib import contextmanager
@@ -320,7 +320,7 @@ class Style:
320320
321321
.. NOTE::
322322
Changing class attributes AFTER the module has loaded WON'T change themes;
323-
Either patch directly the :attr:`Plotter.style` of :term:`installed plotter`),
323+
Either patch directly the :attr:`Plotter.style` of :term:`active plotter`),
324324
or pass a new styles to a new plotter, as described in :ref:`plot-customizations`.
325325
326326
"""
@@ -500,7 +500,7 @@ def resolve_refs(self, values: dict = None) -> None:
500500
Rebase any refs in styles, and deep copy (for free) as instance attributes.
501501
502502
:raises:
503-
Nothing(!), not to CRASH :term:`default installed plotter` on import-time.
503+
Nothing(!), not to CRASH :term:`default active plotter` on import-time.
504504
Ref-errors are log-ERROR reported, and the item with the ref is skipped.
505505
"""
506506

@@ -1030,11 +1030,11 @@ def legend(
10301030
Generate a legend for all plots (see :meth:`.Plottable.plot()` for args)
10311031
10321032
:param plotter:
1033-
override the :term:`installed plotter`
1033+
override the :term:`active plotter`
10341034
10351035
See :meth:`Plotter.render_pydot` for the rest arguments.
10361036
"""
1037-
plotter = plotter or get_installed_plotter()
1037+
plotter = plotter or get_active_plotter()
10381038
return plotter.legend(filename, show, jupyter_render)
10391039

10401040

@@ -1043,24 +1043,24 @@ def supported_plot_formats() -> List[str]:
10431043
return [".%s" % f for f in pydot.Dot().formats]
10441044

10451045

1046-
_installed_plotter: ContextVar[Plotter] = ContextVar(
1047-
"installed_plotter", default=Plotter()
1048-
)
1046+
_active_plotter: ContextVar[Plotter] = ContextVar("active_plotter", default=Plotter())
10491047

10501048

10511049
@contextmanager
1052-
def installed_plotter_plugged(plotter: Plotter) -> None:
1053-
"""Like :func:`set_installed_plotter()` as a context-manager to reset old value. """
1050+
def active_plotter_plugged(plotter: Plotter) -> None:
1051+
"""
1052+
Like :func:`set_active_plotter()` as a context-manager, resetting back to old value.
1053+
"""
10541054
if not isinstance(plotter, Plotter):
10551055
raise ValueError(f"Cannot install invalid plotter: {plotter}")
1056-
resetter = _installed_plotter.set(plotter)
1056+
resetter = _active_plotter.set(plotter)
10571057
try:
10581058
yield
10591059
finally:
1060-
_installed_plotter.reset(resetter)
1060+
_active_plotter.reset(resetter)
10611061

10621062

1063-
def set_installed_plotter(plotter: Plotter):
1063+
def set_active_plotter(plotter: Plotter):
10641064
"""
10651065
The default instance to render :term:`plottable`\\s,
10661066
@@ -1071,13 +1071,13 @@ def set_installed_plotter(plotter: Plotter):
10711071
"""
10721072
if not isinstance(plotter, Plotter):
10731073
raise ValueError(f"Cannot install invalid plotter: {plotter}")
1074-
return _installed_plotter.set(plotter)
1074+
return _active_plotter.set(plotter)
10751075

10761076

1077-
def get_installed_plotter() -> Plotter:
1078-
"""Get the previously installed :class:`.Plotter` instance or default one."""
1079-
plotter = _installed_plotter.get()
1077+
def get_active_plotter() -> Plotter:
1078+
"""Get the previously active :class:`.plotter` instance or default one."""
1079+
plotter = _active_plotter.get()
10801080
if not isinstance(plotter, Plotter):
1081-
raise ValueError(f"Missing or invalid installed plotter: {plotter}")
1081+
raise ValueError(f"Missing or invalid active plotter: {plotter}")
10821082

10831083
return plotter

test/test_plot.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
from graphtik.plot import (
1717
Plotter,
1818
Style,
19-
get_installed_plotter,
20-
installed_plotter_plugged,
19+
get_active_plotter,
20+
active_plotter_plugged,
2121
)
2222

2323

@@ -349,9 +349,9 @@ def test_plotter_customizations(pipeline, monkeypatch):
349349
dot = str(pipeline.plot())
350350
assert url in dot
351351

352-
## New installed_plotter
352+
## New active_plotter
353353
#
354-
with installed_plotter_plugged(Plotter(style=Style(kw_legend={"URL": None}))):
354+
with active_plotter_plugged(Plotter(style=Style(kw_legend={"URL": None}))):
355355
dot = str(pipeline.plot())
356356
assert url not in dot
357357

@@ -365,7 +365,7 @@ def test_plotter_customizations(pipeline, monkeypatch):
365365
assert url in dot
366366

367367
url2 = "http://example.2.org"
368-
with installed_plotter_plugged(Plotter(style=Style(kw_legend={"URL": url2}))):
368+
with active_plotter_plugged(Plotter(style=Style(kw_legend={"URL": url2}))):
369369
dot = str(pipeline.plot())
370370
assert url2 in dot
371371
assert url not in dot
@@ -465,7 +465,7 @@ def test_node_dot_str0(dot_str_pipeline):
465465

466466

467467
def test_node_dot_str1(dot_str_pipeline, monkeypatch):
468-
style = get_installed_plotter().style
468+
style = get_active_plotter().style
469469
monkeypatch.setattr(style, "py_item_url_format", "abc#%s")
470470
monkeypatch.setattr(style, "op_link_target", "_self")
471471
monkeypatch.setattr(style, "fn_link_target", "bad")

0 commit comments

Comments
 (0)