From d451927a62ea469dfdb5a733d2fe125dd30afeec Mon Sep 17 00:00:00 2001 From: Zachary Blackwood Date: Thu, 8 Sep 2022 10:30:04 -0400 Subject: [PATCH 1/2] Add linting --- .github/workflows/linting.yml | 13 +++++++++++++ .pre-commit-config.yaml | 28 ++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 .github/workflows/linting.yml create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml new file mode 100644 index 0000000..3f06354 --- /dev/null +++ b/.github/workflows/linting.yml @@ -0,0 +1,13 @@ +name: linting + +on: + pull_request: + push: + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + - uses: pre-commit/action@v2.0.3 \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..63ecd25 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,28 @@ +repos: +- repo: https://gitlab.com/pycqa/flake8 + rev: "4.0.1" + hooks: + - id: flake8 + additional_dependencies: + - flake8-bugbear +- repo: https://github.com/psf/black + rev: "22.3.0" + hooks: + - id: black +- repo: https://github.com/PyCQA/isort + rev: "5.10.1" + hooks: + - id: isort +- repo: https://github.com/pre-commit/mirrors-mypy + rev: "v0.942" + hooks: + - id: mypy + args: + - --ignore-missing-imports + - --follow-imports=silent + additional_dependencies: + - types-all +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.1.0 # Use the ref you want to point at + hooks: + - id: trailing-whitespace From 3ce09b2499d6e0fe8f952bdd728d58970fb299b2 Mon Sep 17 00:00:00 2001 From: Zachary Blackwood Date: Thu, 8 Sep 2022 10:40:20 -0400 Subject: [PATCH 2/2] Add configuration to make linters behave nicely --- .flake8 | 20 ++++++++++++++++++++ pyproject.toml | 30 ++++++++++++++++++++++++++++++ src/st_keyup/__init__.py | 9 +++++++-- src/st_keyup/frontend/main.js | 2 +- 4 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 .flake8 create mode 100644 pyproject.toml diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..c49849e --- /dev/null +++ b/.flake8 @@ -0,0 +1,20 @@ +[flake8] +max-line-length = 88 +select = + E # pep8 errors + F # pyflakes errors + W # pep8 warnings + B # flake8-bugbear warnings +ignore = + E501 # "Line lengths are recommended to be no greater than 79 characters" + E203 # "Whitespace before ':'": conflicts with black + W503 # "line break before binary operator": conflicts with black +exclude = + .git + .vscode + .pytest_cache + .mypy_cache + .venv + .env + .direnv +per-file-ignores = \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..811553f --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,30 @@ +[tool.isort] +profile = "black" +line_length = 88 +skip = ["./.venv", "./direnv", ".env"] + +[tool.black] +exclude = ''' +( + /( + \.vscode + | \.git + | \.pytest_cache + | \.mypy_cache + | \.venv + | \.env + | \.direnv + )/ +) +''' +include = '\.pyi?$' +line-length = 88 + +[tool.mypy] +files = [ + "**/*.py", +] +follow_imports = "silent" +ignore_missing_imports = true +scripts_are_modules = true +python_version = 3.9 \ No newline at end of file diff --git a/src/st_keyup/__init__.py b/src/st_keyup/__init__.py index 88b5333..7f9a2ec 100644 --- a/src/st_keyup/__init__.py +++ b/src/st_keyup/__init__.py @@ -12,7 +12,7 @@ def st_keyup( label: str, value: str = "", key: Optional[str] = None, - debounce: int = 0, + debounce: Optional[int] = None, on_change: Optional[Callable] = None, args: Optional[Tuple[Any, ...]] = None, kwargs: Optional[Dict[str, Any]] = None, @@ -93,7 +93,12 @@ def on_change2(*args, **kwargs): st.write(value) "## Keyup input with args" - value = st_keyup("Enter a fourth value...", on_change=on_change2, args=("Hello", "World"), kwargs={"foo": "bar"}) + value = st_keyup( + "Enter a fourth value...", + on_change=on_change2, + args=("Hello", "World"), + kwargs={"foo": "bar"}, + ) st.write(value) "## Standard text input for comparison" diff --git a/src/st_keyup/frontend/main.js b/src/st_keyup/frontend/main.js index d9d83c1..de4ff6d 100644 --- a/src/st_keyup/frontend/main.js +++ b/src/st_keyup/frontend/main.js @@ -32,7 +32,7 @@ function onRender(event) { input.value = value } - if (debounce_time > 0) { + if (debounce_time > 0) { // is false if debounce_time is 0 or undefined input.onkeyup = debounce(onKeyUp, debounce_time) } else {