Skip to content

Commit

Permalink
Add code check pipeline (#3996)
Browse files Browse the repository at this point in the history
This PR adds a code-check job to the test pipeline which runs
pre-commit, mypy and pylint on the codebase.
  • Loading branch information
codingpaula authored Nov 15, 2024
1 parent b854480 commit 24ee85a
Show file tree
Hide file tree
Showing 6 changed files with 250 additions and 29 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ concurrency:
cancel-in-progress: true

jobs:
code-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: set up Poetry
uses: abatilo/actions-poetry@v3
- name: set up Python
uses: actions/setup-python@v5
with:
python-version: "3.8"
cache: "poetry"
- name: install dependencies
run: poetry install --all-extras --with dev
- name: pre-commit, mypy & pylint
run: |
poetry run pre-commit run --all-files
poetry run mypy ./nicegui --non-interactive
poetry run pylint ./nicegui
test:
strategy:
matrix:
Expand Down Expand Up @@ -42,6 +60,7 @@ jobs:
slack:
needs:
- test
- code-check
if: always() # also execute when test fail
runs-on: ubuntu-latest
steps:
Expand Down
22 changes: 0 additions & 22 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,6 @@
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"prettier.printWidth": 120,
"pylint.args": [
"--disable=C0103", // Invalid name (e.g., variable/function/class naming conventions)
"--disable=C0114", // Missing module docstring
"--disable=C0115", // Missing class docstring
"--disable=C0301", // Line too long (exceeds character limit)
"--disable=C0302", // Too many lines in module
"--disable=R0801", // Similar lines in files
"--disable=R0901", // Too many ancestors
"--disable=R0902", // Too many instance attributes
"--disable=R0903", // Too few public methods
"--disable=R0904", // Too many public methods
"--disable=R0911", // Too many return statements
"--disable=R0912", // Too many branches
"--disable=R0913", // Too many arguments
"--disable=R0914", // Too many local variables
"--disable=R0915", // Too many statements
"--disable=R1705", // Unnecessary "else" after "return"
"--disable=W0102", // Dangerous default value as argument
"--disable=W0718", // Catching too general exception
"--disable=W1203", // Use % formatting in logging functions
"--disable=W1514" // Using open without explicitly specifying an encoding
],
"python.testing.pytestArgs": ["."],
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": false,
Expand Down
2 changes: 1 addition & 1 deletion nicegui/elements/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(self, *, close: bool = True, **kwargs: Any) -> None:

super().__init__('div')
self.close = close
self.fig = plt.figure(**kwargs)
self.fig = plt.figure(**kwargs) # pylint: disable=possibly-used-before-assignment
self._convert_to_html()

if not self.client.shared:
Expand Down
18 changes: 13 additions & 5 deletions nicegui/native/native.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=C0116
import inspect
import warnings
from multiprocessing import Queue
Expand Down Expand Up @@ -52,7 +53,7 @@ def set_title(self, title: str) -> None:
async def get_cookies(self) -> Any: # pylint: disable=invalid-overridden-method
return await self._request()

async def get_current_url(self) -> str: # pylint: disable=invalid-overridden-method
async def get_current_url(self) -> str: # type: ignore # pylint: disable=invalid-overridden-method
return await self._request()

def destroy(self) -> None:
Expand Down Expand Up @@ -85,13 +86,20 @@ def toggle_fullscreen(self) -> None:
def move(self, x: int, y: int) -> None:
self._send(x, y)

async def evaluate_js(self, script: str) -> str: # pylint: disable=arguments-differ,invalid-overridden-method
async def evaluate_js( # type: ignore # pylint: disable=arguments-differ,invalid-overridden-method
self,
script: str,
) -> str:
return await self._request(script)

async def create_confirmation_dialog(self, title: str, message: str) -> bool: # pylint: disable=invalid-overridden-method
async def create_confirmation_dialog( # type: ignore # pylint: disable=invalid-overridden-method
self,
title: str,
message: str,
) -> bool:
return await self._request(title, message)

async def create_file_dialog( # pylint: disable=invalid-overridden-method
async def create_file_dialog( # type: ignore # pylint: disable=invalid-overridden-method
self,
dialog_type: int = webview.OPEN_DIALOG,
directory: str = '',
Expand All @@ -107,7 +115,7 @@ async def create_file_dialog( # pylint: disable=invalid-overridden-method
file_types=file_types,
)

def expose(self, function: Callable) -> None: # pylint: disable=arguments-differ
def expose(self, function: Callable) -> None: # type: ignore # pylint: disable=arguments-differ
raise NotImplementedError(f'exposing "{function}" is not supported')

def _send(self, *args: Any, **kwargs: Any) -> None:
Expand Down
187 changes: 186 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ polars = [
{version = "^1.8.0", python = "~3.8"},
{version = "^1.12.0", python = ">=3.9,<3.14"}
]
mypy = "^1.13.0"
pylint = [
{version = "^3.1.0", python = "~3.8"},
{version = ">=3.3.1", python = ">=3.9,<3.13"}
]

[tool.poetry.scripts]
nicegui-pack = "nicegui.scripts.pack:main"
Expand All @@ -89,6 +94,8 @@ asyncio_default_fixture_loop_scope = "function"

[tool.mypy]
python_version = "3.8"
install_types = true
check_untyped_defs = true

[[tool.mypy.overrides]]
module = [
Expand Down Expand Up @@ -137,3 +144,27 @@ ignore = [
exclude = [
"website/documentation/content/*",
]

[tool.pylint]
disable = [
"C0103", # Invalid name (e.g., variable/function/class naming conventions)
"C0114", # Missing module docstring
"C0115", # Missing class docstring
"C0301", # Line too long (exceeds character limit)
"C0302", # Too many lines in module
"R0801", # Similar lines in files
"R0901", # Too many ancestors
"R0902", # Too many instance attributes
"R0903", # Too few public methods
"R0904", # Too many public methods
"R0911", # Too many return statements
"R0912", # Too many branches
"R0913", # Too many arguments
"R0914", # Too many local variables
"R0915", # Too many statements
"R1705", # Unnecessary "else" after "return"
"W0102", # Dangerous default value as argument
"W0718", # Catching too general exception
"W1203", # Use % formatting in logging functions
"W1514" # Using open without explicitly specifying an encoding
]

0 comments on commit 24ee85a

Please sign in to comment.