Skip to content

Commit a96d52b

Browse files
authored
Merge branch 'main' into Xmader/feat/python-3.13-support
2 parents 428353c + e72bfd2 commit a96d52b

21 files changed

+385
-228
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: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
branches:
66
- main
77
tags:
8-
- '*'
8+
- 'v*'
99
workflow_call:
1010
workflow_dispatch:
1111
inputs:
@@ -55,6 +55,10 @@ defaults:
5555
# run with Git Bash on Windows
5656
shell: bash
5757

58+
concurrency:
59+
group: ${{ github.workflow }}-${{ github.ref }}
60+
cancel-in-progress: true
61+
5862
jobs:
5963
build-spidermonkey-unix:
6064
strategy:
@@ -130,13 +134,6 @@ jobs:
130134
matrix:
131135
os: [ 'ubuntu-20.04', 'macos-12', 'macos-14', 'windows-2022', 'pi' ]
132136
python_version: [ '3.8', '3.9', '3.10', '3.11', '3.12', '3.13-dev' ]
133-
exclude:
134-
# actions/setup-python: The version '3.8'/'3.9' with architecture 'arm64' was not found for macOS.
135-
# see https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json
136-
- os: 'macos-14'
137-
python_version: '3.8'
138-
- os: 'macos-14'
139-
python_version: '3.9'
140137
runs-on: ${{ matrix.os }}
141138
steps:
142139
- uses: actions/checkout@v4
@@ -209,6 +206,17 @@ jobs:
209206
WORKFLOW_BUILD_TYPE=${{ inputs.build_type }}
210207
BUILD_TYPE=${WORKFLOW_BUILD_TYPE:-"Debug"} poetry build --format=wheel
211208
ls -lah ./dist/
209+
- name: Make the wheels we build also support lower versions of macOS
210+
if: ${{ matrix.os == 'macos-12' || matrix.os == 'macos-14' }}
211+
# Change the platform tag part of the wheel filename to `macosx_11_0_xxx` (means to support macOS 11.0 and above)
212+
# See https://packaging.python.org/en/latest/specifications/binary-distribution-format/#file-format
213+
# 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.
214+
# Otherwise, pip would fallback to compile from the source distribution.
215+
run: |
216+
cd ./dist/
217+
for file in *.whl; do
218+
mv "$file" "$(echo "$file" | sed -E 's/macosx_[0-9]+_[0-9]+/macosx_11_0/')";
219+
done
212220
- name: Upload wheel as CI artifacts
213221
uses: actions/upload-artifact@v3
214222
with:
@@ -294,7 +302,7 @@ jobs:
294302
publish:
295303
needs: [build-and-test, sdist]
296304
runs-on: ubuntu-20.04
297-
if: ${{ success() && github.event_name == 'push' && contains(github.ref, 'refs/tags/') }}
305+
if: ${{ success() && github.event_name == 'push' && github.ref_type == 'tag' }}
298306
steps:
299307
# no need to checkout
300308
- uses: actions/setup-python@v5
@@ -317,7 +325,7 @@ jobs:
317325
# and deploy the static files to GitHub Pages
318326
needs: [build-and-test, sdist]
319327
runs-on: ubuntu-20.04
320-
if: ${{ (success() || failure()) && github.ref_name == 'main' }} # publish nightly builds regardless of tests failure
328+
if: ${{ (success() || failure()) && (github.ref_name == 'main' || github.ref_type == 'tag') }} # publish nightly builds regardless of tests failure
321329
permissions: # grant GITHUB_TOKEN the permissions required to make a Pages deployment
322330
pages: write
323331
id-token: write
@@ -372,3 +380,45 @@ jobs:
372380
- name: Deploy to GitHub Pages
373381
id: deployment
374382
uses: actions/deploy-pages@v2
383+
publish-archive:
384+
# Publish to ⊇istributive's archive server (https://archive.distributed.computer/releases/pythonmonkey/)
385+
needs: [build-and-test, sdist]
386+
runs-on: ubuntu-20.04
387+
if: ${{ (success() || failure()) && (github.ref_name == 'main' || github.ref_type == 'tag') }}
388+
environment:
389+
name: archive
390+
url: https://archive.distributed.computer/releases/pythonmonkey/${{ steps.get_path.outputs.ARCHIVE_PATH }}
391+
steps:
392+
# no need to checkout
393+
- name: Download wheels built
394+
uses: actions/download-artifact@v3
395+
with:
396+
name: wheel-${{ github.run_id }}-${{ github.sha }}
397+
path: ./
398+
- name: Download docs html generated by Doxygen
399+
uses: actions/download-artifact@v3
400+
with:
401+
name: docs-${{ github.run_id }}-${{ github.sha }}
402+
path: ./docs/
403+
- name: Get the pythonmonkey/pminit version number
404+
run: |
405+
file=$(ls ./pminit*.tar.gz | head -1)
406+
pm_version=$(basename "${file%.tar.gz}" | cut -d- -f2) # match /pminit-([^-]+).tar.gz/
407+
echo "PM_VERSION=$pm_version" >> $GITHUB_ENV
408+
- name: Get the archive type (nightly or releases) and path
409+
id: get_path
410+
run: |
411+
path="$ARCHIVE_TYPE/$PM_VERSION/"
412+
echo "$path"
413+
echo "ARCHIVE_PATH=$path" >> $GITHUB_OUTPUT
414+
env:
415+
ARCHIVE_TYPE: ${{ (github.ref_type == 'tag' && 'releases') || 'nightly' }}
416+
- name: SCP to the archive server
417+
uses: appleboy/[email protected]
418+
with:
419+
host: ${{ secrets.ARCHIVE_HOST }}
420+
username: pythonmonkey
421+
key: ${{ secrets.ARCHIVE_KEY }}
422+
source: ./*
423+
target: archive/${{ steps.get_path.outputs.ARCHIVE_PATH }}
424+
overwrite: true

.github/workflows/update-mozcentral-version.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ name: 'Create pull requests to update mozilla-central version to the latest'
22

33
on:
44
schedule:
5-
- cron: "00 14 * * 1" # run every Monday at 14:00 UTC (10:00 Eastern Daylight Time)
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/
67
workflow_call:
78
workflow_dispatch: # or you can run it manually
89

@@ -33,8 +34,10 @@ jobs:
3334
add-paths: mozcentral.version
3435
commit-message: |
3536
chore(deps): upgrade SpiderMonkey to `${{ env.MOZCENTRAL_VERSION }}`
37+
author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
3638
branch: chore/upgrade-spidermonkey-to-${{ env.MOZCENTRAL_VERSION_SHORT }}
3739
title: Upgrade SpiderMonkey to mozilla-central commit `${{ env.MOZCENTRAL_VERSION }}`
3840
body: |
3941
Changeset: https://hg.mozilla.org/mozilla-central/rev/${{ env.MOZCENTRAL_VERSION }}
4042
labels: dependencies
43+
assignees: Xmader

README.md

Lines changed: 13 additions & 4 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 98% to MVP as of August 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

@@ -73,7 +73,7 @@ Read this if you want to build a local version.
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
- npm (nodejs)
7878
- [Poetry](https://python-poetry.org/docs/#installation)
7979
- [poetry-dynamic-versioning](https://github.com/mtkennerly/poetry-dynamic-versioning)
@@ -136,6 +136,15 @@ $ poetry build --format=wheel
136136
```
137137
and install them by `pip install ./dist/*`.
138138

139+
## Uninstallation
140+
141+
Installing `pythonmonkey` will also install the `pminit` package as a dependency. However, `pip uninstall`ing a package won't automatically remove its dependencies.
142+
If you want to cleanly remove `pythonmonkey` from your system, do the following:
143+
144+
```bash
145+
$ pip uninstall pythonmonkey pminit
146+
```
147+
139148
## Debugging Steps
140149

141150
1. [build the project locally](#build-instructions)
@@ -462,7 +471,7 @@ List of commands:
462471
```console
463472
$ pmjs
464473

465-
Welcome to PythonMonkey v0.4.0.
474+
Welcome to PythonMonkey v1.0.0.
466475
Type ".help" for more information.
467476
> .python import sys
468477
> .python sys.path

include/JSStringProxy.hh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
#include <Python.h>
1717

18+
#include <unordered_set>
19+
1820
/**
1921
* @brief The typedef for the backing store that will be used by JSStringProxy objects. All it contains is a pointer to the JSString
2022
*
@@ -24,6 +26,8 @@ typedef struct {
2426
JS::PersistentRootedValue *jsString;
2527
} JSStringProxy;
2628

29+
extern std::unordered_set<JSStringProxy *> jsStringProxies; // a collection of all JSStringProxy objects, used during a GCCallback to ensure they continue to point to the correct char buffer
30+
2731
/**
2832
* @brief This struct is a bundle of methods used by the JSStringProxy type
2933
*
@@ -37,7 +41,7 @@ public:
3741
*/
3842
static void JSStringProxy_dealloc(JSStringProxy *self);
3943

40-
/**
44+
/**
4145
* @brief copy protocol method for both copy and deepcopy
4246
*
4347
* @param self - The JSObjectProxy
@@ -49,13 +53,13 @@ public:
4953
// docs for methods, copied from cpython
5054
PyDoc_STRVAR(stringproxy_deepcopy__doc__,
5155
"__deepcopy__($self, memo, /)\n"
52-
"--\n"
53-
"\n");
56+
"--\n"
57+
"\n");
5458

5559
PyDoc_STRVAR(stringproxy_copy__doc__,
56-
"__copy__($self, /)\n"
57-
"--\n"
58-
"\n");
60+
"__copy__($self, /)\n"
61+
"--\n"
62+
"\n");
5963

6064
/**
6165
* @brief Struct for the other methods

mozcentral.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8a28ad54f9f516c41ceddfa7ea32368fccf4a0eb
1+
a283127a5d0aa005c54d339e8ca27414b55f079b

python/pythonmonkey/builtin_modules/XMLHttpRequest-internal.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ export declare function request(
4646
// callbacks for known exceptions
4747
onTimeoutError: (err: Error) => void,
4848
onNetworkError: (err: Error) => void,
49+
// the debug logging function
50+
/** See `pm.bootstrap.require("debug")` */
51+
debug: (selector: string) => ((...args: string[]) => void),
4952
): Promise<void>;
5053

5154
/**

python/pythonmonkey/builtin_modules/XMLHttpRequest-internal.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ async def request(
4444
# callbacks for known exceptions
4545
onTimeoutError: Callable[[asyncio.TimeoutError], None],
4646
onNetworkError: Callable[[aiohttp.ClientError], None],
47+
# the debug logging function, see `pm.bootstrap.require("debug")`
48+
debug: Callable[[str], Callable[..., None]],
4749
/
4850
):
49-
debug = pm.bootstrap.require("debug")
5051

5152
# to support HTTP-Keep-Alive
5253
global keepAliveConnector

0 commit comments

Comments
 (0)