Use sage files as python modules

asked 2016-12-02 22:46:54 +0200

MvG gravatar image

I've got a project where on the one hand I'd like to use the syntactic sugar the sage preparser adds. So I want my source files to be *.sage not *.py at least in my editor. On the other hand, I would like to make use of Python's module system: each sage file should have its own module scope, and names put there should not affect other modules using the same names. I'd also like for modules to reference on another via relative imports, to facilitate code sharing.

Does Sage offer any help for this kind of use case? Any documentation somewhere?

I guess I could manually run the preparser, then rename all the files since can't contain a module Foo.sage as dots are not valid parts of a module name there. But perhaps there is something more clever. Some hook to the import system, so it can handle these * files or automatically crate them via preparsing if needed. Or some way to select a different extension for the sage -preparse output. Or some way to have sage.repl.load.load do whole-file preparsing, adding relevant imports in particular. Something along these lines.

edit retag flag offensive close merge delete


I do not know the specific situation which needs the syntactic sugar, but

  • either extending the sage package suite with own packages, respecting the same scheme,
  • or using eclipse to bundle dependencies in projects (and using in each routine clear namespaces, so no from sage.all import *) would be ok.

The last is working for me to 80%, although the partial eclipse solution has its own vein.

dan_fulea gravatar imagedan_fulea ( 2017-07-21 22:43:17 +0200 )edit