Hi Simon,

Thanks for your answer.

> On 2014-03-16, Vincent Delecroix <20100.delecr...@gmail.com> wrote:
>> I am able to list all submodules of
>> the Sage library with the pkgutil library but then I somehow need to
>> read some of their source code (in order to avoid loading them). For
>> standard python files it is done with the pkglib. But for cython files
>> it fails. The only alternative I found is to call
>> sage.misc.sageinspect.sage_getsource. My problem is that I need to
>> import the module to call this function... which modifies the
>> namespace of sage !
>
> I don't see why this would modify the namespace of Sage, but anyway.
>

Let me rephrase, it does not modify the namespace (i.e. global
variables) but it modifies the modules that have been loaded

sage: import sys
sage: def f(): import sage.rings.polynomial.real_roots
sage: 'sage.rings.polynomial.real_roots' in sys.modules
False
sage: f()
sage: 'sage.rings.polynomial.real_roots' in sys.modules
True

But I discussed it with Nicolas and he found that it is preferable to
load extra modules rather than parsing many files in the source code
(and also simpler). So I implemented a function "load_submodules"
which can be used in conjunction with import_statements.

>> Do you have a solution from a given module name within the sage
>> library, let say 'sage.rings.polynomial.real_roots', to obtain its
>> source code ?
>
> So, what you start with is not a module but a string specifying a
> module, and you want to find its source?
>
> I guess, if module_name is the name of the module, and if the module is
> *not* a Python module, the following will give you the path to the
> source file.
>
>  sage: module_name = 'sage.rings.polynomial.real_roots'
>  sage:
> os.path.join(SAGE_ROOT,'src',*module_name.split('.'))+os.path.extsep+'pyx'
>  '/home/king/Sage/git/sage/src/sage/rings/polynomial/real_roots.pyx'

Great. I keep it under my pillow !

Thanks
Vincent

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

Reply via email to