@@ -12,13 +12,6 @@ const (
1212 SingleMode CompileMode = "single" // Compile a single (interactive) statement
1313)
1414
15- type RunFlags int32
16-
17- const (
18- // RunOpts.FilePath is intelligently interpreted to load the appropriate pyc object (otherwise new code is generated from the implied .py file)
19- SmartCodeAcquire RunFlags = 0x01
20- )
21-
2215// Ctx is gpython virtual environment instance ("context"), providing a mechanism
2316// for multiple gpython interpreters to run concurrently without restriction.
2417//
@@ -51,45 +44,37 @@ type Ctx interface {
5144 Store () * Store
5245}
5346
54- const (
55- SrcFileExt = ".py"
56- CodeFileExt = ".pyc"
57- )
58-
59- type StdLib int32
60-
61- const (
62- Lib_sys StdLib = 1 << iota
63- Lib_time
64-
65- CoreLibs = Lib_sys | Lib_time
66- )
67-
47+ // CompileOpts specifies options for high-level compilation.
6848type CompileOpts struct {
6949 UseSysPaths bool // If set, sys.path will be used to resolve relative pathnames
70- CurDir string // If non-nil , this is the path of the current working directory. If nil , os.Getwd() is used.
50+ CurDir string // If non-empty , this is the path of the current working directory. If empty , os.Getwd() is used.
7151}
7252
53+ // CompileOut is the output object of high-level compilation, e.g. ResolveAndCompile()
7354type CompileOut struct {
7455 SrcPathname string // Resolved pathname the .py file that was compiled (if applicable)
7556 PycPathname string // Pathname of the .pyc file read and/or written (if applicable)
7657 FileDesc string // Pathname to be used for a a module's "__file__" attrib
7758 Code * Code // Read/Output code object ready for execution
7859}
7960
80- // Can be changed during runtime and will \play nice with others using DefaultCtxOpts()
81- var CoreSysPaths = []string {
61+ // DefaultCoreSysPaths specify default search paths for module sys
62+ // This can be changed during runtime and plays nice with others using DefaultCtxOpts()
63+ var DefaultCoreSysPaths = []string {
8264 "." ,
8365 "lib" ,
8466}
8567
86- // Can be changed during runtime and will \play nice with others using DefaultCtxOpts()
87- var AuxSysPaths = []string {
68+ // DefaultAuxSysPaths are secondary default search paths for module sys.
69+ // This can be changed during runtime and plays nice with others using DefaultCtxOpts()
70+ // They are separated from the default core paths since they the more likley thing you will want to completely replace when using gpython.
71+ var DefaultAuxSysPaths = []string {
8872 "/usr/lib/python3.4" ,
8973 "/usr/local/lib/python3.4/dist-packages" ,
9074 "/usr/lib/python3/dist-packages" ,
9175}
9276
77+ // CtxOpts specifies fundamental environment and input settings for creating a new py.Ctx
9378type CtxOpts struct {
9479 SysArgs []string // sys.argv initializer
9580 SysPaths []string // sys.path initializer
10085 // Calling this ensure that you future proof you code for suggested/default settings.
10186 DefaultCtxOpts = func () CtxOpts {
10287 opts := CtxOpts {
103- SysPaths : CoreSysPaths ,
88+ SysPaths : DefaultCoreSysPaths ,
10489 }
105- opts .SysPaths = append (opts .SysPaths , AuxSysPaths ... )
90+ opts .SysPaths = append (opts .SysPaths , DefaultAuxSysPaths ... )
10691 return opts
10792 }
10893
@@ -115,7 +100,7 @@ var (
115100 Compile func (src , srcDesc string , mode CompileMode , flags int , dont_inherit bool ) (* Code , error )
116101)
117102
118- // Resolves the given pathname, compiles as needed, and runs that code in the given module, returning the Module to indicate success.
103+ // RunFile resolves the given pathname, compiles as needed, and runs that code in the given module, returning the Module to indicate success.
119104// If inModule is a *Module, then the code is run in that module.
120105// If inModule is nil, the code is run in a new __main__ module (and the new Module is returned).
121106// If inModule is a string, the code is run in a new module with the given name (and the new Module is returned).
0 commit comments