diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index e01b3e62..12f72a6a 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -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 diff --git a/.github/workflows/publish-py.yml b/.github/workflows/publish-py.yml index 09be8866..5e1e4ead 100644 --- a/.github/workflows/publish-py.yml +++ b/.github/workflows/publish-py.yml @@ -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 diff --git a/.github/workflows/test-src.yml b/.github/workflows/test-src.yml index 4a03c49c..9ed9de05 100644 --- a/.github/workflows/test-src.yml +++ b/.github/workflows/test-src.yml @@ -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: @@ -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 diff --git a/docs/src/about/code.md b/docs/src/about/code.md index 93121a75..bc3d8ecc 100644 --- a/docs/src/about/code.md +++ b/docs/src/about/code.md @@ -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: @@ -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 @@ -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" %} diff --git a/pyproject.toml b/pyproject.toml index 250a64a6..2c8cb227 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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] diff --git a/requirements/test-env.txt b/requirements/test-env.txt index fc1ba2ce..6f146715 100644 --- a/requirements/test-env.txt +++ b/requirements/test-env.txt @@ -3,3 +3,4 @@ twisted channels[daphne]>=4.0.0 tblib whitenoise +nodejs-bin==18.4.0a4 diff --git a/setup.py b/setup.py index 9174e81a..28ebfc00 100644 --- a/setup.py +++ b/setup.py @@ -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 @@ -42,8 +22,6 @@ def list2cmdline(cmd_list): # ----------------------------------------------------------------------------- # Package Definition # ----------------------------------------------------------------------------- - - package = { "name": name, "python_requires": ">=3.9", @@ -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]) @@ -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 @@ -109,8 +83,6 @@ def list2cmdline(cmd_list): # ----------------------------------------------------------------------------- # Library Description # ----------------------------------------------------------------------------- - - with (root_dir / "README.md").open() as f: long_description = f.read() @@ -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() @@ -182,9 +134,7 @@ def run(self): # ----------------------------------------------------------------------------- -# Install It +# Installation # ----------------------------------------------------------------------------- - - if __name__ == "__main__": setup(**package) diff --git a/tests/test_app/__init__.py b/tests/test_app/__init__.py index e69de29b..86dbd107 100644 --- a/tests/test_app/__init__.py +++ b/tests/test_app/__init__.py @@ -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