Personally I would find it incredibly useful to be able to use Sage as a Python Library. While this is technically possible at the moment (by doing "import sage.all" and when done making sure to run "sage.all.quit_sage"), it isn't very useful, since you still have to import everything in Sage when you might need only a few things (the second it takes to import everything gets very tiresome during the debugging process).
As I see it, there are 2 major issues, and one lesser issue that prevents Sage from usable python library. 1. setting up and cleaning up C level libraries/structures (e.g. the integer pool) 2. Sage's import hell 3. (lesser) Non-standard all.py modules For 1, I'm not really familiar with these components of Sage, but at least naively it seems to me that this stuff could be dealt with in Cython classes (e.g. making the integer pool an actual Cython class, and using __cinit__ and __dealloc__ to handle the setup and cleanup). 2 is a mess, I don't really have any idea how to resolve this, although it looks to me like it might be a blocker for adding Python 3 support (see #15985), unless I'm misdiagnosing the problem (which could be the case). For 3: The all.py's are really just our way of constructing the global sage namespace. They also a common cause of branch collision (which is certainly much less painful to deal with now, but still is an issue). My proposal is very rough, and fuzzy, so bear with me, I'll try to describe how you might transition a module or a package over to my proposed scheme. - To transition a module foo over, add an __all__ to foo with the names that should be part of the global namespace. (it would probably be nice if we settled on a convention -- either have __all__ be the last thing or the first thing in the module). Updated the corresponding package's all.py with 'from foo import *' - To transition a package over, first make sure that all modules in that package have made the transition. Then add an __all_modules__ that lists the modules and subpackages in that package that have names that need to be exported to the global namespace. Remove the package's all.py. Remove that package from its parent's all.py. Finally, add the package to the global list of transitioned packages. As an example of these, see http://git.sagemath.org/sage.git/commit/?h=u/ohanar/all_removal_example&id=6f92ece7642c4dd94f9e7e64ebf88431afbe9ab2(this branch doesn't actually pass doctests, since the doctesting framework would probably have to be updated as well, and I only made changes to the actual starting up of Sage). The idea is that each individual module individually declares what are the important (for the user) names, and each package declares what are the important modules and subpackages. I think doing something along these lines will organically help with 2 (although probably not completely fix it), as well as 1. Things that I've not really considered: - Lazy imports? - Refactoring of namespace (e.g. graphs.<Tab>) I'm curious what other people think -- not just about my very fuzzy proposal, but about how we might address the issues of Sage as a Python library. -- Andrew -- 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.