Last active
February 28, 2019 06:37
-
-
Save maphew/c4670b3cb6e045e7583769de6a185ee6 to your computer and use it in GitHub Desktop.
Snippets for finding Leo's library path (ie: ./leo-editor/leo or PYTHONHOME/Lib/site-packages/leo)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# import pdb ; pdb = pdb.set_trace | |
import os | |
import sys | |
# Partial fix for #541. | |
# See https://stackoverflow.com/questions/24835155/pyw-and-pythonw-does-not-run-under-windows-7/30310192#30310192 | |
if sys.executable.endswith("pythonw.exe"): | |
sys.stdout = open(os.devnull, "w"); | |
sys.stderr = open( | |
os.path.join(os.getenv("TEMP"), | |
"stderr-"+os.path.basename(sys.argv[0])), | |
"w") | |
path = os.getcwd() | |
if path not in sys.path: | |
# print('appending %s to sys.path' % path) | |
sys.path.append(path) | |
# Import leoGlobals, but do NOT set g. | |
import leo.core.leoGlobals as leoGlobals | |
# Create g.app. | |
import leo.core.leoApp as leoApp | |
leoGlobals.app = leoApp.LeoApp() | |
# **Now** we can set g. | |
g = leoGlobals | |
assert(g.app) | |
# --- this creates a traceback --- | |
g.es_print(g.computeLeoDir()) | |
r''' | |
Result: | |
(leo-dev) matt@ENV-SURFACE-MHW C:\Users\mattw\code\leo-editor | |
> python find-leo-lib-using-leo.py | |
Traceback (most recent call last): | |
File "find-leo-lib-using-leo.py", line 26, in <module> | |
g.es_print(g.computeLeoDir()) | |
File "C:\Users\mattw\code\leo-editor\leo\core\leoGlobals.py", line 3409, in computeLeoDir | |
return g.app.loadManager.computeLeoDir() | |
AttributeError: 'NoneType' object has no attribute 'computeLeoDir' | |
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# simple and works, but is there a reason not to I don't know about? | |
import leo | |
leolibpath = leo.__path__ | |
print(leolibpath) | |
r''' | |
Result: | |
(leo-dev) matt@ENV-SURFACE-MHW C:\Users\mattw\code\leo-editor | |
> python find-leo-lib.py | |
['C:\\Users\\mattw\\code\\leo-editor\\leo'] | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment