Skip to content

Commit a74176d

Browse files
committed
fix the __all__ logic for the command line tool
- the module __init__ gets imported first so it can't detect whether __main__.py is going to be in the driver seat - instead, __main__ itself clears out the __all__ namespace (primarily so the .pv script doesn't end up talking to a different canvas)
1 parent 3d8acf4 commit a74176d

2 files changed

Lines changed: 11 additions & 13 deletions

File tree

plotdevice/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ class Halted(Exception): pass # special exception to cleanly exit animation
3232

3333
# note whether the module is being used within the .app, via console.py, or from the repl
3434
called_from = getattr(sys.modules['__main__'], '__file__', '<interactive>')
35-
is_windowed = bool(re.search(r'plotdevice(-app|/run/console)\.py$', called_from))
36-
in_setup = bool(called_from.endswith('setup.py')) # (for builds)
35+
in_app = called_from.endswith('plotdevice-app.py')
36+
in_setup = called_from.endswith('setup.py')
3737

3838
# don't mess with sys.path during builds
3939
if not in_setup:
@@ -47,8 +47,8 @@ class Halted(Exception): pass # special exception to cleanly exit animation
4747
objc.setVerbose(True)
4848

4949
# populate the namespace (or don't) depending on the context
50-
if is_windowed or in_setup:
51-
# if a script imports * from within the app/tool, nothing should be (re-)added to the
50+
if in_app or in_setup:
51+
# if a script imports * from within the app, nothing should be (re-)added to the
5252
# global namespace. we'll let the Sandbox handle populating the namespace instead.
5353
__all__ = []
5454
else:

plotdevice/__main__.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,15 @@
2222
python3 -m plotdevice script.pv --export output.gif --frames 60 --fps 30 --loop
2323
"""
2424

25-
from __future__ import print_function
2625
import sys, os, re
2726
import argparse
28-
import json
29-
import signal
30-
from glob import glob
31-
from subprocess import Popen, PIPE
3227
from os.path import exists, islink, dirname, abspath, realpath, join
33-
from .run.console import run
34-
from . import __version__
28+
3529

3630
def main():
31+
import plotdevice
32+
from .run.console import run
33+
3734
parser = argparse.ArgumentParser(
3835
add_help=False,
3936
description="Run PlotDevice scripts in a window or export graphics to a document (pdf/eps), image (png/jpg/heic/gif/tiff), or movie (mov/gif).",
@@ -44,7 +41,7 @@ def main():
4441
o = parser.add_argument_group("Options", None)
4542
o.add_argument('-h','--help', action='help', help='show this help message and exit')
4643
o.add_argument('-f', dest='fullscreen', action='store_const', const=True, default=False, help='run full-screen')
47-
o.add_argument('-b', dest='activate', action='store_const', const=False, default=True, help='run PlotDevice in the background')
44+
o.add_argument('-b', dest='activate', action='store_const', const=False, default=True, help='run PlotDevice in the background (i.e., leave focus in the active application)')
4845
o.add_argument('-q', dest='mode', action='store_const', const='headless', default='windowed', help='run a PlotDevice script ‘quietly’ (without opening a window)')
4946
o.add_argument('--virtualenv', metavar='PATH', help='path to virtualenv whose libraries you want to use (this should point to the top-level virtualenv directory; a folder containing a lib/python3.x/site-packages subdirectory)')
5047
o.add_argument('--export', '-o', metavar='FILE', help='a destination filename ending in pdf, eps, png, tiff, jpg, heic, gif, or mov')
@@ -55,7 +52,7 @@ def main():
5552
o.add_argument('--cmyk', action='store_const', const=True, default=False, help='convert colors to c/m/y/k during exports')
5653
o.add_argument('--live', action='store_const', const=True, help='re-render graphics each time the file is saved')
5754
o.add_argument('--args', nargs='*', default=[], metavar=('a','b'), help='arguments to be passed to the script as sys.argv')
58-
o.add_argument('--version', action='version', version='PlotDevice %s' % __version__)
55+
o.add_argument('--version', action='version', version='PlotDevice %s' % plotdevice.__version__)
5956

6057
i = parser.add_argument_group("PlotDevice Script File", None)
6158
i.add_argument('script', help='the python script to be rendered')
@@ -120,6 +117,7 @@ def main():
120117
opts.single = bool(ext=='pdf' and not re.search('{\d+}', opts.export) and opts.last and opts.first < opts.last)
121118

122119
# set it off
120+
plotdevice.__all__.clear()
123121
run(vars(opts))
124122

125123
if __name__ == "__main__":

0 commit comments

Comments
 (0)