-
Notifications
You must be signed in to change notification settings - Fork 41
Wes/module system #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
68 commits
Select commit
Hold shift + click to select a range
f6c35f1
Add package.json for npm/JS dependencies
9b313fc
Add node-compatible require() for CommonJS modules
156feb8
use-require example: update include() so that cwd doesn't matter
8f480ed
pythonmonkey_require - improve code clarity; now compatible with late…
72f4f46
pythonmonkey_require - add python JS global, improve debug function, …
c89036b
pythonmonkey_require - add sys.paths+/node_modules to module.paths
264a9d4
pythonmonkey_require - add support for .py modules
704baca
pythonmonkey_require - fix support for directory/index modules
aed2672
Update README to reflect module system progress
7c4cbfb
feat: Updated pythonmonkey_require to use pythonic module loading use…
ca2d68f
chore: Add some pythonic comments and type hinting for devs
55bff26
fix: Fixed import for importlib machinery to keep it in scope and bet…
9bc5d09
rename exports to module_exports to make sure semantics aren't confused
cca1218
fix: pythonmonkey_require - Make sure memoized modules are also expor…
8f43482
feat: Updated variable names in examples, more accurate python module…
77d5473
fix: Delete mistakenly copied additional file
fad3dba
Merge branch 'BF-38' into wes/module-system
27c8ee0
Merge branch 'hamada/module-system' into wes/module-system
0839bae
Merge: main into module system to update build system
1544520
WIP: Updated pythonmonkey_require to be in pythonmonkey directory and…
ddbdb92
chore: `npm i` should be run in `python/pythonmonkey` directory
Xmader bcd6f67
test(promise): fix regex doesn't match when having `ctx-module`
Xmader 3423f19
chore: must explicitly include `node_modules` into the wheel package
Xmader acc13d0
Merge pull request #47 from Distributive-Network/Xmader/fix/module-sy…
Hamada-Distributed 336b0cc
Add reentrance_smoke test
32b09f4
eval - implement support for compilation options
0ea3b54
Add simple console.log placeholder
7456148
Add simple js testing
fc3314b
peter-jr - improve output
7eaa6c7
Add trivial REPL; pmjs
4fdb52d
Add hard-coded __version__ to pythonmonkey module
ab1a0a3
Add emacs tmp files to .gitignore
baa2c66
Add (dormant) implementation of runInContext for require
01d34e2
Generate __version__ directly from pyproject.toml at build time
wesgarland a246b51
Add console smoke test
wesgarland 7619a00
require - add ./builtin_modules/ to list of search paths
wesgarland 2c594e5
temp console - plumb-in globalThis.console as a side-effect of loadin…
wesgarland 5118c58
Update key file locations and paths so that createRequire can be expo…
wesgarland be29725
Update examples to load createRequire from pythonmonkey module
wesgarland 8c74c23
peter-jr - improve output
wesgarland ed09e2a
Add python-language CommonJS module test
wesgarland 89a78ca
Add isCompilableUnit to support writing JS REPLs
wesgarland e3f8e8f
pmjs - exit REPL when ^D
wesgarland 7a7477c
Add test coverage for isCompilableUnit
wesgarland e3e7ff4
pmjs - add support for multi-line statements, result colourization, i…
wesgarland 70c37e8
pmjs - improve Error output
wesgarland 1c2966c
pmjs - implement half-baked sigint handler; might need to escape read…
wesgarland a9a9e9b
pmjs - improve code readability and command argument parsing
wesgarland 7206801
Add basic smoke-test for CommonJS module loading
wesgarland e1fd220
require.py - remove globalSet and propSet hacks, depends on ctx-modul…
wesgarland 311b46e
chore: make pythonmonkey python files more pythonic and update tests
da3a900
build_script.sh - stop growing version.py
wesgarland 7270d4c
peter-jr - fix argv parsing, add test-failure exit code
wesgarland 334fb0d
pmjs - police whitespace
wesgarland 7f38d25
Merge branch 'BF-38' into wes/module-system-main-merge
wesgarland 7bc5a5f
add pmjs-require.js
wesgarland 4c11666
pmjs, require examples, etc - let poetry manage sys.path to find pyth…
wesgarland bfee9f2
Add builtin_modules to wheel
wesgarland 4087f37
Change cmake LINUX variables to UNIX so that the build builds
wesgarland 2b1dbf4
re-fix rpath for appple in CMakeLists.txt
wesgarland 3e39ead
Remove cmake inputs from .gitignore
wesgarland 3062532
Merge remote-tracking branch 'origin/hamada/update-module-system' int…
wesgarland fb7cb57
Merge branch 'main' into wes/module-system
wesgarland 3afea05
Merge branch 'main' into wes/module-system
Xmader 1066eeb
docs: update README.md
Xmader 90f981d
chore: fix src/CMakeLists.txt typo
Xmader 04d3303
Update README.md to reflect roadmap advances
wesgarland 8445eee
README - add examples section
wesgarland File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,22 @@ | ||
build/ | ||
.vscode/ | ||
pyvenv.cfg | ||
python/pythonmonkey/version.py | ||
python/pythonmonkey/node_modules | ||
bin/ | ||
lib/* | ||
.pytest_cache | ||
.DS_Store | ||
firefox-*.tar.xz | ||
firefox-*/ | ||
tests/__pycache__/* | ||
tests/python/__pycache__/* | ||
__pycache__ | ||
Testing/Temporary | ||
_spidermonkey_install | ||
__pycache__ | ||
__pycache__/* | ||
dist | ||
*.so | ||
_spidermonkey_install/* | ||
wesgarland marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*~ | ||
*.dylib | ||
*.dll | ||
*.pyd |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# @file use-require.py | ||
# Sample code which demonstrates how to use require | ||
# @author Wes Garland, wes@distributive.network | ||
# @date Jun 2023 | ||
|
||
import pythonmonkey as pm | ||
|
||
require = pm.createRequire(__file__) | ||
require('./use-python-module'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const { helloWorld } = require('./my-python-module'); | ||
helloWorld() | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
def helloWorld(): | ||
print('hello, world!') | ||
|
||
exports['helloWorld'] = helloWorld | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# @file use-require.py | ||
# Sample code which demonstrates how to use require | ||
# @author Wes Garland, wes@distributive.network | ||
# @date Jun 2023 | ||
|
||
import pythonmonkey as pm | ||
|
||
require = pm.createRequire(__file__) | ||
require('./use-require/test1'); | ||
print("Done") | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict' | ||
|
||
const makeOutput = require('./test2').makeOutput; | ||
|
||
makeOutput('hello world'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict' | ||
|
||
exports.makeOutput = function makeOutput() | ||
{ | ||
const argv = Array.from(arguments); | ||
argv.unshift('TEST OUTPUT: '); | ||
python.print.apply(null, argv); | ||
wesgarland marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#! /usr/bin/env python3 | ||
# @file js-test-runner | ||
# A simple test driver for peter-jr that runs JS code via PythonMonkey.require | ||
# @author Wes Garland, wes@distributive.network | ||
# @date Jun 2023 | ||
|
||
import sys, os | ||
import pythonmonkey as pm | ||
|
||
# Main | ||
require = pm.createRequire(__file__) | ||
require('console'); | ||
|
||
testName = os.path.realpath(sys.argv[1]); | ||
testDir = os.path.dirname(testName); | ||
pm.createRequire(testName)(testName); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
#! /bin/bash | ||
# | ||
# @file peter-js | ||
# A simple test framework in the spirit of Peter (npmjs.com/packages/peter) for testing | ||
# basic PythonMonkey functionality. | ||
# | ||
# Exit Codes: | ||
# 0 - all tests passed | ||
# 1 - one or more tests failed | ||
# 2 - no tests ran | ||
# 3 - internal error | ||
# | ||
# @author Wes Garland, wes@distributive.network | ||
# @date Jun 2023 | ||
# | ||
runDir=`pwd` | ||
cd `dirname "$0"` | ||
topDir=`pwd` | ||
cd "$runDir" | ||
|
||
set -u | ||
set -o pipefail | ||
peter_exit_code=2 | ||
|
||
if [ "${1:-}" = "-v" ]; then | ||
VERBOSE=1 | ||
shift | ||
else | ||
VERBOSE="${VERBOSE:-}" | ||
fi | ||
|
||
[ "${1:-}" ] || set "${topDir}/tests/js" | ||
testLocations=("$@") | ||
|
||
function panic() | ||
{ | ||
echo "PANIC: $*" >&2 | ||
exit 3 | ||
} | ||
|
||
TMP=`mktemp -d` | ||
([ "${TMP}" ] && [ -d "${TMP}" ]) || exit 3 | ||
|
||
trap "rm -r \"${TMP}\"" EXIT | ||
|
||
if [ "$VERBOSE" ]; then | ||
stdout="/dev/stdout" | ||
stderr="/dev/stderr" | ||
else | ||
stdout="$TMP/stdout" | ||
stderr="$TMP/stderr" | ||
fi | ||
|
||
red() | ||
{ | ||
printf "\e[0;31m%s\e[0m" "$*" | ||
} | ||
|
||
green() | ||
{ | ||
printf "\e[0;32m%s\e[0m" "$*" | ||
} | ||
|
||
yellow() | ||
{ | ||
printf "\e[0;33m%s\e[0m" "$*" | ||
} | ||
|
||
grey() | ||
{ | ||
printf "\e[0;90m%s\e[0m" "$*" | ||
} | ||
|
||
( | ||
for loc in "${testLocations[@]}" | ||
do | ||
find $(realpath "$loc") -type f -name \*.simple | ||
find $(realpath "$loc") -type f -name \*.bash | ||
done | ||
) \ | ||
| while read file | ||
do | ||
sfile=$(realpath --relative-to="${runDir}" "${file}") | ||
printf 'Testing %-40s ... ' "${sfile}" | ||
ext="${file##*.}" | ||
( | ||
case "$ext" in | ||
"simple") | ||
"${topDir}/js-test-runner" "$file" | ||
exitCode="$?" | ||
;; | ||
"bash") | ||
bash "$file" | ||
exitCode="$?" | ||
;; | ||
*) | ||
echo | ||
panic "${file}: invalid extension '$ext'" | ||
;; | ||
esac | ||
|
||
exit "$exitCode" | ||
)> $stdout 2>$stderr | ||
exitCode="$?" | ||
|
||
if [ "$exitCode" = "0" ]; then | ||
echo "$(green PASS)" | ||
[ "${peter_exit_code}" = "2" ] && peter_exit_code=0 | ||
printf "\e[0;31m" | ||
[ "$VERBOSE" ] || cat "$stderr" | ||
printf "\e[0m" | ||
else | ||
echo "$(red FAIL)" | ||
peter_exit_code=1 | ||
if [ ! "$VERBOSE" ]; then | ||
echo | ||
echo "$(grey --) $(yellow ${file}) $(grey vvvvvvvvvvvvvv)" | ||
cat "$stdout" | sed 's/^/ /' | ||
printf "\e[0;31m" | ||
cat "$stderr" | sed -e 's/^/ /' | ||
printf "\e[0m" | ||
echo "$(grey --) $(yellow ${file}) $(grey ^^^^^^^^^^^^^^)" | ||
echo | ||
fi | ||
fi | ||
(exit ${peter_exit_code}) | ||
done | ||
peter_exit_code="$?" | ||
|
||
exit ${peter_exit_code} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.