Re: g.importModule() and friends: do they still work? Examples?

2018-04-08 Thread Edward K. Ream
On Sun, Apr 8, 2018 at 1:54 PM, Viktor Ransmayr 
wrote:


> I haven't been able to get them to work. Is it them or me? ;-)
>>
>> import leo.core.leoGlobals as g
>> # g.importFromPath('semantic_version',
>> # 
>> r'C:\Users\mattw\Documents\GitHub\leo-editor\leo\extensions\semantic_version',
>>
>> # verbose=True)
>> # g.importExtension('semantic_version', verbose=True)
>>
>> g.importModule('semantic_version')
>>
>> Result:
>>
>> >python xx-test-semver.py
>> Traceback (most recent call last):
>>   File "xx-test-semver.py", line 13, in 
>> g.importModule('semantic_version')
>>   File "C:\Users\mattw\code\leo-editor\leo\core\leoGlobals.py", line 4916
>> , in importModule
>> trace = (False or g.app.trace_plugins) and not g.unitTesting
>> AttributeError: 'NoneType' object has no attribute 'trace_plugins'
>>
>
> ​
This clearly indicates that g.app is None, which would be so if you execute
a script outside of Leo.

g.importModule is designed to be executed when g.app *does* exist, that is,
from with Leo or a Leo plugin.

Furthermore, a cff on importModule shows that it is called from several
places. The likelihood that g.importModule is broken is small.

HTH.

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To post to this group, send email to leo-editor@googlegroups.com.
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.


Re: g.importModule() and friends: do they still work? Examples?

2018-04-08 Thread Viktor Ransmayr
Hello Matt

2018-04-08 19:26 GMT+02:00 Matt Wilkie :

> Hi All,
>
> I found 3 related functions that purport to do variants of:
>
> Try to import a module as Python's import command does.
>>
>> moduleName is the module's name, without file extension.
>>
>> This function first attempts to import from sys.modules,
>> then from the extensions and external directories.
>>
>
> but I haven't been able to get them to work. Is it them or me? ;-)
>
> import leo.core.leoGlobals as g
> # g.importFromPath('semantic_version',
> # 
> r'C:\Users\mattw\Documents\GitHub\leo-editor\leo\extensions\semantic_version',
>
> # verbose=True)
> # g.importExtension('semantic_version', verbose=True)
>
> g.importModule('semantic_version')
>
> Result:
>
> >python xx-test-semver.py
> Traceback (most recent call last):
>   File "xx-test-semver.py", line 13, in 
> g.importModule('semantic_version')
>   File "C:\Users\mattw\code\leo-editor\leo\core\leoGlobals.py", line 4916,
> in importModule
> trace = (False or g.app.trace_plugins) and not g.unitTesting
> AttributeError: 'NoneType' object has no attribute 'trace_plugins'
>

I created a node



# Node Header:

@file ~/test_sem_version.py

# Node Body:

import leo.core.leoGlobals as g
g.importModule('semantic_version')



in the workbook.leo outline in the virtual environment (VE) for/of my
cloned Leo-Master-Repo.

The result I get, when I execute this file is:



(leo-devel-git) PS C:\Users\Viktor> python ./test_sem_version.py
Traceback (most recent call last):
  File "./test_sem_version.py", line 3, in 
import leo.core.leoGlobals as g
ModuleNotFoundError: No module named 'leo'
(leo-devel-git) PS C:\Users\Viktor> v



I hope this input does helps you a bit further in your investigations ...

With kind regards,

VR

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To post to this group, send email to leo-editor@googlegroups.com.
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.