Skip to content

Commit e8147b1

Browse files
authored
Merge pull request #57 from Distributive-Network/Xmader/feat/post-install-npm
Run `npm i` at `pip install pythonmonkey` time
2 parents b198aff + de68174 commit e8147b1

File tree

11 files changed

+90
-23
lines changed

11 files changed

+90
-23
lines changed

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

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ jobs:
117117
echo "Installing python deps"
118118
poetry self add "poetry-dynamic-versioning[plugin]"
119119
poetry env use python3 # use the correct Python version we've set up
120-
poetry install --no-root
120+
poetry install --no-root --only=dev
121121
echo "Installed Dependencies"
122122
- name: Use cached spidermonkey build
123123
uses: actions/cache@v3
@@ -126,6 +126,13 @@ jobs:
126126
./_spidermonkey_install/*
127127
key: spidermonkey-${{ runner.os }}-${{ runner.arch }}
128128
fail-on-cache-miss: true # SpiderMonkey is expected to be cached in its dedicated job
129+
- name: Build pminit
130+
run: |
131+
cd python/pminit
132+
poetry build --format=sdist
133+
cd -
134+
mkdir -p ./dist/
135+
mv -v python/pminit/dist/* ./dist/
129136
- name: Build wheel
130137
run: |
131138
echo $(poetry run python --version)
@@ -138,7 +145,7 @@ jobs:
138145
path: ./dist/
139146
- name: Run Python tests (pytest)
140147
run: |
141-
poetry run python -m pip install --force-reinstall ./dist/*.whl
148+
poetry run python -m pip install --force-reinstall ./dist/*
142149
poetry run python -m pytest tests/python
143150
sdist:
144151
runs-on: ubuntu-20.04
@@ -205,16 +212,26 @@ jobs:
205212
uses: actions/download-artifact@v3
206213
with:
207214
name: wheel-${{ github.run_id }}-${{ github.sha }}
208-
path: ./pythonmonkey/ # write to the repository project path
215+
path: ./dist/
216+
- name: Move wheels to the correct repository project paths
217+
run: |
218+
mkdir -p ./pythonmonkey/ ./pminit/
219+
mv ./dist/pythonmonkey-* ./pythonmonkey/
220+
mv ./dist/pminit-* ./pminit/
209221
- name: Generate index page for the project
210222
run: |
211-
cd ./pythonmonkey/
212-
html="<html><head><title>PythonMonkey Nightly Builds</title></head><body>"
213-
for file in ./*; do # generate <a> tags for each file
214-
html+="<a href=\"$file\">$file</a><br/>"
215-
done
216-
html+="</body></html>"
217-
echo "$html" > ./index.html
223+
generate_index () {
224+
cd $1
225+
html="<html><head><title>PythonMonkey Nightly Builds</title></head><body>"
226+
for file in ./*; do # generate <a> tags for each file
227+
html+="<a href=\"$file\">$file</a><br/>"
228+
done
229+
html+="</body></html>"
230+
echo "$html" > ./index.html
231+
cd -
232+
}
233+
generate_index ./pythonmonkey/
234+
generate_index ./pminit/
218235
- name: Generate repository root page
219236
run: |
220237
html="<html><head><title>PythonMonkey Nightly Builds</title></head><body>"
@@ -223,6 +240,7 @@ jobs:
223240
html+="<pre>pip install -i https://nightly.pythonmonkey.io/ --pre pythonmonkey</pre>"
224241
html+="<h3>Browse files:</h3>"
225242
html+="<a href="pythonmonkey/">pythonmonkey</a>"
243+
html+="<a href="pminit/">pminit</a>"
226244
html+="</body></html>"
227245
echo "$html" > ./index.html
228246
- uses: actions/upload-pages-artifact@v1

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
build/
22
.vscode/
33
pyvenv.cfg
4-
python/pythonmonkey/version.py
54
python/pythonmonkey/node_modules
65
bin/
76
lib/*
@@ -15,8 +14,6 @@ _spidermonkey_install
1514
__pycache__/*
1615
dist
1716
*.so
18-
_spidermonkey_install/*
19-
*~
2017
*.dylib
2118
*.dll
2219
*.pyd

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,12 @@ this package to execute our complex `dcp-client` library, which is written in JS
5757
- [Poetry](https://python-poetry.org/docs/#installation)
5858
- [poetry-dynamic-versioning](https://github.com/mtkennerly/poetry-dynamic-versioning)
5959

60-
2. Run `poetry install`. This command automatically compiles the project and installs the project as well as all Python dependencies to the poetry virtualenv.
60+
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.
6161

6262
## Running tests
6363
1. Compile the project
64-
2. From the root directory, run `poetry run pytest ./tests/python`
64+
2. Install development dependencies: `poetry install --no-root --only=dev`
65+
3. From the root directory, run `poetry run pytest ./tests/python`
6566

6667
## Using the library
6768

build_script.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,3 @@ else
2323
cmake ..
2424
fi
2525
cmake --build . -j$CPUS --config Release
26-
27-
cd ../python/pythonmonkey
28-
# npm is used to load JS components, see package.json
29-
cd "${topDir}/python/pythonmonkey/"
30-
npm i

pyproject.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,11 @@ include = [
1111
# Linux and macOS
1212
"python/pythonmonkey/pythonmonkey.so",
1313
"python/pythonmonkey/libmozjs*",
14-
"python/pythonmonkey/builtin_modules/**/*",
1514

1615
# Windows
1716
"python/pythonmonkey/pythonmonkey.pyd",
1817
"python/pythonmonkey/mozjs-*.dll",
1918

20-
"python/pythonmonkey/node_modules/**/*",
21-
2219
# include all files for source distribution
2320
{ path = "src", format = "sdist" },
2421
{ path = "include", format = "sdist" },
@@ -34,6 +31,7 @@ include = [
3431

3532
[tool.poetry.dependencies]
3633
python = "^3.8"
34+
pminit = { version = "*", allow-prereleases = true }
3735

3836

3937
[tool.poetry-dynamic-versioning]

python/pminit/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

python/pminit/pminit/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Placeholder
2+
# A __init__.py file is required by pip

python/pminit/post-install-hook.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import subprocess
2+
import sys
3+
4+
def execute(cmd: str):
5+
popen = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.STDOUT,
6+
shell = True, text = True )
7+
for stdout_line in iter(popen.stdout.readline, ""):
8+
sys.stdout.write(stdout_line)
9+
sys.stdout.flush()
10+
11+
popen.stdout.close()
12+
return_code = popen.wait()
13+
if return_code:
14+
raise subprocess.CalledProcessError(return_code, cmd)
15+
16+
def main():
17+
execute("cd pythonmonkey && npm i --no-package-lock") # do not update package-lock.json
18+
19+
if __name__ == "__main__":
20+
main()

python/pminit/pyproject.toml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[tool.poetry]
2+
name = "pminit"
3+
version = "0"
4+
description = "Post-install hook for PythonMonkey"
5+
authors = [
6+
"Tom Tang <[email protected]>",
7+
"Caleb Aikens <[email protected]>",
8+
"Wes Garland <[email protected]>",
9+
"Hamada Gasmallah <[email protected]>"
10+
]
11+
include = [
12+
# Install extra files into the pythonmonkey package
13+
"pythonmonkey/package*.json",
14+
{ path = "pythonmonkey/node_modules/**/*", format = "wheel" },
15+
# pip builds (and actually installs from) the wheel when installing from sdist
16+
# we don't want node_modules inside the sdist package
17+
]
18+
19+
[tool.poetry.dependencies]
20+
python = "^3.8"
21+
22+
[tool.poetry-dynamic-versioning]
23+
enable = true
24+
vcs = "git"
25+
style = "pep440"
26+
bump = true
27+
28+
[tool.poetry.build]
29+
script = "post-install-hook.py"
30+
generate-setup-file = false
31+
32+
[build-system]
33+
requires = ["poetry-core>=1.0.0", "poetry-dynamic-versioning"]
34+
build-backend = "poetry_dynamic_versioning.backend"
35+
File renamed without changes.

0 commit comments

Comments
 (0)