From 340004bdeea7b0c9f8f310934fa1d2b9b7662b80 Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Sun, 6 Nov 2022 12:47:15 +0100 Subject: [PATCH] DX: switch to new VSCode Python extensions (#469) * DX: activate and configure VSCode flake8 extension * DX: activate and configure VSCode isort extension * DX: activate and configure VSCode pylint extension * DX: extend pyright file exclusions * MAINT: limit scope of pyright ignore statements --- .gitpod.yml | 3 +++ .vscode/extensions.json | 3 +++ .vscode/settings.json | 9 ++++++--- pyrightconfig.json | 11 +++++++++-- src/tensorwaves/function/_backend.py | 6 +++--- src/tensorwaves/function/sympy/__init__.py | 3 +-- tests/function/test_backend.py | 3 +-- tests/optimizer/test_fit_simple_model.py | 3 +-- 8 files changed, 27 insertions(+), 14 deletions(-) diff --git a/.gitpod.yml b/.gitpod.yml index c0963cb2..7f1e854c 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -22,6 +22,9 @@ vscode: - esbenp.prettier-vscode - executablebookproject.myst-highlight - github.vscode-pull-request-github + - ms-python.flake8 + - ms-python.pylint + - ms-python.isort - ms-python.python - ms-python.vscode-pylance - ms-vsliveshare.vsliveshare diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 6dd65a79..457fce57 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -9,6 +9,9 @@ "esbenp.prettier-vscode", "executablebookproject.myst-highlight", "github.vscode-pull-request-github", + "ms-python.flake8", + "ms-python.pylint", + "ms-python.isort", "ms-python.python", "ms-python.vscode-pylance", "ms-vsliveshare.vsliveshare", diff --git a/.vscode/settings.json b/.vscode/settings.json index f01dd796..38d4239b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -36,6 +36,7 @@ "**/.git/**": true, "**/.tox/**": true }, + "flake8.importStrategy": "fromEnvironment", "git.rebaseWhenSync": true, "github-actions.workflows.pinned.refresh.enabled": true, "github-actions.workflows.pinned.workflows": [ @@ -43,6 +44,8 @@ ".github/workflows/ci-docs.yml", ".github/workflows/ci-tests.yml" ], + "isort.check": true, + "isort.importStrategy": "fromEnvironment", "json.schemas": [ { "fileMatch": ["*particle*.json"], @@ -53,18 +56,18 @@ "url": "https://zenodo.org/schemas/deposits/records/legacyrecord.json" } ], + "pylint.importStrategy": "fromEnvironment", "python.analysis.autoImportCompletions": false, "python.analysis.diagnosticMode": "workspace", "python.analysis.typeCheckingMode": "strict", "python.formatting.provider": "black", "python.linting.banditEnabled": false, "python.linting.enabled": true, - "python.linting.flake8Enabled": true, + "python.linting.flake8Enabled": false, "python.linting.mypyEnabled": true, "python.linting.pydocstyleEnabled": true, "python.linting.pylamaEnabled": false, - "python.linting.pylintCategorySeverity.refactor": "Information", - "python.linting.pylintEnabled": true, + "python.linting.pylintEnabled": false, "python.testing.pytestArgs": ["--color=no", "--no-cov"], "python.testing.pytestEnabled": true, "python.testing.unittestEnabled": false, diff --git a/pyrightconfig.json b/pyrightconfig.json index 46b229ac..f0a8ebfc 100644 --- a/pyrightconfig.json +++ b/pyrightconfig.json @@ -1,6 +1,13 @@ { - "exclude": [".git", ".tox", "docs/_build"], - "include": ["docs", "src", "tests"], + "exclude": [ + "**/__pycache__", + "**/_build", + "**/.git", + "**/.ipynb_checkpoints", + "**/.mypy_cache", + "**/.pytest_cache", + "**/.tox" + ], "reportGeneralTypeIssues": false, "reportMissingTypeArgument": false, "reportMissingTypeStubs": false, diff --git a/src/tensorwaves/function/_backend.py b/src/tensorwaves/function/_backend.py index b302df76..6e7e2053 100644 --- a/src/tensorwaves/function/_backend.py +++ b/src/tensorwaves/function/_backend.py @@ -49,9 +49,8 @@ def get_backend_modules(backend: str | tuple | dict) -> str | tuple | dict: if backend in {"tensorflow", "tf"}: try: # pylint: disable=import-error, no-name-in-module - # pyright: reportMissingImports=false import tensorflow as tf - import tensorflow.experimental.numpy as tnp + import tensorflow.experimental.numpy as tnp # pyright: ignore[reportMissingImports] from tensorflow.python.ops.numpy_ops import np_config except ImportError: # pragma: no cover raise_missing_module_error("tensorflow", extras_require="tf") @@ -75,7 +74,8 @@ def jit_compile(backend: str) -> Callable[[Callable], Callable]: if backend == "numba": try: - import numba # pylint: disable=import-error + # pylint: disable=import-error + import numba # pyright: ignore[reportMissingImports] except ImportError: # pragma: no cover raise_missing_module_error("numba", extras_require="numba") return partial(numba.jit, forceobj=True, parallel=True) diff --git a/src/tensorwaves/function/sympy/__init__.py b/src/tensorwaves/function/sympy/__init__.py index ae768f4e..655301d7 100644 --- a/src/tensorwaves/function/sympy/__init__.py +++ b/src/tensorwaves/function/sympy/__init__.py @@ -216,8 +216,7 @@ def numba_lambdify() -> Callable: def tensorflow_lambdify() -> Callable: try: # pylint: disable=import-error - # pyright: reportMissingImports=false - import tensorflow.experimental.numpy as tnp + import tensorflow.experimental.numpy as tnp # pyright: ignore[reportMissingImports] except ImportError: # pragma: no cover raise_missing_module_error("tensorflow", extras_require="tf") from ._printer import TensorflowPrinter diff --git a/tests/function/test_backend.py b/tests/function/test_backend.py index 14667766..4055e624 100644 --- a/tests/function/test_backend.py +++ b/tests/function/test_backend.py @@ -1,5 +1,4 @@ # pylint: disable=import-error, import-outside-toplevel -# pyright: reportMissingImports=false from tensorwaves.function._backend import find_function @@ -23,7 +22,7 @@ def test_find_function_numpy(): def test_find_function_tf(): import tensorflow as tf - import tensorflow.experimental.numpy as tnp + import tensorflow.experimental.numpy as tnp # pyright: ignore[reportMissingImports] assert find_function("array", backend="tf") is tnp.array assert find_function("linspace", backend="tf") is tnp.linspace diff --git a/tests/optimizer/test_fit_simple_model.py b/tests/optimizer/test_fit_simple_model.py index 0f0b92ef..64d6964c 100644 --- a/tests/optimizer/test_fit_simple_model.py +++ b/tests/optimizer/test_fit_simple_model.py @@ -133,8 +133,7 @@ def test_optimize_all_parameters( # pylint: disable=too-many-locals ] try: # pylint: disable=import-outside-toplevel - # pyright: reportUnusedImport=false - import tensorflow # noqa: F401 + import tensorflow # pyright: ignore[reportUnusedImport] # noqa: F401 callbacks.append(TFSummary()) except ImportError: