Skip to content

Commit 5a6afd0

Browse files
committed
Merge branch 'main' into wes/pmjs-use-inspect
2 parents af2832e + 59642c3 commit 5a6afd0

File tree

17 files changed

+217
-42
lines changed

17 files changed

+217
-42
lines changed

.github/workflows/test-and-publish.yaml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ defaults:
2323
jobs:
2424
build-spidermonkey-unix:
2525
strategy:
26+
fail-fast: false
2627
matrix:
2728
# Use Ubuntu 20.04 / macOS 12 + Python 3.10 to build SpiderMonkey
2829
os: [ 'ubuntu-20.04', 'macos-12', 'm2ci' ]
@@ -39,8 +40,13 @@ jobs:
3940
with:
4041
path: |
4142
./_spidermonkey_install/*
42-
key: spidermonkey-${{ runner.os }}-${{ runner.arch }}
43+
key: spidermonkey102.13-${{ runner.os }}-${{ runner.arch }}
4344
lookup-only: true # skip download
45+
- name: Setup Poetry
46+
if: ${{ steps.cache-spidermonkey.outputs.cache-hit != 'true' }}
47+
uses: snok/install-poetry@v1
48+
with:
49+
version: 1.5.1
4450
- name: Build spidermonkey
4551
if: ${{ steps.cache-spidermonkey.outputs.cache-hit != 'true' }}
4652
run: ./setup.sh
@@ -54,8 +60,13 @@ jobs:
5460
with:
5561
path: |
5662
./_spidermonkey_install/*
57-
key: spidermonkey-${{ runner.os }}-${{ runner.arch }}
63+
key: spidermonkey102.13-${{ runner.os }}-${{ runner.arch }}
5864
lookup-only: true # skip download
65+
- name: Setup Poetry
66+
if: ${{ steps.cache-spidermonkey.outputs.cache-hit != 'true' }}
67+
uses: snok/install-poetry@v1
68+
with:
69+
version: 1.5.1
5970
- name: Install dependencies
6071
if: ${{ steps.cache-spidermonkey.outputs.cache-hit != 'true' }}
6172
shell: powershell
@@ -124,7 +135,7 @@ jobs:
124135
with:
125136
path: |
126137
./_spidermonkey_install/*
127-
key: spidermonkey-${{ runner.os }}-${{ runner.arch }}
138+
key: spidermonkey102.13-${{ runner.os }}-${{ runner.arch }}
128139
fail-on-cache-miss: true # SpiderMonkey is expected to be cached in its dedicated job
129140
- name: Build pminit
130141
run: |
@@ -147,6 +158,11 @@ jobs:
147158
run: |
148159
poetry run python -m pip install --force-reinstall ./dist/*
149160
poetry run python -m pytest tests/python
161+
- name: Run JS tests (peter-jr)
162+
if: ${{ runner.os != 'Windows' }} # Python on Windows doesn't have the readline library
163+
# FIXME: on macOS we must make sure to use the GNU version of wc and realpath
164+
run: |
165+
poetry run bash ./peter-jr ./tests/js/
150166
sdist:
151167
runs-on: ubuntu-20.04
152168
steps:

.gitmodules

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[submodule "tests/commonjs-official"]
2-
path = tests/commonjs-official
3-
url = git@github.com:commonjs/commonjs.git
2+
path = tests/commonjs-official
3+
url = https://github.com/commonjs/commonjs.git

.vscode/launch.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "(gdb) Debug",
6+
"type": "cppdbg",
7+
"request": "launch",
8+
"program": "python",
9+
"args": [
10+
"${file}"
11+
],
12+
"pipeTransport": {
13+
"pipeCwd": "${workspaceFolder}",
14+
"pipeProgram": "poetry",
15+
"quoteArgs": false,
16+
"pipeArgs": [
17+
"run"
18+
],
19+
},
20+
"preLaunchTask": "Build",
21+
"cwd": "${fileDirname}",
22+
"environment": [],
23+
"externalConsole": false,
24+
"MIMode": "gdb",
25+
"setupCommands": [
26+
{
27+
"description": "Enable pretty-printing for gdb",
28+
"text": "-enable-pretty-printing",
29+
"ignoreFailures": true
30+
},
31+
{
32+
"description": "Set Disassembly Flavor to Intel",
33+
"text": "-gdb-set disassembly-flavor intel",
34+
"ignoreFailures": true
35+
}
36+
]
37+
},
38+
]
39+
}

.vscode/tasks.json

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"tasks": [
3+
//
4+
// Setup
5+
//
6+
{
7+
"label": "Setup SpiderMonkey",
8+
"type": "process",
9+
"command": "./setup.sh",
10+
},
11+
//
12+
// Build
13+
//
14+
{
15+
"label": "Build",
16+
"type": "process",
17+
"command": "poetry",
18+
"args": [
19+
"install",
20+
],
21+
"problemMatcher": [
22+
"$gcc"
23+
],
24+
"group": {
25+
"kind": "build",
26+
"isDefault": true
27+
}
28+
},
29+
//
30+
// Test
31+
//
32+
{
33+
"label": "Install development dependencies",
34+
"type": "process",
35+
"command": "poetry",
36+
"args": [
37+
"install",
38+
"--no-root",
39+
"--only=dev"
40+
],
41+
},
42+
{
43+
"label": "Run pytest",
44+
"type": "process",
45+
"command": "poetry",
46+
"args": [
47+
"run",
48+
"pytest",
49+
"./tests/python"
50+
],
51+
},
52+
{
53+
"label": "Test",
54+
"dependsOrder": "sequence",
55+
"dependsOn": [
56+
"Install development dependencies",
57+
"Run pytest",
58+
],
59+
"group": {
60+
"kind": "test",
61+
"isDefault": true
62+
}
63+
},
64+
],
65+
"options": {
66+
"cwd": "${workspaceFolder}"
67+
},
68+
"problemMatcher": [],
69+
"version": "2.0.0"
70+
}

README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ this package to execute our complex `dcp-client` library, which is written in JS
4545
- [done] JS TypedArrays coerce to Python TypeArrays
4646

4747
## Build Instructions
48-
1. You will need the following installed (which can be done automatically by running ``./setup.sh``):
48+
49+
Read this if you want to build a local version.
50+
51+
1. You will need the following installed (which can be done automatically by running `./setup.sh`):
4952
- bash
5053
- cmake
5154
- doxygen
@@ -58,13 +61,17 @@ this package to execute our complex `dcp-client` library, which is written in JS
5861
- [Poetry](https://python-poetry.org/docs/#installation)
5962
- [poetry-dynamic-versioning](https://github.com/mtkennerly/poetry-dynamic-versioning)
6063

61-
2. Run `poetry run pip install --verbose python/pminit ./`. This command automatically compiles the project and installs the project as well as dependencies into the poetry virtualenv.
64+
2. Run `poetry install`. This command automatically compiles the project and installs the project as well as dependencies into the poetry virtualenv.
65+
66+
If you are using VSCode, you can just press <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>B</kbd> to [run build task](https://code.visualstudio.com/docs/editor/tasks#_custom-tasks) - We have [the `tasks.json` file configured for you](.vscode/tasks.json).
6267

6368
## Running tests
6469
1. Compile the project
6570
2. Install development dependencies: `poetry install --no-root --only=dev`
6671
3. From the root directory, run `poetry run pytest ./tests/python`
6772

73+
For VSCode users, similar to the Build Task, we have a Test Task ready to use.
74+
6875
## Using the library
6976

7077
### Install from [PyPI](https://pypi.org/project/pythonmonkey/)
@@ -99,6 +106,14 @@ Type "help", "copyright", "credits" or "license" for more information.
99106

100107
Alternatively, you can build a `wheel` package by running `poetry build --format=wheel`, and install it by `pip install dist/*.whl`.
101108

109+
## Debugging Steps
110+
111+
1. [build the project locally](#build-instructions)
112+
2. To use gdb, run `poetry run gdb python`.
113+
See [Python Wiki: DebuggingWithGdb](https://wiki.python.org/moin/DebuggingWithGdb)
114+
115+
If you are using VSCode, it's more convenient to debug in [VSCode's built-in debugger](https://code.visualstudio.com/docs/editor/debugging). Simply press <kbd>F5</kbd> on an open Python to start debugging - We have [the `launch.json` file configured for you](.vscode/launch.json).
116+
102117
## Examples
103118

104119
* [examples/](examples/)

TODO.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

build.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ def build():
5757
ensure_spidermonkey()
5858
run_cmake_build()
5959
copy_artifacts()
60-
os.chdir(TOP_DIR + "/python/pminit")
61-
execute(sys.executable + " ./post-install-hook.py")
6260

6361
if __name__ == "__main__":
6462
build()

examples/use-python-module.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@
55

66
import pythonmonkey as pm
77

8-
require = pm.createRequire(__file__)
9-
require('./use-python-module');
8+
pm.require('./use-python-module');

examples/use-require.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import pythonmonkey as pm
77

8-
require = pm.createRequire(__file__)
9-
require('./use-require/test1');
8+
pm.require('./use-require/test1');
109
print("Done")
1110

pmjs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ if (os.getenv('PMJS_PATH')):
1212
else:
1313
requirePath = False;
1414

15+
globalThis = pm.eval("globalThis;")
16+
1517
pm.eval("""'use strict';
1618
const cmds = {};
1719
@@ -104,7 +106,10 @@ def repl():
104106
readline.parse_and_bind('set editing-mode emacs')
105107
histfile = os.getenv('PMJS_REPL_HISTORY') or os.path.expanduser('~/.pmjs_history')
106108
if (os.path.exists(histfile)):
107-
readline.read_history_file(histfile)
109+
try:
110+
readline.read_history_file(histfile)
111+
except:
112+
pass
108113

109114
got_sigint = 0
110115
statement = ''

0 commit comments

Comments
 (0)