From 92816224f90a57fdc5d7f9e66a5a04fa241dda9d Mon Sep 17 00:00:00 2001 From: Sebastien Binet Date: Wed, 23 Mar 2022 17:26:52 +0100 Subject: [PATCH 1/2] all: move modules to stdlib --- examples/embedding/main.go | 6 +++--- examples/multi-context/main.go | 4 ++-- main.go | 3 ++- pytest/pytest.go | 4 ++-- repl/repl_test.go | 2 +- repl/web/main.go | 5 ++--- modules/runtime.go => stdlib/stdlib.go | 4 +++- 7 files changed, 15 insertions(+), 13 deletions(-) rename modules/runtime.go => stdlib/stdlib.go (97%) diff --git a/examples/embedding/main.go b/examples/embedding/main.go index 37f34a7f..e4aadfef 100644 --- a/examples/embedding/main.go +++ b/examples/embedding/main.go @@ -10,7 +10,7 @@ import ( // This initializes gpython for runtime execution and is essential. // It defines forward-declared symbols and registers native built-in modules, such as sys and time. - _ "github.com/go-python/gpython/modules" + _ "github.com/go-python/gpython/stdlib" // Commonly consumed gpython "github.com/go-python/gpython/py" @@ -27,8 +27,8 @@ func runWithFile(pyFile string) error { // See type Context interface and related docs ctx := py.NewContext(py.DefaultContextOpts()) - - // This drives modules being able to perform cleanup and release resources + + // This drives modules being able to perform cleanup and release resources defer ctx.Close() var err error diff --git a/examples/multi-context/main.go b/examples/multi-context/main.go index 4bbeda8b..f645e766 100644 --- a/examples/multi-context/main.go +++ b/examples/multi-context/main.go @@ -14,7 +14,7 @@ import ( // This initializes gpython for runtime execution and is critical. // It defines forward-declared symbols and registers native built-in modules, such as sys and time. - _ "github.com/go-python/gpython/modules" + _ "github.com/go-python/gpython/stdlib" // This is the primary import for gpython. // It contains all symbols needed to fully compile and run python. @@ -129,7 +129,7 @@ func RunMultiPi(numWorkers, numTimes int) time.Duration { } workersRunning.Done() - // This drives modules being able to perform cleanup and release resources + // This drives modules being able to perform cleanup and release resources w.ctx.Close() }() } diff --git a/main.go b/main.go index d529646a..bc906aac 100644 --- a/main.go +++ b/main.go @@ -14,10 +14,11 @@ import ( "runtime" "runtime/pprof" - _ "github.com/go-python/gpython/modules" "github.com/go-python/gpython/py" "github.com/go-python/gpython/repl" "github.com/go-python/gpython/repl/cli" + + _ "github.com/go-python/gpython/stdlib" ) // Globals diff --git a/pytest/pytest.go b/pytest/pytest.go index db556f6e..7cadadb1 100644 --- a/pytest/pytest.go +++ b/pytest/pytest.go @@ -11,10 +11,10 @@ import ( "strings" "testing" - _ "github.com/go-python/gpython/modules" - "github.com/go-python/gpython/compile" "github.com/go-python/gpython/py" + + _ "github.com/go-python/gpython/stdlib" ) var gContext = py.NewContext(py.DefaultContextOpts()) diff --git a/repl/repl_test.go b/repl/repl_test.go index 9c64879e..3c13c7c6 100644 --- a/repl/repl_test.go +++ b/repl/repl_test.go @@ -6,7 +6,7 @@ import ( "testing" // import required modules - _ "github.com/go-python/gpython/modules" + _ "github.com/go-python/gpython/stdlib" ) type replTest struct { diff --git a/repl/web/main.go b/repl/web/main.go index 0be6f3cd..f0cebfd8 100644 --- a/repl/web/main.go +++ b/repl/web/main.go @@ -13,12 +13,11 @@ import ( "log" "runtime" + "github.com/go-python/gpython/repl" "github.com/gopherjs/gopherwasm/js" // gopherjs to wasm converter shim // import required modules - _ "github.com/go-python/gpython/modules" - - "github.com/go-python/gpython/repl" + _ "github.com/go-python/gpython/stdlib" ) // Implement the replUI interface diff --git a/modules/runtime.go b/stdlib/stdlib.go similarity index 97% rename from modules/runtime.go rename to stdlib/stdlib.go index 0b003022..5298b7e7 100644 --- a/modules/runtime.go +++ b/stdlib/stdlib.go @@ -2,7 +2,9 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package modules +// Package stdlib provides the bootstrap code to wire in all the stdlib +// (python) modules into a gpython context and VM. +package stdlib import ( "bytes" From e8acd73a892dba1a0d9a87c9dfd68827d1fa8bdb Mon Sep 17 00:00:00 2001 From: Sebastien Binet Date: Wed, 23 Mar 2022 17:33:47 +0100 Subject: [PATCH 2/2] all: move gpython py-modules under stdlib --- .gitignore | 4 ++-- {builtin => stdlib/builtin}/builtin.go | 0 {builtin => stdlib/builtin}/builtin_test.go | 0 {builtin => stdlib/builtin}/tests/builtin.py | 0 {builtin => stdlib/builtin}/tests/lib.py | 0 {builtin => stdlib/builtin}/tests/libtest.py | 0 {math => stdlib/math}/math.go | 0 {math => stdlib/math}/math_test.go | 0 {math => stdlib/math}/tests/libtest.py | 0 {math => stdlib/math}/tests/libulp.py | 0 {math => stdlib/math}/tests/mathtests.py | 0 {math => stdlib/math}/tests/testcases.py | 0 stdlib/stdlib.go | 8 ++++---- {sys => stdlib/sys}/sys.go | 0 {time => stdlib/time}/time.go | 0 15 files changed, 6 insertions(+), 6 deletions(-) rename {builtin => stdlib/builtin}/builtin.go (100%) rename {builtin => stdlib/builtin}/builtin_test.go (100%) rename {builtin => stdlib/builtin}/tests/builtin.py (100%) rename {builtin => stdlib/builtin}/tests/lib.py (100%) rename {builtin => stdlib/builtin}/tests/libtest.py (100%) rename {math => stdlib/math}/math.go (100%) rename {math => stdlib/math}/math_test.go (100%) rename {math => stdlib/math}/tests/libtest.py (100%) rename {math => stdlib/math}/tests/libulp.py (100%) rename {math => stdlib/math}/tests/mathtests.py (100%) rename {math => stdlib/math}/tests/testcases.py (100%) rename {sys => stdlib/sys}/sys.go (100%) rename {time => stdlib/time}/time.go (100%) diff --git a/.gitignore b/.gitignore index ff8d3cdb..dc9b73bb 100644 --- a/.gitignore +++ b/.gitignore @@ -10,5 +10,5 @@ cover.out /dist # tests -builtin/testfile -examples/embedding/embedding \ No newline at end of file +stdlib/builtin/testfile +examples/embedding/embedding diff --git a/builtin/builtin.go b/stdlib/builtin/builtin.go similarity index 100% rename from builtin/builtin.go rename to stdlib/builtin/builtin.go diff --git a/builtin/builtin_test.go b/stdlib/builtin/builtin_test.go similarity index 100% rename from builtin/builtin_test.go rename to stdlib/builtin/builtin_test.go diff --git a/builtin/tests/builtin.py b/stdlib/builtin/tests/builtin.py similarity index 100% rename from builtin/tests/builtin.py rename to stdlib/builtin/tests/builtin.py diff --git a/builtin/tests/lib.py b/stdlib/builtin/tests/lib.py similarity index 100% rename from builtin/tests/lib.py rename to stdlib/builtin/tests/lib.py diff --git a/builtin/tests/libtest.py b/stdlib/builtin/tests/libtest.py similarity index 100% rename from builtin/tests/libtest.py rename to stdlib/builtin/tests/libtest.py diff --git a/math/math.go b/stdlib/math/math.go similarity index 100% rename from math/math.go rename to stdlib/math/math.go diff --git a/math/math_test.go b/stdlib/math/math_test.go similarity index 100% rename from math/math_test.go rename to stdlib/math/math_test.go diff --git a/math/tests/libtest.py b/stdlib/math/tests/libtest.py similarity index 100% rename from math/tests/libtest.py rename to stdlib/math/tests/libtest.py diff --git a/math/tests/libulp.py b/stdlib/math/tests/libulp.py similarity index 100% rename from math/tests/libulp.py rename to stdlib/math/tests/libulp.py diff --git a/math/tests/mathtests.py b/stdlib/math/tests/mathtests.py similarity index 100% rename from math/tests/mathtests.py rename to stdlib/math/tests/mathtests.py diff --git a/math/tests/testcases.py b/stdlib/math/tests/testcases.py similarity index 100% rename from math/tests/testcases.py rename to stdlib/math/tests/testcases.py diff --git a/stdlib/stdlib.go b/stdlib/stdlib.go index 5298b7e7..7b46d391 100644 --- a/stdlib/stdlib.go +++ b/stdlib/stdlib.go @@ -18,10 +18,10 @@ import ( "github.com/go-python/gpython/py" "github.com/go-python/gpython/vm" - _ "github.com/go-python/gpython/builtin" - _ "github.com/go-python/gpython/math" - _ "github.com/go-python/gpython/sys" - _ "github.com/go-python/gpython/time" + _ "github.com/go-python/gpython/stdlib/builtin" + _ "github.com/go-python/gpython/stdlib/math" + _ "github.com/go-python/gpython/stdlib/sys" + _ "github.com/go-python/gpython/stdlib/time" ) func init() { diff --git a/sys/sys.go b/stdlib/sys/sys.go similarity index 100% rename from sys/sys.go rename to stdlib/sys/sys.go diff --git a/time/time.go b/stdlib/time/time.go similarity index 100% rename from time/time.go rename to stdlib/time/time.go