Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into feature/client_data
Browse files Browse the repository at this point in the history
# Conflicts:
#	nicegui/client.py
  • Loading branch information
Alyxion committed Sep 25, 2024
2 parents d582e03 + 8398cfa commit 60e5c42
Show file tree
Hide file tree
Showing 673 changed files with 551,253 additions and 678,578 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.8
FROM --platform=linux/amd64 python:3.8

ENV POETRY_VERSION=1.6.1 \
POETRY_NO_INTERACTION=1 \
Expand Down
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "daily"
22 changes: 10 additions & 12 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: set up Poetry
uses: abatilo/actions-poetry@v2.0.0
with:
poetry-version: "1.3.1"
uses: abatilo/actions-poetry@v3
- name: get version
id: get_version
run: echo "VERSION=$(echo ${GITHUB_REF/refs\/tags\//})" >> $GITHUB_ENV
Expand All @@ -30,7 +28,7 @@ jobs:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_API_TOKEN }}
run: poetry publish --build
- name: Create GitHub release entry
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
id: create_release
with:
draft: true
Expand All @@ -48,7 +46,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Prepare
id: prep
run: |
Expand Down Expand Up @@ -79,7 +77,7 @@ jobs:
platforms: all
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
Expand All @@ -89,7 +87,7 @@ jobs:
with:
install: true
- name: Build
uses: docker/build-push-action@v2
uses: docker/build-push-action@v6
with:
context: .
file: ./release.dockerfile
Expand All @@ -114,12 +112,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
ref: main

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: 3.11

Expand All @@ -131,7 +129,7 @@ jobs:
- name: Update Citation.cff
env:
ZENODO_TOKEN: ${{ secrets.ZENODO_TOKEN }}
run: python .github/workflows/update_citation.py
run: python .github/workflows/update_citation.py $(echo ${GITHUB_REF/refs\/tags\//})

- name: Update version in pyproject.toml
run: python .github/workflows/update_pyproject.py $(echo ${GITHUB_REF/refs\/tags\//})
Expand Down
12 changes: 5 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 40
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- name: set up Poetry
uses: abatilo/actions-poetry@v2.0.0
with:
poetry-version: "1.6.1"
uses: abatilo/actions-poetry@v3
- name: install dependencies
run: |
set -x
Expand All @@ -33,11 +31,11 @@ jobs:
- name: test startup
run: ./test_startup.sh
- name: setup chromedriver
uses: nanasess/setup-chromedriver@v2.2.0
uses: nanasess/setup-chromedriver@v2.2.2
- name: pytest
run: pytest
- name: upload screenshots
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/update_citation.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python3
import os
import sys
from pathlib import Path
Expand All @@ -7,7 +8,7 @@
import yaml


def get_infos() -> Tuple[str, str, str]:
def get_infos() -> Tuple[str, str]:
headers = {
'Accept': 'application/json',
}
Expand All @@ -26,11 +27,12 @@ def get_infos() -> Tuple[str, str, str]:
sys.exit(1)
data = response.json()
metadata = data['hits']['hits'][0]['metadata']
return str(metadata['doi']), str(metadata['version']), str(metadata['publication_date'])
return str(metadata['doi']), str(metadata['publication_date'])


if __name__ == '__main__':
path = Path('CITATION.cff')
citation = yaml.safe_load(path.read_text())
citation['doi'], citation['version'], citation['date-released'] = get_infos()
citation['doi'], citation['date-released'] = get_infos()
citation['version'] = sys.argv[1].removeprefix('v')
path.write_text(yaml.dump(citation, sort_keys=False, default_flow_style=False))
6 changes: 3 additions & 3 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ authors:
given-names: Rodja
orcid: https://orcid.org/0009-0009-4735-6227
title: 'NiceGUI: Web-based user interfaces with Python. The nice way.'
version: v1.4.27
date-released: '2024-06-13'
version: 2.1.0
date-released: '2024-08-31'
url: https://github.com/zauberzeug/nicegui
doi: 10.5281/zenodo.11637764
doi: 10.5281/zenodo.13623828
62 changes: 33 additions & 29 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,6 @@ To view the log output, use the command

### Formatting

We use [pre-commit](https://github.com/pre-commit/pre-commit) to make sure the coding style is enforced.
You first need to install pre-commit and the corresponding git commit hooks by running the following commands:

```bash
python3 -m pip install pre-commit
pre-commit install
```

After that you can make sure your code satisfies the coding style by running the following command:

```bash
pre-commit run --all-files
```

These checks will also run automatically before every commit.

### Formatting

We use [autopep8](https://github.com/hhatto/autopep8) with a 120 character line length to format our code.
Before submitting a pull request, please run

Expand All @@ -109,24 +91,46 @@ There are cases where one or the other arrangement of, e.g., function arguments
Then we like the flexibility to either put all arguments on separate lines or only put the lengthy event handler
on a second line and leave the other arguments as they are.

### Imports
### Linting

We use [ruff](https://docs.astral.sh/ruff/) to automatically sort imports:
We use [pre-commit](https://github.com/pre-commit/pre-commit) to make sure the coding style is enforced.
You first need to install pre-commit and the corresponding git commit hooks by running the following commands:

```bash
ruff check . --fix
python3 -m pip install pre-commit
pre-commit install
```

### Single vs Double Quotes

Regarding single or double quotes: [PEP 8](https://peps.python.org/pep-0008/) doesn't give any recommendation, so we simply chose single quotes and sticked with it.
On qwerty keyboards it's a bit easier to type, is visually less cluttered, and it works well for strings containing double quotes from the English language.
After that you can make sure your code satisfies the coding style by running the following command:

### F-Strings
```bash
pre-commit run --all-files
```

We use f-strings where ever possible because they are generally more readable - once you get used to them.
There are only a few places in the code base where performance really matters and f-strings might not be the best choice.
These places should be marked with a `# NOTE: ...` comment when diverging from f-string usage.
> [!TIP]
> The command may fail with
>
> > RuntimeError: failed to find interpreter for Builtin discover of python_spec='python3.8'
>
> You will need to install Python 3.8 and make sure it is available in your `PATH`.
These checks will also run automatically before every commit:

- Run `ruff check . --fix` to check the code and sort imports.
- Remove trailing whitespace.
- Fix end of files.
- Enforce single quotes.

> [!NOTE]
>
> **Regarding single or double quotes:** > [PEP 8](https://peps.python.org/pep-0008/) doesn't give any recommendation, so we simply chose single quotes and sticked with it.
> On qwerty keyboards it's a bit easier to type, is visually less cluttered, and it works well for strings containing double quotes from the English language.
> [!NOTE]
>
> **We use f-strings** where ever possible because they are generally more readable - once you get used to them.
> There are only a few places in the code base where performance really matters and f-strings might not be the best choice.
> These places should be marked with a `# NOTE: ...` comment when diverging from f-string usage.
## Running tests

Expand Down
26 changes: 13 additions & 13 deletions DEPENDENCIES.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# Included Web Dependencies

- vue: 3.3.6 ([MIT](https://opensource.org/licenses/MIT))
- quasar: 2.13.0 ([MIT](https://opensource.org/licenses/MIT))
- tailwindcss: 3.2.0 ([MIT](https://opensource.org/licenses/MIT))
- socket.io: 4.7.2 ([MIT](https://opensource.org/licenses/MIT))
- es-module-shims: 1.8.0 ([MIT](https://opensource.org/licenses/MIT))
- aggrid: 30.2.0 ([MIT](https://opensource.org/licenses/MIT))
- vue: 3.4.38 ([MIT](https://opensource.org/licenses/MIT))
- quasar: 2.16.9 ([MIT](https://opensource.org/licenses/MIT))
- tailwindcss: 3.4.10 ([MIT](https://opensource.org/licenses/MIT))
- socket.io: 4.7.5 ([MIT](https://opensource.org/licenses/MIT))
- es-module-shims: 1.10.0 ([MIT](https://opensource.org/licenses/MIT))
- aggrid: 32.1.0 ([MIT](https://opensource.org/licenses/MIT))
- codemirror: 6.0.1 ([MIT](https://opensource.org/licenses/MIT))
- echarts: 5.4.3 ([Apache-2.0](https://opensource.org/licenses/Apache-2.0))
- echarts: 5.5.1 ([Apache-2.0](https://opensource.org/licenses/Apache-2.0))
- echarts-gl: 2.0.9 ([BSD-3-Clause](https://opensource.org/licenses/BSD-3-Clause))
- leaflet: 1.9.4 ([BSD-2-Clause](https://opensource.org/licenses/BSD-2-Clause))
- leaflet-draw: 1.0.4 ([MIT](https://opensource.org/licenses/MIT))
- mermaid: 10.5.1 ([MIT](https://opensource.org/licenses/MIT))
- nipplejs: 0.10.1 ([MIT](https://opensource.org/licenses/MIT))
- plotly: 2.27.0 ([MIT](https://opensource.org/licenses/MIT))
- three: 0.157.0 ([MIT](https://opensource.org/licenses/MIT))
- tween: 21.0.0 ([MIT](https://opensource.org/licenses/MIT))
- vanilla-jsoneditor: 0.18.10 ([ISC](https://opensource.org/licenses/ISC))
- mermaid: 11.0.2 ([MIT](https://opensource.org/licenses/MIT))
- nipplejs: 0.10.2 ([MIT](https://opensource.org/licenses/MIT))
- plotly: 2.35.0 ([MIT](https://opensource.org/licenses/MIT))
- three: 0.168.0 ([MIT](https://opensource.org/licenses/MIT))
- tween: 25.0.0 ([MIT](https://opensource.org/licenses/MIT))
- vanilla-jsoneditor: 0.23.8 ([ISC](https://opensource.org/licenses/ISC))
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: "3.9"
services:
app:
build:
Expand Down
4 changes: 2 additions & 2 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ if ! getent passwd "$PUID" >/dev/null; then
useradd --create-home --shell /bin/bash --uid "$PUID" --gid "$PGID" appuser
fi
# Make user the owner of the app directory.
chown -R appuser:appgroup /app
chown -R "$PUID":"$PGID" /app
# Copy the default .bashrc file to the appuser home directory.
cp /etc/skel/.bashrc /home/appuser/.bashrc
chown appuser:appgroup /home/appuser/.bashrc
chown "$PUID":"$PGID" /home/appuser/.bashrc
export HOME=/home/appuser
# Set permissions on font directories.
if [ -d "/usr/share/fonts" ]; then
Expand Down
2 changes: 1 addition & 1 deletion docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ case $cmd in
docker compose up -d --build $cmd_args
;;
d | down)
docker compose down -d $cmd_args
docker compose down $cmd_args
;;
s | start)
docker compose start $cmd_args
Expand Down
Empty file.
14 changes: 9 additions & 5 deletions examples/authentication/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from fastapi.responses import RedirectResponse
from starlette.middleware.base import BaseHTTPMiddleware

from nicegui import Client, app, ui
from nicegui import app, ui

# in reality users passwords would obviously need to be hashed
passwords = {'user1': 'pass1', 'user2': 'pass2'}
Expand All @@ -27,7 +27,7 @@ class AuthMiddleware(BaseHTTPMiddleware):

async def dispatch(self, request: Request, call_next):
if not app.storage.user.get('authenticated', False):
if request.url.path in Client.page_routes.values() and request.url.path not in unrestricted_page_routes:
if not request.url.path.startswith('/_nicegui') and request.url.path not in unrestricted_page_routes:
app.storage.user['referrer_path'] = request.url.path # remember where the user wanted to go
return RedirectResponse('/login')
return await call_next(request)
Expand All @@ -38,10 +38,13 @@ async def dispatch(self, request: Request, call_next):

@ui.page('/')
def main_page() -> None:
def logout() -> None:
app.storage.user.clear()
ui.navigate.to('/login')

with ui.column().classes('absolute-center items-center'):
ui.label(f'Hello {app.storage.user["username"]}!').classes('text-2xl')
ui.button(on_click=lambda: (app.storage.user.clear(), ui.navigate.to('/login')), icon='logout') \
.props('outline round')
ui.button(on_click=logout, icon='logout').props('outline round')


@ui.page('/subpage')
Expand All @@ -67,4 +70,5 @@ def try_login() -> None: # local function to avoid passing username and passwor
return None


ui.run(storage_secret='THIS_NEEDS_TO_BE_CHANGED')
if __name__ in {'__main__', '__mp_main__'}:
ui.run(storage_secret='THIS_NEEDS_TO_BE_CHANGED')
37 changes: 37 additions & 0 deletions examples/authentication/test_authentication.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import pytest

from nicegui.testing import User

from . import main

# pylint: disable=missing-function-docstring

pytest_plugins = ['nicegui.testing.user_plugin']


@pytest.mark.module_under_test(main)
async def test_login_logoff(user: User) -> None:
await user.open('/')
user.find('Username').type('user1')
user.find('Password').type('pass1')
user.find('Log in').click()
await user.should_see('Hello user1!')
user.find('logout').click()
await user.should_see('Log in')


@pytest.mark.module_under_test(main)
async def test_wrong_password(user: User) -> None:
await user.open('/')
user.find('Username').type('user1')
user.find('Password').type('wrong').trigger('keydown.enter')
await user.should_see('Wrong username or password')


@pytest.mark.module_under_test(main)
async def test_subpage_access(user: User) -> None:
await user.open('/subpage')
await user.should_see('Log in')
user.find('Username').type('user1')
user.find('Password').type('pass1').trigger('keydown.enter')
await user.should_see('This is a sub page.')
Empty file added examples/chat_app/__init__.py
Empty file.
Loading

0 comments on commit 60e5c42

Please sign in to comment.