Skip to content

Commit

Permalink
Create new ReactPyDjangoClient (#175)
Browse files Browse the repository at this point in the history
- Move from JavaScript to TypeScript
- Bumped the minimum `@reactpy/client` version to `0.3.1`
- Create a Django-specific client
- Minor refactoring to various bits of code
- Bumped minimum Django version to `4.2`.
- More customization for reconnection behavior through new settings!
    - `REACTPY_RECONNECT_INTERVAL`
    - `REACTPY_RECONNECT_MAX_INTERVAL`
    - `REACTPY_RECONNECT_MAX_RETRIES`
    - `REACTPY_RECONNECT_BACKOFF_MULTIPLIER`
  • Loading branch information
Archmonger authored Aug 27, 2023
1 parent cd0ebf5 commit 4a973b6
Show file tree
Hide file tree
Showing 29 changed files with 672 additions and 227 deletions.
56 changes: 28 additions & 28 deletions .github/workflows/publish-py.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,33 @@
name: Publish Python

on:
release:
types: [published]
release:
types: [published]

jobs:
release-package:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "14.x"
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: "3.x"
- name: Install NPM
run: |
npm install -g npm@7.22.0
npm --version
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements/build-pkg.txt
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python -m build --sdist --wheel --outdir dist .
twine upload dist/*
release-package:
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
pip install -r requirements/build-pkg.txt
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python -m build --sdist --wheel --outdir dist .
twine upload dist/*
1 change: 0 additions & 1 deletion .github/workflows/publish-release-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ jobs:
git config user.name github-actions
git config user.email github-actions@github.com
mike deploy --push --update-aliases ${{ github.event.release.name }} latest
mike set-default --push latest
2 changes: 1 addition & 1 deletion .github/workflows/test-src.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "14.x"
node-version: "20.x"
- name: Use Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,26 @@ Using the following categories, list your changes in this order:

### Added

- More customization for reconnection behavior through new settings!
- `REACTPY_RECONNECT_INTERVAL`
- `REACTPY_RECONNECT_MAX_INTERVAL`
- `REACTPY_RECONNECT_MAX_RETRIES`
- `REACTPY_RECONNECT_BACKOFF_MULTIPLIER`
- [ReactPy-Django docs](https://reactive-python.github.io/reactpy-django/) are now version controlled via [mike](https://github.com/jimporter/mike)!

### Changed

- Bumped the minimum ReactPy version to `1.0.2`.
- Prettier websocket URLs for components that do not have sessions.
- Template tag will now only validate `args`/`kwargs` if `settings.py:DEBUG` is enabled.
- Bumped the minimum `@reactpy/client` version to `0.3.1`
- Use TypeScript instead of JavaScript for this repository.
- Bumped minimum Django version to `4.2`.
- Note: ReactPy-Django will continue bumping minimum Django requirements to versions that increase async support. This "latest-only" trend will continue until Django has all async features that ReactPy benefits from. After this point, ReactPy-Django will begin supporting all maintained Django versions.

### Removed

- `settings.py:REACTPY_RECONNECT_MAX` is removed. See the docs for the new `REACTPY_RECONNECT_*` settings.

## [3.4.0] - 2023-08-18

Expand Down
2 changes: 1 addition & 1 deletion docs/src/contribute/code.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ cd tests
python manage.py runserver
```

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

## GitHub Pull Request

Expand Down
2 changes: 1 addition & 1 deletion docs/src/contribute/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Finally, to verify that everything is working properly, you can manually run the
mkdocs serve
```

Navigate to `http://127.0.0.1:8000` to view a preview of the documentation.
Navigate to [`http://127.0.0.1:8000`](http://127.0.0.1:8000) to view a preview of the documentation.

## GitHub Pull Request

Expand Down
6 changes: 5 additions & 1 deletion docs/src/features/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ These are ReactPy-Django's default settings values. You can modify these values
| --- | --- | --- | --- |
| `REACTPY_CACHE` | `#!python "default"` | `#!python "my-reactpy-cache"` | Cache used to store ReactPy web modules. ReactPy benefits from a fast, well indexed cache.<br/>We recommend installing [`redis`](https://redis.io/) or [`python-diskcache`](https://grantjenks.com/docs/diskcache/tutorial.html#djangocache). |
| `REACTPY_DATABASE` | `#!python "default"` | `#!python "my-reactpy-database"` | Database used to store ReactPy session data. ReactPy requires a multiprocessing-safe and thread-safe database.<br/>If configuring `REACTPY_DATABASE`, it is mandatory to use our database router like such:<br/>`#!python DATABASE_ROUTERS = ["reactpy_django.database.Router", ...]` |
| `REACTPY_RECONNECT_MAX` | `#!python 259200` | `#!python 96000`, `#!python 60`, `#!python 0` | Maximum seconds between reconnection attempts before giving up.<br/>Use `#!python 0` to prevent reconnection. |
| `REACTPY_SESSION_MAX_AGE` | `#!python 259200` | `#!python 0`, `#!python 60`, `#!python 96000` | Maximum seconds to store ReactPy session data, such as `args` and `kwargs` passed into your component template tag.<br/>Use `#!python 0` to not store any session data. |
| `REACTPY_URL_PREFIX` | `#!python "reactpy/"` | `#!python "rp/"`, `#!python "render/reactpy/"` | The prefix to be used for all ReactPy websocket and HTTP URLs. |
| `REACTPY_DEFAULT_QUERY_POSTPROCESSOR` | `#!python "reactpy_django.utils.django_query_postprocessor"` | `#!python "example_project.my_query_postprocessor"` | Dotted path to the default `reactpy_django.hooks.use_query` postprocessor function. |
| `REACTPY_AUTH_BACKEND` | `#!python "django.contrib.auth.backends.ModelBackend"` | `#!python "example_project.auth.MyModelBackend"` | Dotted path to the Django authentication backend to use for ReactPy components. This is only needed if:<br/> 1. You are using `AuthMiddlewareStack` and...<br/> 2. You are using Django's `AUTHENTICATION_BACKENDS` setting and...<br/> 3. Your Django user model does not define a `backend` attribute. |
| `REACTPY_BACKHAUL_THREAD` | `#!python False` | `#!python True` | Whether to render ReactPy components in a dedicated thread. This allows the webserver to process web traffic while during ReactPy rendering.<br/>Vastly improves throughput with web servers such as `hypercorn` and `uvicorn`. |
| `REACTPY_DEFAULT_HOSTS` | `#!python None` | `#!python ["localhost:8000", "localhost:8001", "localhost:8002/subdir" ]` | The default host(s) that can render your ReactPy components. ReactPy will use these hosts in a round-robin fashion, allowing for easy distributed computing.<br/>You can use the `host` argument in your [template tag](../features/template-tag.md#component) as a manual override. |
| `REACTPY_RECONNECT_INTERVAL` | `#!python 750` | `#!python 100`, `#!python 2500`, `#!python 6000` | Milliseconds between client reconnection attempts. This value will gradually increase if `REACTPY_RECONNECT_BACKOFF_MULTIPLIER` is greater than `#!python 1`. |
| `REACTPY_RECONNECT_MAX_INTERVAL` | `#!python 60000` | `#!python 10000`, `#!python 25000`, `#!python 900000` | Maximum milliseconds between client reconnection attempts. This allows setting an upper bound on how high `REACTPY_RECONNECT_BACKOFF_MULTIPLIER` can increase the time between reconnection attempts. |
| `REACTPY_RECONNECT_MAX_RETRIES` | `#!python 150` | `#!python 0`, `#!python 5`, `#!python 300` | Maximum number of reconnection attempts before the client gives up. |
| `REACTPY_RECONNECT_BACKOFF_MULTIPLIER` | `#!python 1.25` | `#!python 1`, `#!python 1.5`, `#!python 3` | Multiplier for the time between client reconnection attempts. On each reconnection attempt, the `REACTPY_RECONNECT_INTERVAL` will be multiplied by this to increase the time between attempts. You can keep time between each reconnection the same by setting this to `#!python 1`. |

<!--config-details-end-->
2 changes: 1 addition & 1 deletion docs/src/get-started/run-webserver.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ To test your new Django view, run the following command to start up a developmen
python manage.py runserver
```

Now you can navigate to your **Django project** URL that contains a ReactPy component, such as `http://127.0.0.1:8000/example/` ([_from the previous step_](./register-view.md)).
Now you can navigate to your **Django project** URL that contains a ReactPy component, such as [`http://127.0.0.1:8000/example/`](http://127.0.0.1:8000/example/) ([_from the previous step_](./register-view.md)).

If you copy-pasted our example component, you will now see your component display "Hello World".

Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ warn_unused_configs = true
warn_redundant_casts = true
warn_unused_ignores = true
check_untyped_defs = true
incremental = true

[tool.ruff.isort]
known-first-party = ["src", "tests"]
Expand Down
2 changes: 1 addition & 1 deletion requirements/pkg-deps.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
channels >=4.0.0
django >=4.1.0
django >=4.2.0
reactpy >=1.0.2, <1.1.0
aiofile >=3.0
dill >=0.3.5
Expand Down
Loading

0 comments on commit 4a973b6

Please sign in to comment.