Skip to content

Commit 095f46b

Browse files
authored
Merge branch 'main' into Xmader/feat/npm-py
2 parents 2b99eeb + c8aa8d7 commit 095f46b

File tree

80 files changed

+2661
-507
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+2661
-507
lines changed

.git-blame-ignore-revs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,10 @@ aae30e864449442cf0b04e94f8a242b1b667de9a
55
16dc3153b3cb684ca72445ed058babc8f5d97f42
66

77
# chore(linting): lint all C++ files
8-
58cd4b45777b046f03a63255c1d93e289e1cab5e
8+
58cd4b45777b046f03a63255c1d93e289e1cab5e
9+
10+
# chore(linting): lint PyBytesProxyHandler.cc
11+
d540ed6e0edfe9538dc726cf587dfb2cc76dde34
12+
13+
# chore(linting): lint PyObjectProxyHandler.cc
14+
1d45ea98e42294cce16deec5454725d4de36f59f

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

Lines changed: 67 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ on:
1717
- ''
1818
- 'ubuntu-20.04'
1919
- 'macos-12'
20-
- 'macos-13'
2120
- 'macos-14'
22-
- 'windows-2019'
21+
- 'windows-2022'
2322
debug_enabled_python:
2423
type: choice
2524
description: Choose a Python version to run the build with SSH debugging on
@@ -61,42 +60,47 @@ jobs:
6160
fail-fast: false
6261
matrix:
6362
# Use Ubuntu 20.04 / macOS 13 x86_64 / macOS 14 arm64 + Python 3.10 to build SpiderMonkey
64-
os: [ 'ubuntu-20.04', 'macos-13', 'macos-14' ] # macOS 14 runner exclusively runs on M1 hardwares
65-
# see https://github.blog/changelog/2024-01-30-github-actions-macos-14-sonoma-is-now-available
63+
os: [ 'ubuntu-20.04', 'macos-13', 'macos-14', 'pi' ] # macOS 14 runner exclusively runs on M1 hardwares
64+
# see https://github.blog/changelog/2024-01-30-github-actions-macos-14-sonoma-is-now-available
6665
python_version: [ '3.10' ]
6766
runs-on: ${{ matrix.os }}
6867
steps:
6968
- uses: actions/checkout@v4
7069
- uses: actions/setup-python@v5
7170
with:
7271
python-version: ${{ matrix.python_version }}
72+
- name: Read the mozilla-central commit hash to be used
73+
run: echo "MOZCENTRAL_VERSION=$(cat mozcentral.version)" >> $GITHUB_ENV
7374
- name: Cache spidermonkey build
7475
id: cache-spidermonkey
7576
uses: actions/cache@v4
7677
with:
7778
path: |
7879
./_spidermonkey_install/*
79-
key: spidermonkey115.8.0-${{ runner.os }}-${{ runner.arch }}
80+
key: spidermonkey-${{ env.MOZCENTRAL_VERSION }}-${{ runner.os }}-${{ runner.arch }}
8081
lookup-only: true # skip download
8182
- name: Setup XCode
8283
if: ${{ (matrix.os == 'macos-13' || matrix.os == 'macos-14') && steps.cache-spidermonkey.outputs.cache-hit != 'true' }}
83-
# SpiderMonkey 115 ESR requires XCode SDK version at least 13.3
84-
# https://github.com/actions/runner-images/blob/main/images/macos/macos-13-Readme.md#installed-sdks
84+
# SpiderMonkey requires XCode SDK version at least 13.3
8585
run: sudo xcode-select -switch /Applications/Xcode_14.3.app
8686
- name: Build spidermonkey
8787
if: ${{ steps.cache-spidermonkey.outputs.cache-hit != 'true' }}
8888
run: ./setup.sh
8989
build-spidermonkey-win:
90-
runs-on: windows-2019
90+
runs-on: windows-2022
91+
# SpiderMonkey requires Visual Studio 2022 or newer.
92+
# The Windows 2019 runner only has Visual Studio Enterprise 2019 installed.
9193
steps:
9294
- uses: actions/checkout@v4
95+
- name: Read the mozilla-central commit hash to be used
96+
run: echo "MOZCENTRAL_VERSION=$(cat mozcentral.version)" >> $GITHUB_ENV
9397
- name: Cache spidermonkey build
9498
id: cache-spidermonkey
9599
uses: actions/cache@v4
96100
with:
97101
path: |
98102
./_spidermonkey_install/*
99-
key: spidermonkey115.8.0-${{ runner.os }}-${{ runner.arch }}
103+
key: spidermonkey-${{ env.MOZCENTRAL_VERSION }}-${{ runner.os }}-${{ runner.arch }}
100104
lookup-only: true # skip download
101105
- name: Install dependencies
102106
if: ${{ steps.cache-spidermonkey.outputs.cache-hit != 'true' }}
@@ -105,7 +109,7 @@ jobs:
105109
# Already installed in Github Actions runner
106110
# choco install -y cmake --installargs 'ADD_CMAKE_TO_PATH=System' # add CMake to system PATH
107111
# choco install -y llvm gnuwin32-m4
108-
choco install -y wget make
112+
choco install -y wget make unzip
109113
- name: Install MozillaBuild
110114
if: ${{ steps.cache-spidermonkey.outputs.cache-hit != 'true' }}
111115
run: |
@@ -123,19 +127,8 @@ jobs:
123127
strategy:
124128
fail-fast: false
125129
matrix:
126-
# The lowest supported version is Ubuntu 20.04 + Python 3.8 or macOS 12 + Python 3.9
127-
os: [ 'ubuntu-20.04', 'macos-12', 'macos-13', 'macos-14', 'windows-2019' ]
130+
os: [ 'ubuntu-20.04', 'macos-12', 'macos-14', 'windows-2022', 'pi' ]
128131
python_version: [ '3.8', '3.9', '3.10', '3.11', '3.12' ]
129-
exclude:
130-
# macOS 12 comes with Python 3.9 by default, so we drop ci support for Python 3.8 on macOS
131-
- os: 'macos-12'
132-
python_version: '3.8'
133-
# actions/setup-python: The version '3.8'/'3.9' with architecture 'arm64' was not found for macOS.
134-
# see https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json
135-
- os: 'macos-14'
136-
python_version: '3.8'
137-
- os: 'macos-14'
138-
python_version: '3.9'
139132
runs-on: ${{ matrix.os }}
140133
steps:
141134
- uses: actions/checkout@v4
@@ -146,6 +139,9 @@ jobs:
146139
- uses: actions/setup-python@v5
147140
with:
148141
python-version: ${{ matrix.python_version }}
142+
- name: Remove old poetry cache
143+
run: rm -rf ~/.cache/pypoetry
144+
if: ${{ matrix.os == 'pi' }}
149145
- name: Setup Poetry
150146
uses: snok/install-poetry@v1
151147
with:
@@ -155,22 +151,42 @@ jobs:
155151
echo "Installing Dependencies"
156152
if [[ "$OSTYPE" == "linux-gnu"* ]]; then # Linux
157153
sudo apt-get update -y
158-
sudo apt-get install -y cmake graphviz llvm
154+
sudo apt-get install -y cmake llvm
159155
elif [[ "$OSTYPE" == "darwin"* ]]; then # macOS
160156
brew update || true # allow failure
161-
brew install cmake pkg-config wget coreutils # `coreutils` installs the `realpath` command
157+
brew install cmake pkg-config wget unzip coreutils # `coreutils` installs the `realpath` command
162158
fi
163159
echo "Installing python deps"
164160
poetry self add "poetry-dynamic-versioning[plugin]"
165-
poetry env use python3 # use the correct Python version we've set up
161+
poetry env use python$PYTHON_VERSION || poetry env use python3 # use the correct Python version we've set up
166162
poetry install --no-root --only=dev
167163
echo "Installed Dependencies"
164+
env:
165+
PYTHON_VERSION: ${{ matrix.python_version }}
166+
- name: Build Docs # only build docs once
167+
if: ${{ matrix.os == 'ubuntu-20.04' && matrix.python_version == '3.11' }}
168+
run: |
169+
sudo apt-get install -y graphviz
170+
# the newest version in Ubuntu 20.04 repository is 1.8.17, but we need Doxygen 1.9 series
171+
wget -c -q https://www.doxygen.nl/files/doxygen-1.9.7.linux.bin.tar.gz
172+
tar xf doxygen-1.9.7.linux.bin.tar.gz
173+
cd doxygen-1.9.7 && sudo make install && cd -
174+
rm -rf doxygen-1.9.7 doxygen-1.9.7.linux.bin.tar.gz
175+
BUILD_DOCS=1 BUILD_TYPE=None poetry install
176+
- name: Upload Doxygen-generated docs as CI artifacts
177+
if: ${{ matrix.os == 'ubuntu-20.04' && matrix.python_version == '3.11' }}
178+
uses: actions/upload-artifact@v3
179+
with:
180+
name: docs-${{ github.run_id }}-${{ github.sha }}
181+
path: ./build/docs/html/
182+
- name: Read the mozilla-central commit hash to be used
183+
run: echo "MOZCENTRAL_VERSION=$(cat mozcentral.version)" >> $GITHUB_ENV
168184
- name: Use cached spidermonkey build
169185
uses: actions/cache@v4
170186
with:
171187
path: |
172188
./_spidermonkey_install/*
173-
key: spidermonkey115.8.0-${{ runner.os }}-${{ runner.arch }}
189+
key: spidermonkey-${{ env.MOZCENTRAL_VERSION }}-${{ runner.os }}-${{ runner.arch }}
174190
fail-on-cache-miss: true # SpiderMonkey is expected to be cached in its dedicated job
175191
- name: Build pminit
176192
run: |
@@ -185,13 +201,24 @@ jobs:
185201
WORKFLOW_BUILD_TYPE=${{ inputs.build_type }}
186202
BUILD_TYPE=${WORKFLOW_BUILD_TYPE:-"Debug"} poetry build --format=wheel
187203
ls -lah ./dist/
204+
- name: Make the wheels we build also support lower versions of macOS
205+
if: ${{ matrix.os == 'macos-12' || matrix.os == 'macos-14' }}
206+
# Change the platform tag part of the wheel filename to `macosx_11_0_xxx` (means to support macOS 11.0 and above)
207+
# See https://packaging.python.org/en/latest/specifications/binary-distribution-format/#file-format
208+
# A wheel package file will only be selected by pip to install if the platform tag satisfies, regardless of whether the binary compatibility actually is.
209+
# Otherwise, pip would fallback to compile from the source distribution.
210+
run: |
211+
cd ./dist/
212+
for file in *.whl; do
213+
mv "$file" "$(echo "$file" | sed -E 's/macosx_[0-9]+_[0-9]+/macosx_11_0/')";
214+
done
188215
- name: Upload wheel as CI artifacts
189216
uses: actions/upload-artifact@v3
190217
with:
191218
name: wheel-${{ github.run_id }}-${{ github.sha }}
192219
path: ./dist/
193220
- name: Set cores to get stored in /cores
194-
if: ${{ matrix.os != 'windows-2019' }}
221+
if: ${{ matrix.os != 'windows-2022' }}
195222
# TODO (Caleb Aikens) figure out how to get Windows core dumps
196223
run: |
197224
sudo mkdir -p /cores
@@ -226,7 +253,7 @@ jobs:
226253
credentials: "admin:admin"
227254
- name: Upload core dumps as CI artifacts
228255
uses: actions/upload-artifact@v3
229-
if: ${{ matrix.os != 'windows-2019' && failure() }}
256+
if: ${{ matrix.os != 'windows-2022' && failure() }}
230257
# TODO (Caleb Aikens) figure out how to get Windows core dumps
231258
with:
232259
name: cores-${{ matrix.os }}-${{ matrix.python_version }}
@@ -246,26 +273,27 @@ jobs:
246273
version: 1.5.1
247274
- name: Build source distribution (sdist) file
248275
run: |
249-
# Install Doxygen
250-
# the newest version in Ubuntu 20.04 repository is 1.8.17, but we need Doxygen 1.9 series
251-
wget -c -q https://www.doxygen.nl/files/doxygen-1.9.7.linux.bin.tar.gz
252-
tar xf doxygen-1.9.7.linux.bin.tar.gz
253-
cd doxygen-1.9.7 && sudo make install && cd -
254-
rm -rf doxygen-1.9.7 doxygen-1.9.7.linux.bin.tar.gz
255276
poetry self add "poetry-dynamic-versioning[plugin]"
256-
BUILD_DOCS=1 BUILD_TYPE=None poetry install
257277
poetry build --format=sdist
258278
ls -lah ./dist/
259279
- name: Upload sdist as CI artifacts
260280
uses: actions/upload-artifact@v3
261281
with:
262282
name: wheel-${{ github.run_id }}-${{ github.sha }}
263283
path: ./dist/
264-
- name: Upload Doxygen-generated docs as CI artifacts
265-
uses: actions/upload-artifact@v3
284+
check-install-from-sdist:
285+
needs: sdist
286+
runs-on: ubuntu-24.04
287+
steps:
288+
- uses: actions/setup-python@v5
266289
with:
267-
name: docs-${{ github.run_id }}-${{ github.sha }}
268-
path: ./build/docs/html/
290+
python-version: '3.10'
291+
- name: Download wheels built
292+
uses: actions/download-artifact@v3
293+
with:
294+
name: wheel-${{ github.run_id }}-${{ github.sha }}
295+
path: ./dist/
296+
- run: pip install ./dist/pythonmonkey-*.tar.gz
269297
publish:
270298
needs: [build-and-test, sdist]
271299
runs-on: ubuntu-20.04
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: 'Create pull requests to update mozilla-central version to the latest'
2+
3+
on:
4+
schedule:
5+
- cron: "00 14 */100,1-7 * 1" # run on the first Monday of each month at 14:00 UTC (10:00 Eastern Daylight Time)
6+
# See https://blog.healthchecks.io/2022/09/schedule-cron-job-the-funky-way/
7+
workflow_call:
8+
workflow_dispatch: # or you can run it manually
9+
10+
defaults:
11+
run:
12+
shell: bash
13+
14+
jobs:
15+
update:
16+
runs-on: ubuntu-20.04
17+
steps:
18+
- uses: actions/checkout@v4
19+
- name: Check Version
20+
# Check the latest changes on mozilla-central via the Mercurial pushlog HTTP API
21+
# See https://mozilla-version-control-tools.readthedocs.io/en/latest/hgmo/pushlog.html#hgweb-commands
22+
run: |
23+
COMMIT_HASH=$(
24+
curl -s "https://hg.mozilla.org/mozilla-central/json-pushes?tipsonly=1&version=2" |\
25+
jq --join-output '(.lastpushid | tostring) as $pushid | empty, .pushes[$pushid].changesets[0]'
26+
)
27+
echo "MOZCENTRAL_VERSION=$COMMIT_HASH" >> $GITHUB_ENV
28+
echo "MOZCENTRAL_VERSION_SHORT=${COMMIT_HASH:0:7}" >> $GITHUB_ENV
29+
- name: Update `mozcentral.version` File
30+
run: echo -n $MOZCENTRAL_VERSION > mozcentral.version
31+
- name: Create Pull Request
32+
uses: peter-evans/create-pull-request@v6
33+
with:
34+
add-paths: mozcentral.version
35+
commit-message: |
36+
chore(deps): upgrade SpiderMonkey to `${{ env.MOZCENTRAL_VERSION }}`
37+
author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
38+
branch: chore/upgrade-spidermonkey-to-${{ env.MOZCENTRAL_VERSION_SHORT }}
39+
title: Upgrade SpiderMonkey to mozilla-central commit `${{ env.MOZCENTRAL_VERSION }}`
40+
body: |
41+
Changeset: https://hg.mozilla.org/mozilla-central/rev/${{ env.MOZCENTRAL_VERSION }}
42+
labels: dependencies
43+
assignees: Xmader

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ lib/*
77
.pytest_cache
88
.DS_Store
99
firefox-*.tar.xz
10+
firefox-*.zip
1011
firefox-*/
12+
mozilla-central-*
1113
__pycache__
1214
Testing/Temporary
13-
_spidermonkey_install
15+
_spidermonkey_install*
1416
uncrustify-*.tar.gz
1517
uncrustify-*/
1618
uncrustify
19+
uncrustify.exe
1720
*.uncrustify
1821
__pycache__/*
1922
dist

.vscode/tasks.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
"problemMatcher": [
3939
"$gcc"
4040
],
41+
"options": {
42+
"env": {
43+
"BUILD_TYPE": "Debug"
44+
}
45+
},
4146
"group": {
4247
"kind": "build",
4348
}

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ else ifeq ($(BUILD),Debug)
2727
PYTHON_BUILD_ENV += BUILD_TYPE=Debug
2828
else ifeq ($(BUILD),DRelease)
2929
PYTHON_BUILD_ENV += BUILD_TYPE=DRelease
30-
else ifeq($(BUILD), None)
30+
else ifeq ($(BUILD), None)
3131
PYTHON_BUILD_ENV += BUILD_TYPE=None
3232
else # Release build
3333
PYTHON_BUILD_ENV += BUILD_TYPE=Release

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# PythonMonkey
22

3-
![Testing Suite](https://github.com/Kings-Distributed-Systems/PythonMonkey/actions/workflows/tests.yaml/badge.svg)
3+
[![Test and Publish Suite](https://github.com/Distributive-Network/PythonMonkey/actions/workflows/test-and-publish.yaml/badge.svg)](https://github.com/Distributive-Network/PythonMonkey/actions/workflows/test-and-publish.yaml)
44

55
## About
66
[PythonMonkey](https://pythonmonkey.io) is a Mozilla [SpiderMonkey](https://firefox-source-docs.mozilla.org/js/index.html) JavaScript engine embedded into the Python Runtime,
77
using the Python engine to provide the Javascript host environment.
88

99
We feature JavaScript Array and Object methods implemented on Python List and Dictionaries using the cPython C API, and the inverse using the Mozilla Firefox Spidermonkey JavaScript C++ API.
1010

11-
This product is in an advanced stage, approximately 95% to MVP as of March 2024. It is under active development by [Distributive](https://distributive.network/).
11+
This project has reached MVP as of September 2024. It is under maintenance by [Distributive](https://distributive.network/).
1212

1313
External contributions and feedback are welcome and encouraged.
1414

@@ -68,12 +68,12 @@ Read this if you want to build a local version.
6868
1. You will need the following installed (which can be done automatically by running `./setup.sh`):
6969
- bash
7070
- cmake
71-
- Doxygen 1.9 series
72-
- graphviz
71+
- Doxygen 1.9 series (if you want to build the docs)
72+
- graphviz (if you want to build the docs)
7373
- llvm
7474
- rust
7575
- python3.8 or later with header files (python3-dev)
76-
- spidermonkey 115.1.0 or later
76+
- spidermonkey latest from mozilla-central
7777
- [Poetry](https://python-poetry.org/docs/#installation)
7878
- [poetry-dynamic-versioning](https://github.com/mtkennerly/poetry-dynamic-versioning)
7979

@@ -163,11 +163,11 @@ They are largely based on SpiderMonkey's `CompileOptions`. The supported option
163163
- `filename`: set the filename of this code for the purposes of generating stack traces etc.
164164
- `lineno`: set the line number offset of this code for the purposes of generating stack traces etc.
165165
- `column`: set the column number offset of this code for the purposes of generating stack traces etc.
166-
- `mutedErrors`: experimental
167-
- `noScriptRval`: experimental
168-
- `selfHosting`: experimental
169-
- `strict`: experimental
170-
- `module`: experimental
166+
- `mutedErrors`: if set to `True`, eval errors or unhandled rejections are ignored ("muted"). Default `False`.
167+
- `noScriptRval`: if `False`, return the last expression value of the script as the result value to the caller. Default `False`.
168+
- `selfHosting`: *experimental*
169+
- `strict`: forcibly evaluate in strict mode (`"use strict"`). Default `False`.
170+
- `module`: indicate the file is an ECMAScript module (always strict mode code and disallow HTML comments). Default `False`.
171171
- `fromPythonFrame`: generate the equivalent of filename, lineno, and column based on the location of
172172
the Python call to eval. This makes it possible to evaluate Python multiline string literals and
173173
generate stack traces in JS pointing to the error in the Python source file.
@@ -461,7 +461,7 @@ List of commands:
461461
```console
462462
$ pmjs
463463

464-
Welcome to PythonMonkey v0.4.0.
464+
Welcome to PythonMonkey v1.0.0.
465465
Type ".help" for more information.
466466
> .python import sys
467467
> .python sys.path

0 commit comments

Comments
 (0)