Skip to content

Commit

Permalink
chore: use official isort in pre-commmit (#17215)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoyongjie authored Oct 25, 2021
1 parent 31085e3 commit 4f1d202
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 28 deletions.
8 changes: 2 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions superset/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions superset/initialization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions superset/security/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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 = (
Expand Down
4 changes: 2 additions & 2 deletions superset/sqllab/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
4 changes: 2 additions & 2 deletions superset/sqllab/execution_context_convertor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion superset/sqllab/query_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
2 changes: 1 addition & 1 deletion superset/utils/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions tests/integration_tests/dashboards/filter_sets/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

if TYPE_CHECKING:
from flask.testing import FlaskClient

from superset.models.filter_set import FilterSet


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

if TYPE_CHECKING:
from flask.testing import FlaskClient

from superset.models.filter_set import FilterSet


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

if TYPE_CHECKING:
from flask.testing import FlaskClient

from superset.models.filter_set import FilterSet


Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests/fixtures/birth_names_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion tests/integration_tests/reports/commands_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
11 changes: 6 additions & 5 deletions tests/integration_tests/sqla_models_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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"),
Expand Down

0 comments on commit 4f1d202

Please sign in to comment.