Skip to content

Commit 6fb7ba2

Browse files
authored
Use NodeJS-bin instead of the user's node install (#208)
Use premade binaries for npm instead of the user's local npm installation.
1 parent b307b3e commit 6fb7ba2

File tree

8 files changed

+33
-96
lines changed

8 files changed

+33
-96
lines changed

.github/FUNDING.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# These are supported funding model platforms
22

3-
github: [rmorshea]
3+
github: [archmonger]
44
patreon: # Replace with a single Patreon username
55
open_collective: # Replace with a single Open Collective username
66
ko_fi: # Replace with a single Ko-fi username

.github/workflows/publish-py.yml

-7
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,10 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v3
15-
- uses: actions/setup-node@v3
16-
with:
17-
node-version: "20.x"
1815
- name: Set up Python
1916
uses: actions/setup-python@v1
2017
with:
2118
python-version: "3.x"
22-
- name: Install NPM
23-
run: |
24-
npm install -g npm@latest
25-
npm --version
2619
- name: Install dependencies
2720
run: |
2821
python -m pip install --upgrade pip

.github/workflows/test-src.yml

-5
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ jobs:
1818
python-version: ["3.9", "3.10", "3.11"]
1919
steps:
2020
- uses: actions/checkout@v3
21-
- uses: actions/setup-node@v3
22-
with:
23-
node-version: "20.x"
2421
- name: Use Python ${{ matrix.python-version }}
2522
uses: actions/setup-python@v4
2623
with:
@@ -29,6 +26,4 @@ jobs:
2926
run: pip install -r requirements/test-run.txt
3027
- name: Run Tests
3128
run: |
32-
npm install -g npm@latest
33-
npm --version
3429
nox -s test

docs/src/about/code.md

+10-20
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ If you plan to make code changes to this repository, you will need to install th
2020

2121
- [Python 3.9+](https://www.python.org/downloads/)
2222
- [Git](https://git-scm.com/downloads)
23-
- [NPM](https://docs.npmjs.com/try-the-latest-stable-version-of-npm) for installing and managing Javascript
2423

2524
Once done, you should clone this repository:
2625

@@ -29,33 +28,20 @@ git clone https://github.com/reactive-python/reactpy-django.git
2928
cd reactpy-django
3029
```
3130

32-
Then, by running the command below you can:
33-
34-
- Install an editable version of the Python code
35-
- Download, build, and install Javascript dependencies
31+
Then, by running the command below you can install the dependencies needed to run the ReactPy Django development environment.
3632

3733
```bash linenums="0"
38-
pip install -e . -r requirements.txt --verbose --upgrade
34+
pip install -r requirements.txt --upgrade --verbose
3935
```
4036

4137
!!! warning "Pitfall"
4238

43-
Some of our development dependencies require a C++ compiler, which is not installed by default on Windows.
44-
45-
If you receive errors related to this during installation, follow the instructions in your console errors.
39+
Some of our development dependencies require a C++ compiler, which is not installed by default on Windows. If you receive errors related to this during installation, follow the instructions in your console errors.
4640

47-
Finally, to verify that everything is working properly, you can manually run the test web server.
48-
49-
```bash linenums="0"
50-
cd tests
51-
python manage.py runserver
52-
```
41+
Additionally, be aware that ReactPy Django's JavaScript bundle is built within the following scenarios:
5342

54-
Navigate to [`http://127.0.0.1:8000`](http://127.0.0.1:8000) to see if the tests are rendering correctly.
55-
56-
## Creating a pull request
57-
58-
{% include-markdown "../../includes/pr.md" %}
43+
1. When `pip install` is run on the `reactpy-django` package.
44+
2. Every time `python manage.py ...` or `nox ...` is run
5945

6046
## Running the full test suite
6147

@@ -92,3 +78,7 @@ If you want to manually run the Django test application, you can use the followi
9278
cd tests
9379
python manage.py runserver
9480
```
81+
82+
## Creating a pull request
83+
84+
{% include-markdown "../../includes/pr.md" %}

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["setuptools>=42", "wheel"]
2+
requires = ["setuptools>=42", "wheel", "nodejs-bin==18.4.0a4"]
33
build-backend = "setuptools.build_meta"
44

55
[tool.mypy]

requirements/test-env.txt

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ twisted
33
channels[daphne]>=4.0.0
44
tblib
55
whitenoise
6+
nodejs-bin==18.4.0a4

setup.py

+12-62
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,19 @@
1-
from __future__ import print_function
1+
from __future__ import annotations, print_function
22

3-
import pipes
4-
import shutil
5-
import subprocess
63
import sys
74
import traceback
85
from distutils import log
9-
from logging import StreamHandler, getLogger
106
from pathlib import Path
117

8+
from nodejs import npm
129
from setuptools import find_namespace_packages, setup
1310
from setuptools.command.develop import develop
1411
from setuptools.command.sdist import sdist
1512

16-
if sys.platform == "win32":
17-
from subprocess import list2cmdline
18-
else:
19-
20-
def list2cmdline(cmd_list):
21-
return " ".join(map(pipes.quote, cmd_list))
22-
23-
24-
log = getLogger() # noqa: F811
25-
log.addHandler(StreamHandler(sys.stdout))
26-
27-
2813
# -----------------------------------------------------------------------------
2914
# Basic Constants
3015
# -----------------------------------------------------------------------------
31-
32-
33-
# the name of the project
3416
name = "reactpy_django"
35-
36-
# basic paths used to gather files
3717
root_dir = Path(__file__).parent
3818
src_dir = root_dir / "src"
3919
package_dir = src_dir / name
@@ -42,8 +22,6 @@ def list2cmdline(cmd_list):
4222
# -----------------------------------------------------------------------------
4323
# Package Definition
4424
# -----------------------------------------------------------------------------
45-
46-
4725
package = {
4826
"name": name,
4927
"python_requires": ">=3.9",
@@ -84,8 +62,6 @@ def list2cmdline(cmd_list):
8462
# -----------------------------------------------------------------------------
8563
# Library Version
8664
# -----------------------------------------------------------------------------
87-
88-
8965
for line in (package_dir / "__init__.py").read_text().split("\n"):
9066
if line.startswith("__version__ = "):
9167
package["version"] = eval(line.split("=", 1)[1])
@@ -98,9 +74,7 @@ def list2cmdline(cmd_list):
9874
# -----------------------------------------------------------------------------
9975
# Requirements
10076
# -----------------------------------------------------------------------------
101-
102-
103-
requirements = []
77+
requirements: list[str] = []
10478
with (root_dir / "requirements" / "pkg-deps.txt").open() as f:
10579
requirements.extend(line for line in map(str.strip, f) if not line.startswith("#"))
10680
package["install_requires"] = requirements
@@ -109,8 +83,6 @@ def list2cmdline(cmd_list):
10983
# -----------------------------------------------------------------------------
11084
# Library Description
11185
# -----------------------------------------------------------------------------
112-
113-
11486
with (root_dir / "README.md").open() as f:
11587
long_description = f.read()
11688

@@ -121,44 +93,24 @@ def list2cmdline(cmd_list):
12193
# ----------------------------------------------------------------------------
12294
# Build Javascript
12395
# ----------------------------------------------------------------------------
124-
125-
126-
def build_javascript_first(cls):
127-
class Command(cls):
96+
def build_javascript_first(build_cls: type):
97+
class Command(build_cls):
12898
def run(self):
12999
js_dir = str(src_dir / "js")
130-
npm = shutil.which("npm") # this is required on windows
131-
if npm is None:
132-
raise RuntimeError("NPM is not installed.")
133-
134-
log.info("Updating NPM...")
135-
try:
136-
args_list = [npm, "install", "-g", "npm@latest"]
137-
log.info(f"> {list2cmdline(args_list)}")
138-
subprocess.run(args_list, cwd=js_dir, check=True)
139-
except Exception:
140-
log.error(traceback.format_exc())
141-
log.error("Failed to update NPM, continuing anyway...")
142100

143101
log.info("Installing Javascript...")
144-
try:
145-
args_list = [npm, "install"]
146-
log.info(f"> {list2cmdline(args_list)}")
147-
subprocess.run(args_list, cwd=js_dir, check=True)
148-
except Exception:
102+
result = npm.call(["install"], cwd=js_dir)
103+
if result != 0:
149104
log.error(traceback.format_exc())
150105
log.error("Failed to install Javascript")
151-
raise
106+
raise RuntimeError("Failed to install Javascript")
152107

153108
log.info("Building Javascript...")
154-
try:
155-
args_list = [npm, "run", "build"]
156-
log.info(f"> {list2cmdline(args_list)}")
157-
subprocess.run(args_list, cwd=js_dir, check=True)
158-
except Exception:
109+
result = npm.call(["run", "build"], cwd=js_dir)
110+
if result != 0:
159111
log.error(traceback.format_exc())
160112
log.error("Failed to build Javascript")
161-
raise
113+
raise RuntimeError("Failed to build Javascript")
162114

163115
log.info("Successfully built Javascript")
164116
super().run()
@@ -182,9 +134,7 @@ def run(self):
182134

183135

184136
# -----------------------------------------------------------------------------
185-
# Install It
137+
# Installation
186138
# -----------------------------------------------------------------------------
187-
188-
189139
if __name__ == "__main__":
190140
setup(**package)

tests/test_app/__init__.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from pathlib import Path
2+
3+
from nodejs import npm
4+
5+
# Make sure the JS is always re-built before running the tests
6+
js_dir = Path(__file__).parent.parent.parent / "src" / "js"
7+
assert npm.call(["install"], cwd=str(js_dir)) == 0
8+
assert npm.call(["run", "build"], cwd=str(js_dir)) == 0

0 commit comments

Comments
 (0)