Skip to content

refactor, ci: upgrade linting & ci setup #39

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 8 commits into from
Dec 16, 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
29 changes: 11 additions & 18 deletions .github/workflows/codequality.yaml
Original file line number Diff line number Diff line change
@@ -1,33 +1,26 @@
name: Code quality

on:
- push
- pull_request
- workflow_dispatch
workflow_call:
workflow_dispatch:

jobs:
build:
code-quality:
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
python-version: [3.7, 3.8, 3.9, "3.10", "3.11"]
python-version: [3.8, 3.9, "3.10", "3.11"] # pre-commit does not support Python < 3.8

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Downgrade pip
run: pip install "pip<22"
- name: Install dependencies
run: |
pip install ".[dev]" "mypy<1" "black<23"
mypy --install-types --non-interactive reacton
- name: Run black
run: black reacton
- name: Run flake
run: flake8 reacton
- name: mypy
run: mypy reacton
pip install ".[dev]"
- name: Install pre-commit
run: pre-commit install
- name: Run pre-commit
run: pre-commit run --all-files
17 changes: 10 additions & 7 deletions .github/workflows/installation.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
name: Test installation

on:
- push
- pull_request
- workflow_dispatch
workflow_call:
workflow_dispatch:

jobs:
build:
test-installation:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python 3.7
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: 3.7
- name: Install hatch
run: pip install hatch "pip<22"
run: pip install hatch
- name: Build
run: hatch build
- name: Install
run: pip install dist/*.whl
- name: Test import
run: python -c "import react_ipywidgets; import reacton"
- uses: actions/upload-artifact@v4
with:
name: reacton-build-${{ github.run_number }}
path: ./dist
15 changes: 11 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@ on:
- "*"

jobs:
build:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: ./.github/workflows/unittest.yml

release:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.7
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: 3.7
- name: Install hatch
Expand All @@ -29,7 +36,7 @@ jobs:
run: |
openssl sha256 dist/*
hatch publish
- uses: actions/upload-artifact@v1
- uses: actions/upload-artifact@v4
with:
name: distributions
path: ./dist
28 changes: 20 additions & 8 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
name: Unit testing

on:
- push
- pull_request
- workflow_dispatch
push:
branches:
- master
pull_request:
workflow_dispatch:

jobs:
build:
uses: ./.github/workflows/installation.yml

code-quality:
uses: ./.github/workflows/codequality.yaml

unit-test:
needs: [build, code-quality]
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
python-version: [3.6, 3.7, 3.8, 3.9, "3.10", "3.11"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Downgrade pip
run: pip install "pip<22"
- uses: actions/download-artifact@v4
with:
name: reacton-build-${{ github.run_number }}
path: ./dist
- name: Install
run: pip install ".[dev]" "black<23"
run: |
pip install `echo dist/*.whl`[dev] "black<23"
- name: test
run: pytest --cov=reacton reacton
23 changes: 8 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
rev: v5.0.0
hooks:
- id: check-yaml
args: [--unsafe]
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 22.3.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.3
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 3.9.2
hooks:
- id: flake8
- repo: https://github.com/PyCQA/isort
rev: 5.11.5
hooks:
- id: isort
files: \.py$
args: [--profile=black]
- id: ruff
stages: [pre-commit]
- id: ruff-format
stages: [pre-commit]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v0.942" # Use the sha / tag you want to point at
rev: "v1.13.0" # Use the sha / tag you want to point at
hooks:
- id: mypy
10 changes: 7 additions & 3 deletions notebooks/calculator.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@
" with w.VBox():\n",
" w.Label(value=state.error or state.output or \"0\")\n",
"\n",
" \n",
" with w.HBox():\n",
" if state.input:\n",
" w.Button(description=\"C\", on_click=lambda: dispatch((\"clear\", None)))\n",
Expand All @@ -157,6 +156,7 @@
" op = operator_map[op_symbol]\n",
" w.Button(description=op_symbol, on_click=lambda op=op: dispatch((\"operator\", op)))\n",
" with w.HBox():\n",
"\n",
" def boom():\n",
" print(\"boom\")\n",
" raise ValueError(\"boom\")\n",
Expand All @@ -170,7 +170,8 @@
"\n",
" return main\n",
"\n",
"Calculator()\n"
"\n",
"Calculator()"
]
},
{
Expand Down Expand Up @@ -225,6 +226,7 @@
" op = operator_map[op_symbol]\n",
" v.BtnWithClick(children=op_symbol, color=\"primary\", on_click=lambda op=op: dispatch((\"operator\", op)), class_=class_)\n",
" with w.HBox():\n",
"\n",
" def boom():\n",
" print(\"boom\")\n",
" raise ValueError(\"boom\")\n",
Expand All @@ -237,7 +239,9 @@
" v.BtnWithClick(children=\"=\", color=\"primary\", on_click=lambda: dispatch((\"calculate\", None)), class_=class_)\n",
"\n",
" return main\n",
"CalculatorVuetify()\n"
"\n",
"\n",
"CalculatorVuetify()"
]
},
{
Expand Down
26 changes: 18 additions & 8 deletions notebooks/click-button.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@
"\n",
"\n",
"clicks = 0 # issue 3\n",
"\n",
"\n",
"def on_click(button):\n",
" global clicks # issue 3\n",
" clicks += 1\n",
" button.description = f\"Clicked {clicks} times\" # issue 1\n",
"button = widgets.Button(description=\"Clicked 0 times\") # issue 1\n",
" button.description = f\"Clicked {clicks} times\" # issue 1\n",
"\n",
"\n",
"button = widgets.Button(description=\"Clicked 0 times\") # issue 1\n",
"button.on_click(on_click) # issue 2\n",
"display(button)"
]
Expand Down Expand Up @@ -64,15 +68,15 @@
" # first render, this return 0, after that, the last argument\n",
" # of set_clicks\n",
" clicks, set_clicks = reacton.use_state(0)\n",
" \n",
"\n",
" def my_click_handler():\n",
" # trigger a new render with a new value for clicks\n",
" set_clicks(clicks+1)\n",
" set_clicks(clicks + 1)\n",
"\n",
" button = w.Button(description=f\"Clicked {clicks} times\",\n",
" on_click=my_click_handler)\n",
" button = w.Button(description=f\"Clicked {clicks} times\", on_click=my_click_handler)\n",
" return button\n",
"\n",
"\n",
"ButtonClick()"
]
},
Expand All @@ -89,6 +93,8 @@
" slider = w.IntSlider(min=0, max=20, value=count, on_value=set_count)\n",
" buttons = [ButtonClick() for i in range(count)]\n",
" return w.VBox(children=[slider, *buttons])\n",
"\n",
"\n",
"display(ManyButtons())"
]
},
Expand Down Expand Up @@ -116,12 +122,16 @@
" # first render, this return 0, after that, the last argument\n",
" # of set_clicks\n",
" clicks, set_clicks = reacton.use_state(0)\n",
"\n",
" def my_click_handler(*ignore_args):\n",
" # trigger a new render with a new value for clicks\n",
" set_clicks(clicks+1)\n",
" set_clicks(clicks + 1)\n",
"\n",
" button = rv.Btn(children=[f\"Clicked {clicks} times\"])\n",
" rv.use_event(button, 'click', my_click_handler)\n",
" rv.use_event(button, \"click\", my_click_handler)\n",
" return button\n",
"\n",
"\n",
"ButtonClick()"
]
},
Expand Down
9 changes: 5 additions & 4 deletions notebooks/markdown.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
" html = markdown.markdown(md)\n",
" return w.HTML(value=html)\n",
"\n",
"\n",
"Markdown(\"# Reacton rocks\\nSeriously **bold** idea!\")"
]
},
Expand All @@ -49,17 +50,17 @@
"outputs": [],
"source": [
"@reacton.component\n",
"def MarkdownEditor(md : str):\n",
"def MarkdownEditor(md: str):\n",
" md, set_md = reacton.use_state(md)\n",
" edit, set_edit = reacton.use_state(True)\n",
" with w.VBox() as main:\n",
" Markdown(md)\n",
" w.ToggleButton(description=\"Edit\",\n",
" value=edit,\n",
" on_value=set_edit)\n",
" w.ToggleButton(description=\"Edit\", value=edit, on_value=set_edit)\n",
" if edit:\n",
" w.Textarea(value=md, on_value=set_md, rows=10)\n",
" return main\n",
"\n",
"\n",
"MarkdownEditor(\"# Reacton rocks\\nSeriously **bold** idea!\")"
]
},
Expand Down
Loading
Loading