| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ba23488 commit 91e00bf
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,46 +18,35 @@ | |||
| 18 | 18 | All rights reserved. | |
| 19 | 19 | MIT Licensed (see README file for details) | |
| 20 | 20 | """ | |
| 21 | + import sys, re, os, site | ||
| 21 | 22 | ||
| 22 | 23 | __version__ = '0.9.4' | |
| 23 | 24 | __author__ = 'Christian Swinehart' | |
| 24 | - __email__ = "drafting@samizdat.cc" | ||
| 25 | + __email__ = 'drafting@samizdat.cc' | ||
| 25 | 26 | __credits__ = 'Frederik De Bleser, Tom De Smedt, Just van Rossum, & Marcos Ojeda' | |
| 26 | 27 | __license__ = 'MIT' | |
| 27 | 28 | ||
| 28 | - | ||
| 29 | - # add the shared directory (for Libraries) to the path | ||
| 30 | - import sys, re, os | ||
| 31 | - sys.path.append(os.path.join(os.getenv('HOME'), 'Library', 'Application Support', 'PlotDevice')) | ||
| 32 | - | ||
| 33 | - # add the Extras directory to sys.path since every module depends on PyObjC and friends | ||
| 34 | - try: | ||
| 35 | - import objc | ||
| 36 | - except ImportError: | ||
| 37 | - extras = '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python' | ||
| 38 | - sys.path.extend([extras, '%s/PyObjC'%extras]) | ||
| 39 | - import objc | ||
| 40 | - | ||
| 41 | - # print python exceptions to the console rather than silently failing | ||
| 42 | - objc.setVerbose(True) | ||
| 43 | - | ||
| 44 | - # the global non-conflicting token (fingers crossed) | ||
| 45 | - INTERNAL = '_p_l_o_t_d_e_v_i_c_e_' | ||
| 46 | - | ||
| 47 | - # please excuse our technical difficulties | ||
| 48 | - class DeviceError(Exception): | ||
| 49 | - pass | ||
| 50 | - | ||
| 51 | - # special exception to cleanly exit animations | ||
| 52 | - class Halted(Exception): | ||
| 53 | - pass | ||
| 29 | + INTERNAL = '_p_l_o_t_d_e_v_i_c_e_' # the global non-conflicting token (fingers crossed) | ||
| 30 | + class DeviceError(Exception): pass # please excuse our technical difficulties | ||
| 31 | + class Halted(Exception): pass # special exception to cleanly exit animations | ||
| 54 | 32 | ||
| 55 | 33 | # note whether the module is being used within the .app, via console.py, or from the repl | |
| 56 | 34 | called_from = getattr(sys.modules['__main__'], '__file__', '<interactive>') | |
| 57 | 35 | is_windowed = bool(re.search(r'plotdevice(-app|/run/console)\.py$', called_from)) | |
| 58 | 36 | in_setup = bool(called_from.endswith('setup.py')) # (for builds) | |
| 59 | 37 | ||
| 60 | - # populate the namespace (or don't) accordingly | ||
| 38 | + # don't mess with sys.path during builds | ||
| 39 | + if not in_setup: | ||
| 40 | + # use the bundled copy of PyObjC rather than the system version | ||
| 41 | + from .run import objc | ||
| 42 | + | ||
| 43 | + # add the shared directory (for Libraries) to the path | ||
| 44 | + sys.path.append(os.path.join(os.getenv('HOME'), 'Library', 'Application Support', 'PlotDevice')) | ||
| 45 | + | ||
| 46 | + # print python exceptions to the console rather than silently failing | ||
| 47 | + objc.setVerbose(True) | ||
| 48 | + | ||
| 49 | + # populate the namespace (or don't) depending on the context | ||
| 61 | 50 | if is_windowed or in_setup: | |
| 62 | 51 | # if a script imports * from within the app/tool, nothing should be (re-)added to the | |
| 63 | 52 | # global namespace. we'll let the Sandbox handle populating the namespace instead. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,12 +4,12 @@ | |||
| 4 | 4 | # do some special-case handling when the module is imported from within the source dist | |
| 5 | 5 | # (determined by checking the existence project files at a known path). if we're in the | |
| 6 | 6 | # source dist, add the build dir to the path so we can pick up the .so files, | |
| 7 | - module_root = abspath(join(abspath(dirname(__file__)), '../..')) | ||
| 8 | - if exists(join(module_root, 'app/PlotDevice-Info.plist')): | ||
| 9 | - so_dir = join(module_root, 'build/lib/plotdevice/lib') | ||
| 7 | + dist_root = abspath(join(abspath(dirname(__file__)), '../..')) | ||
| 8 | + if exists(join(dist_root, 'app/PlotDevice-Info.plist')): | ||
| 9 | + so_dir = join(dist_root, 'build/lib/plotdevice/lib') | ||
| 10 | 10 | sys.path.append(so_dir) | |
| 11 | 11 | if not exists(so_dir): | |
| 12 | - unbuilt = 'Build the plotdevice module with `python setup.pt build\' before attempting import it.' | ||
| 12 | + unbuilt = 'Build the plotdevice module with `python setup.py build\' before attempting import it.' | ||
| 13 | 13 | raise RuntimeError(unbuilt) | |
| 14 | 14 | ||
| 15 | 15 | # test the sys.path by attempting to load the c-extensions | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,8 +1,25 @@ | |||
| 1 | - import linecache, re | ||
| 2 | - from sys import exc_info | ||
| 3 | - from os.path import abspath, dirname, relpath | ||
| 1 | + import re, sys, site, linecache | ||
| 2 | + from os.path import abspath, dirname, relpath, exists, join | ||
| 4 | 3 | from traceback import format_list, format_exception_only | |
| 5 | - from AppKit import NSBundle | ||
| 4 | + | ||
| 5 | + # add our embedded PyObjC site-dir to the sys.path | ||
| 6 | + dist_root = abspath(join(dirname(__file__), '../..')) | ||
| 7 | + if exists(join(dist_root, 'app/PlotDevice-Info.plist')): | ||
| 8 | + # if run from the sdist, look in the build dir... | ||
| 9 | + objc_dir = join(dist_root, 'build/lib/plotdevice/lib/PyObjC') | ||
| 10 | + else: | ||
| 11 | + # ...otherwise find the modules in .lib | ||
| 12 | + objc_dir = abspath(join(dirname(__file__), '../lib/PyObjC')) | ||
| 13 | + map(sys.path.remove, filter(lambda p:p.endswith('PyObjC'), sys.path)) | ||
| 14 | + site.addsitedir(objc_dir) | ||
| 15 | + | ||
| 16 | + # test the sys.path by attempting to load a PyObjC submodule | ||
| 17 | + try: | ||
| 18 | + import objc | ||
| 19 | + except: | ||
| 20 | + unbuilt = 'Build the plotdevice module with `python setup.py build\' before attempting import it.' | ||
| 21 | + raise RuntimeError(unbuilt) | ||
| 22 | + | ||
| 6 | 23 | ||
| 7 | 24 | def encoding(src): | |
| 8 | 25 | """Searches the first two lines of a string looking for an `# encoding: ???` comment.""" | |
@@ -51,7 +68,7 @@ def stacktrace(script=None, src=None): | |||
| 51 | 68 | def coredump(script=None, src=None, syntax=True): | |
| 52 | 69 | """Get a clean stacktrace with absolute paths and source pulled from the editor rather than disk""" | |
| 53 | 70 | # use the most recently caught exception | |
| 54 | - etype, value, tb = exc_info() | ||
| 71 | + etype, value, tb = sys.exc_info() | ||
| 55 | 72 | script = script or '<Untitled>' if src else None | |
| 56 | 73 | frames = extract_tb(tb, script, src) | |
| 57 | 74 | ||
@@ -85,6 +102,7 @@ def extract_tb(tb, script=None, src=None): | |||
| 85 | 102 | tb = tb.tb_next | |
| 86 | 103 | ||
| 87 | 104 | # omit the internal plotdevice stack frames in `dist` builds | |
| 105 | + from AppKit import NSBundle | ||
| 88 | 106 | debug = 'flux' in NSBundle.mainBundle().infoDictionary().get('CFBundleVersion','') | |
| 89 | 107 | if not debug: | |
| 90 | 108 | moduledir = abspath(dirname(dirname(__file__))) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments