From 4f1d202430c35723130d2004b2e7b8a345bb8ab7 Mon Sep 17 00:00:00 2001 From: Yongjie Zhao Date: Mon, 25 Oct 2021 10:57:38 +0100 Subject: [PATCH] chore: use official isort in pre-commmit (#17215) --- .pre-commit-config.yaml | 8 ++------ superset/config.py | 1 + superset/initialization/__init__.py | 6 +++--- superset/security/manager.py | 6 +++--- superset/sqllab/command.py | 4 ++-- superset/sqllab/execution_context_convertor.py | 4 ++-- superset/sqllab/query_render.py | 2 +- superset/utils/core.py | 2 +- .../dashboards/filter_sets/conftest.py | 7 ++++--- .../dashboards/filter_sets/delete_api_tests.py | 1 + .../dashboards/filter_sets/get_api_tests.py | 1 + .../dashboards/filter_sets/update_api_tests.py | 1 + .../fixtures/birth_names_dashboard.py | 2 +- tests/integration_tests/reports/commands_tests.py | 3 ++- tests/integration_tests/sqla_models_tests.py | 11 ++++++----- 15 files changed, 31 insertions(+), 28 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a3c5fd6da43a9..ef644cae77db0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,12 +15,8 @@ # limitations under the License. # repos: - - repo: https://github.com/asottile/seed-isort-config - rev: v1.9.3 - hooks: - - id: seed-isort-config - - repo: https://github.com/pre-commit/mirrors-isort - rev: v4.3.21 + - repo: https://github.com/PyCQA/isort + rev: 5.9.3 hooks: - id: isort - repo: https://github.com/pre-commit/mirrors-mypy diff --git a/superset/config.py b/superset/config.py index ba236b029dcd2..711b1632e7cde 100644 --- a/superset/config.py +++ b/superset/config.py @@ -53,6 +53,7 @@ if TYPE_CHECKING: from flask_appbuilder.security.sqla import models + from superset.connectors.sqla.models import SqlaTable from superset.models.core import Database diff --git a/superset/initialization/__init__.py b/superset/initialization/__init__.py index b8a1098cf0b9d..56076e294fc11 100644 --- a/superset/initialization/__init__.py +++ b/superset/initialization/__init__.py @@ -112,8 +112,8 @@ def init_views(self) -> None: # the global Flask app # # pylint: disable=import-outside-toplevel,too-many-locals,too-many-statements - from superset.annotation_layers.api import AnnotationLayerRestApi from superset.annotation_layers.annotations.api import AnnotationRestApi + from superset.annotation_layers.api import AnnotationLayerRestApi from superset.async_events.api import AsyncEventsRestApi from superset.cachekeys.api import CacheRestApi from superset.charts.api import ChartRestApi @@ -132,16 +132,16 @@ def init_views(self) -> None: ) from superset.css_templates.api import CssTemplateRestApi from superset.dashboards.api import DashboardRestApi + from superset.dashboards.filter_sets.api import FilterSetRestApi from superset.databases.api import DatabaseRestApi from superset.datasets.api import DatasetRestApi from superset.datasets.columns.api import DatasetColumnsRestApi from superset.datasets.metrics.api import DatasetMetricRestApi from superset.queries.api import QueryRestApi - from superset.security.api import SecurityRestApi from superset.queries.saved_queries.api import SavedQueryRestApi from superset.reports.api import ReportScheduleRestApi from superset.reports.logs.api import ReportExecutionLogRestApi - from superset.dashboards.filter_sets.api import FilterSetRestApi + from superset.security.api import SecurityRestApi from superset.views.access_requests import AccessRequestsModelView from superset.views.alerts import ( AlertLogModelView, diff --git a/superset/security/manager.py b/superset/security/manager.py index ff25a2c1dcdcf..523f8d97767e5 100644 --- a/superset/security/manager.py +++ b/superset/security/manager.py @@ -69,8 +69,8 @@ from superset.common.query_context import QueryContext from superset.connectors.base.models import BaseDatasource from superset.connectors.druid.models import DruidCluster - from superset.models.dashboard import Dashboard from superset.models.core import Database + from superset.models.dashboard import Dashboard from superset.models.sql_lab import Query from superset.sql_parse import Table from superset.viz import BaseViz @@ -1169,10 +1169,10 @@ def raise_for_dashboard_access(dashboard: "Dashboard") -> None: :raises DashboardAccessDeniedError: If the user cannot access the resource """ # pylint: disable=import-outside-toplevel + from superset import is_feature_enabled from superset.dashboards.commands.exceptions import DashboardAccessDeniedError from superset.views.base import get_user_roles, is_user_admin from superset.views.utils import is_owner - from superset import is_feature_enabled if is_feature_enabled("DASHBOARD_RBAC"): has_rbac_access = any( @@ -1193,8 +1193,8 @@ def can_access_based_on_dashboard(datasource: "BaseDatasource") -> bool: # pylint: disable=import-outside-toplevel from superset import db from superset.dashboards.filters import DashboardAccessFilter - from superset.models.slice import Slice from superset.models.dashboard import Dashboard + from superset.models.slice import Slice datasource_class = type(datasource) query = ( diff --git a/superset/sqllab/command.py b/superset/sqllab/command.py index cb4854965de5d..1c2674b060f19 100644 --- a/superset/sqllab/command.py +++ b/superset/sqllab/command.py @@ -37,10 +37,10 @@ from superset.sqllab.limiting_factor import LimitingFactor if TYPE_CHECKING: + from superset.databases.dao import DatabaseDAO + from superset.queries.dao import QueryDAO from superset.sqllab.sql_json_executer import SqlJsonExecutor from superset.sqllab.sqllab_execution_context import SqlJsonExecutionContext - from superset.queries.dao import QueryDAO - from superset.databases.dao import DatabaseDAO logger = logging.getLogger(__name__) diff --git a/superset/sqllab/execution_context_convertor.py b/superset/sqllab/execution_context_convertor.py index 6d52355d20f75..20eabfa7b3f4d 100644 --- a/superset/sqllab/execution_context_convertor.py +++ b/superset/sqllab/execution_context_convertor.py @@ -26,9 +26,9 @@ from superset.sqllab.utils import apply_display_max_row_configuration_if_require if TYPE_CHECKING: - from superset.sqllab.sqllab_execution_context import SqlJsonExecutionContext - from superset.sqllab.sql_json_executer import SqlResults from superset.models.sql_lab import Query + from superset.sqllab.sql_json_executer import SqlResults + from superset.sqllab.sqllab_execution_context import SqlJsonExecutionContext class ExecutionContextConvertorImpl(ExecutionContextConvertor): diff --git a/superset/sqllab/query_render.py b/superset/sqllab/query_render.py index b03b21d83ce3a..a280e303a3669 100644 --- a/superset/sqllab/query_render.py +++ b/superset/sqllab/query_render.py @@ -32,8 +32,8 @@ MSG_OF_1006 = "Issue 1006 - One or more parameters specified in the query are missing." if TYPE_CHECKING: - from superset.sqllab.sqllab_execution_context import SqlJsonExecutionContext from superset.jinja_context import BaseTemplateProcessor + from superset.sqllab.sqllab_execution_context import SqlJsonExecutionContext PARAMETER_MISSING_ERR = ( "Please check your template parameters for syntax errors and make sure " diff --git a/superset/utils/core.py b/superset/utils/core.py index b99036f5d7f52..81c4343cd5372 100644 --- a/superset/utils/core.py +++ b/superset/utils/core.py @@ -16,6 +16,7 @@ # under the License. """Utility functions used across Superset""" # pylint: disable=too-many-lines +import _thread # pylint: disable=C0411 import collections import decimal import errno @@ -85,7 +86,6 @@ from sqlalchemy.types import TEXT, TypeDecorator, TypeEngine from typing_extensions import TypedDict, TypeGuard -import _thread # pylint: disable=C0411 from superset.constants import ( EXAMPLES_DB_UUID, EXTRA_FORM_DATA_APPEND_KEYS, diff --git a/tests/integration_tests/dashboards/filter_sets/conftest.py b/tests/integration_tests/dashboards/filter_sets/conftest.py index 36642b194dbce..d07f869f6a551 100644 --- a/tests/integration_tests/dashboards/filter_sets/conftest.py +++ b/tests/integration_tests/dashboards/filter_sets/conftest.py @@ -49,17 +49,18 @@ if TYPE_CHECKING: from flask.ctx import AppContext from flask.testing import FlaskClient + from flask_appbuilder.security.manager import BaseSecurityManager from flask_appbuilder.security.sqla.models import ( + PermissionView, Role, User, ViewMenu, - PermissionView, ) - from flask_appbuilder.security.manager import BaseSecurityManager from sqlalchemy.orm import Session - from superset.models.slice import Slice + from superset.connectors.sqla.models import SqlaTable from superset.models.core import Database + from superset.models.slice import Slice security_manager: BaseSecurityManager = sm diff --git a/tests/integration_tests/dashboards/filter_sets/delete_api_tests.py b/tests/integration_tests/dashboards/filter_sets/delete_api_tests.py index 12a9bff9e13b8..34f52011d812b 100644 --- a/tests/integration_tests/dashboards/filter_sets/delete_api_tests.py +++ b/tests/integration_tests/dashboards/filter_sets/delete_api_tests.py @@ -32,6 +32,7 @@ if TYPE_CHECKING: from flask.testing import FlaskClient + from superset.models.filter_set import FilterSet diff --git a/tests/integration_tests/dashboards/filter_sets/get_api_tests.py b/tests/integration_tests/dashboards/filter_sets/get_api_tests.py index 3db2d472eae71..a1ad55aa2a8bd 100644 --- a/tests/integration_tests/dashboards/filter_sets/get_api_tests.py +++ b/tests/integration_tests/dashboards/filter_sets/get_api_tests.py @@ -31,6 +31,7 @@ if TYPE_CHECKING: from flask.testing import FlaskClient + from superset.models.filter_set import FilterSet diff --git a/tests/integration_tests/dashboards/filter_sets/update_api_tests.py b/tests/integration_tests/dashboards/filter_sets/update_api_tests.py index fcaeaab016c6c..ccd5ae83afba1 100644 --- a/tests/integration_tests/dashboards/filter_sets/update_api_tests.py +++ b/tests/integration_tests/dashboards/filter_sets/update_api_tests.py @@ -40,6 +40,7 @@ if TYPE_CHECKING: from flask.testing import FlaskClient + from superset.models.filter_set import FilterSet diff --git a/tests/integration_tests/fixtures/birth_names_dashboard.py b/tests/integration_tests/fixtures/birth_names_dashboard.py index 67ea016e26d70..7d78a22656a2f 100644 --- a/tests/integration_tests/fixtures/birth_names_dashboard.py +++ b/tests/integration_tests/fixtures/birth_names_dashboard.py @@ -71,7 +71,7 @@ def _load_data(): fetch_values_predicate="123 = 123", ) - from superset.examples.birth_names import create_slices, create_dashboard + from superset.examples.birth_names import create_dashboard, create_slices slices, _ = create_slices(table, admin_owner=False) dash = create_dashboard(slices) diff --git a/tests/integration_tests/reports/commands_tests.py b/tests/integration_tests/reports/commands_tests.py index b94b579fe4c46..1ed3f35a16512 100644 --- a/tests/integration_tests/reports/commands_tests.py +++ b/tests/integration_tests/reports/commands_tests.py @@ -1610,9 +1610,10 @@ def test_grace_period_error_flap( ) @patch("superset.reports.dao.ReportScheduleDAO.bulk_delete_logs") def test_prune_log_soft_time_out(bulk_delete_logs, create_report_email_dashboard): - from celery.exceptions import SoftTimeLimitExceeded from datetime import datetime, timedelta + from celery.exceptions import SoftTimeLimitExceeded + bulk_delete_logs.side_effect = SoftTimeLimitExceeded() with pytest.raises(SoftTimeLimitExceeded) as excinfo: AsyncPruneReportScheduleLogCommand().run() diff --git a/tests/integration_tests/sqla_models_tests.py b/tests/integration_tests/sqla_models_tests.py index 7155735b5db11..e92ba165687ce 100644 --- a/tests/integration_tests/sqla_models_tests.py +++ b/tests/integration_tests/sqla_models_tests.py @@ -58,6 +58,12 @@ } +class FilterTestCase(NamedTuple): + operator: str + value: Union[float, int, List[Any], str] + expected: Union[str, List[str]] + + class TestDatabaseModel(SupersetTestCase): def test_is_time_druid_time_col(self): """Druid has a special __time column""" @@ -223,11 +229,6 @@ def test_jinja_metrics_and_calc_columns(self, flask_g): @pytest.mark.usefixtures("load_birth_names_dashboard_with_slices") def test_where_operators(self): - class FilterTestCase(NamedTuple): - operator: str - value: Union[float, int, List[Any], str] - expected: Union[str, List[str]] - filters: Tuple[FilterTestCase, ...] = ( FilterTestCase(FilterOperator.IS_NULL, "", "IS NULL"), FilterTestCase(FilterOperator.IS_NOT_NULL, "", "IS NOT NULL"),