Skip to content

Use NodeJS-bin instead of the user's node install #208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These are supported funding model platforms

github: [rmorshea]
github: [archmonger]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
Expand Down
7 changes: 0 additions & 7 deletions .github/workflows/publish-py.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "20.x"
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: "3.x"
- name: Install NPM
run: |
npm install -g npm@latest
npm --version
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/test-src.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ jobs:
python-version: ["3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "20.x"
- name: Use Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
Expand All @@ -29,6 +26,4 @@ jobs:
run: pip install -r requirements/test-run.txt
- name: Run Tests
run: |
npm install -g npm@latest
npm --version
nox -s test
30 changes: 10 additions & 20 deletions docs/src/about/code.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ If you plan to make code changes to this repository, you will need to install th

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

Once done, you should clone this repository:

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

Then, by running the command below you can:

- Install an editable version of the Python code
- Download, build, and install Javascript dependencies
Then, by running the command below you can install the dependencies needed to run the ReactPy Django development environment.

```bash linenums="0"
pip install -e . -r requirements.txt --verbose --upgrade
pip install -r requirements.txt --upgrade --verbose
```

!!! warning "Pitfall"

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.
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.

Finally, to verify that everything is working properly, you can manually run the test web server.

```bash linenums="0"
cd tests
python manage.py runserver
```
Additionally, be aware that ReactPy Django's JavaScript bundle is built within the following scenarios:

Navigate to [`http://127.0.0.1:8000`](http://127.0.0.1:8000) to see if the tests are rendering correctly.

## Creating a pull request

{% include-markdown "../../includes/pr.md" %}
1. When `pip install` is run on the `reactpy-django` package.
2. Every time `python manage.py ...` or `nox ...` is run

## Running the full test suite

Expand Down Expand Up @@ -92,3 +78,7 @@ If you want to manually run the Django test application, you can use the followi
cd tests
python manage.py runserver
```

## Creating a pull request

{% include-markdown "../../includes/pr.md" %}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools>=42", "wheel"]
requires = ["setuptools>=42", "wheel", "nodejs-bin==18.4.0a4"]
build-backend = "setuptools.build_meta"

[tool.mypy]
Expand Down
1 change: 1 addition & 0 deletions requirements/test-env.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ twisted
channels[daphne]>=4.0.0
tblib
whitenoise
nodejs-bin==18.4.0a4
74 changes: 12 additions & 62 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,19 @@
from __future__ import print_function
from __future__ import annotations, print_function

import pipes
import shutil
import subprocess
import sys
import traceback
from distutils import log
from logging import StreamHandler, getLogger
from pathlib import Path

from nodejs import npm
from setuptools import find_namespace_packages, setup
from setuptools.command.develop import develop
from setuptools.command.sdist import sdist

if sys.platform == "win32":
from subprocess import list2cmdline
else:

def list2cmdline(cmd_list):
return " ".join(map(pipes.quote, cmd_list))


log = getLogger() # noqa: F811
log.addHandler(StreamHandler(sys.stdout))


# -----------------------------------------------------------------------------
# Basic Constants
# -----------------------------------------------------------------------------


# the name of the project
name = "reactpy_django"

# basic paths used to gather files
root_dir = Path(__file__).parent
src_dir = root_dir / "src"
package_dir = src_dir / name
Expand All @@ -42,8 +22,6 @@ def list2cmdline(cmd_list):
# -----------------------------------------------------------------------------
# Package Definition
# -----------------------------------------------------------------------------


package = {
"name": name,
"python_requires": ">=3.9",
Expand Down Expand Up @@ -84,8 +62,6 @@ def list2cmdline(cmd_list):
# -----------------------------------------------------------------------------
# Library Version
# -----------------------------------------------------------------------------


for line in (package_dir / "__init__.py").read_text().split("\n"):
if line.startswith("__version__ = "):
package["version"] = eval(line.split("=", 1)[1])
Expand All @@ -98,9 +74,7 @@ def list2cmdline(cmd_list):
# -----------------------------------------------------------------------------
# Requirements
# -----------------------------------------------------------------------------


requirements = []
requirements: list[str] = []
with (root_dir / "requirements" / "pkg-deps.txt").open() as f:
requirements.extend(line for line in map(str.strip, f) if not line.startswith("#"))
package["install_requires"] = requirements
Expand All @@ -109,8 +83,6 @@ def list2cmdline(cmd_list):
# -----------------------------------------------------------------------------
# Library Description
# -----------------------------------------------------------------------------


with (root_dir / "README.md").open() as f:
long_description = f.read()

Expand All @@ -121,44 +93,24 @@ def list2cmdline(cmd_list):
# ----------------------------------------------------------------------------
# Build Javascript
# ----------------------------------------------------------------------------


def build_javascript_first(cls):
class Command(cls):
def build_javascript_first(build_cls: type):
class Command(build_cls):
def run(self):
js_dir = str(src_dir / "js")
npm = shutil.which("npm") # this is required on windows
if npm is None:
raise RuntimeError("NPM is not installed.")

log.info("Updating NPM...")
try:
args_list = [npm, "install", "-g", "npm@latest"]
log.info(f"> {list2cmdline(args_list)}")
subprocess.run(args_list, cwd=js_dir, check=True)
except Exception:
log.error(traceback.format_exc())
log.error("Failed to update NPM, continuing anyway...")

log.info("Installing Javascript...")
try:
args_list = [npm, "install"]
log.info(f"> {list2cmdline(args_list)}")
subprocess.run(args_list, cwd=js_dir, check=True)
except Exception:
result = npm.call(["install"], cwd=js_dir)
if result != 0:
log.error(traceback.format_exc())
log.error("Failed to install Javascript")
raise
raise RuntimeError("Failed to install Javascript")

log.info("Building Javascript...")
try:
args_list = [npm, "run", "build"]
log.info(f"> {list2cmdline(args_list)}")
subprocess.run(args_list, cwd=js_dir, check=True)
except Exception:
result = npm.call(["run", "build"], cwd=js_dir)
if result != 0:
log.error(traceback.format_exc())
log.error("Failed to build Javascript")
raise
raise RuntimeError("Failed to build Javascript")

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


# -----------------------------------------------------------------------------
# Install It
# Installation
# -----------------------------------------------------------------------------


if __name__ == "__main__":
setup(**package)
8 changes: 8 additions & 0 deletions tests/test_app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from pathlib import Path

from nodejs import npm

# Make sure the JS is always re-built before running the tests
js_dir = Path(__file__).parent.parent.parent / "src" / "js"
assert npm.call(["install"], cwd=str(js_dir)) == 0
assert npm.call(["run", "build"], cwd=str(js_dir)) == 0