You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by hu...@apache.org on 2024/04/24 21:48:03 UTC
(superset) branch hxgh-ruff created (now 35e0bbc4a8)
This is an automated email from the ASF dual-hosted git repository.
hugh pushed a change to branch hxgh-ruff
in repository https://gitbox.apache.org/repos/asf/superset.git
at 35e0bbc4a8 ok first set of fixes
This branch includes the following new commits:
new 35e0bbc4a8 ok first set of fixes
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(superset) 01/01: ok first set of fixes
Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
hugh pushed a commit to branch hxgh-ruff
in repository https://gitbox.apache.org/repos/asf/superset.git
commit 35e0bbc4a8e45436134a34d2f5fed2d88726a105
Author: Hugh Miles <hu...@Hughs-MacBook-Pro.local>
AuthorDate: Wed Apr 24 17:46:41 2024 -0400
ok first set of fixes
---
.pre-commit-config.yaml | 11 +++++++++++
RELEASING/changelog.py | 10 +++++-----
scripts/build_docker.py | 6 ++----
scripts/change_detector.py | 5 ++---
scripts/erd/erd.py | 3 +--
superset/__init__.py | 7 -------
superset/commands/chart/importers/v1/__init__.py | 1 -
superset/commands/dashboard/importers/v1/__init__.py | 1 -
superset/commands/database/create.py | 1 -
superset/commands/database/importers/v1/__init__.py | 1 -
superset/commands/database/update.py | 1 -
superset/commands/dataset/importers/v1/__init__.py | 1 -
superset/commands/importers/v1/__init__.py | 6 +-----
superset/commands/query/importers/v1/__init__.py | 2 --
superset/connectors/sqla/__init__.py | 1 -
superset/connectors/sqla/models.py | 8 ++++----
superset/daos/chart.py | 2 +-
superset/daos/dataset.py | 4 ++--
superset/db_engine_specs/duckdb.py | 2 +-
superset/db_engine_specs/hive.py | 6 ++----
superset/db_engine_specs/ocient.py | 4 ++--
superset/db_engine_specs/presto.py | 6 +++---
superset/examples/data_loading.py | 18 ------------------
superset/models/__init__.py | 1 -
superset/reports/notifications/__init__.py | 2 --
superset/row_level_security/api.py | 2 +-
superset/sql_validators/__init__.py | 1 -
superset/sqllab/execution_context_convertor.py | 2 --
superset/tasks/celery_app.py | 1 -
superset/utils/log.py | 2 +-
superset/views/__init__.py | 12 ------------
superset/viz.py | 1 -
32 files changed, 39 insertions(+), 92 deletions(-)
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index a476dc3ab1..73304d9923 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -95,3 +95,14 @@ repos:
hooks:
- id: helm-docs
files: helm
+ - repo: https://github.com/astral-sh/ruff-pre-commit
+ # Ruff version.
+ rev: v0.1.4
+ hooks:
+ # Run the linter.
+ - id: ruff
+ args: [ --fix ]
+ exclude: ^(superset/migrations/|tests/)|superset/config\.py$
+ # Run the formatter.
+ - id: ruff-format
+ exclude: ^(superset/migrations/|tests/)|superset/config\.py$
\ No newline at end of file
diff --git a/RELEASING/changelog.py b/RELEASING/changelog.py
index d1ba06a620..80ff98cba6 100644
--- a/RELEASING/changelog.py
+++ b/RELEASING/changelog.py
@@ -94,10 +94,10 @@ class GitChangeLog:
if not pull_request:
pull_request = github_repo.get_pull(pr_number)
self._github_prs[pr_number] = pull_request
- except BadCredentialsException as ex:
+ except BadCredentialsException:
print(
- f"Bad credentials to github provided"
- f" use access_token parameter or set GITHUB_TOKEN"
+ "Bad credentials to github provided"
+ " use access_token parameter or set GITHUB_TOKEN"
)
sys.exit(1)
@@ -167,8 +167,8 @@ class GitChangeLog:
def _get_changelog_version_head(self) -> str:
if not len(self._logs):
print(
- f"No changes found between revisions. "
- f"Make sure your branch is up to date."
+ "No changes found between revisions. "
+ "Make sure your branch is up to date."
)
sys.exit(1)
return f"### {self._version} ({self._logs[0].time})"
diff --git a/scripts/build_docker.py b/scripts/build_docker.py
index 3351e508df..812d087399 100755
--- a/scripts/build_docker.py
+++ b/scripts/build_docker.py
@@ -82,8 +82,8 @@ def is_latest_release(release: str) -> bool:
return "SKIP_TAG::false" in output
-def make_docker_tag(l: list[str]) -> str:
- return f"{REPO}:" + "-".join([o for o in l if o])
+def make_docker_tag(tags: list[str]) -> str:
+ return f"{REPO}:" + "-".join([o for o in tags if o])
def get_docker_tags(
@@ -140,7 +140,6 @@ def get_docker_command(
build_context_ref: str,
force_latest: bool = False,
) -> str:
- tag = ""
build_target = ""
py_ver = BASE_PY_IMAGE
docker_context = "."
@@ -284,7 +283,6 @@ def main(
script = script + docker_build_command
if verbose:
run_cmd("cat Dockerfile")
- stdout = run_cmd(script)
else:
print("Dry Run - Docker Build Command:")
print(docker_build_command)
diff --git a/scripts/change_detector.py b/scripts/change_detector.py
index df2c872a4a..4c953555fd 100755
--- a/scripts/change_detector.py
+++ b/scripts/change_detector.py
@@ -21,7 +21,6 @@ import os
import re
import subprocess
from typing import List
-from urllib.error import HTTPError, URLError
from urllib.request import Request, urlopen
# Define patterns for each group of files you're interested in
@@ -102,12 +101,12 @@ def main(event_type: str, sha: str, repo: str) -> None:
if event_type == "pull_request":
pr_number = os.getenv("GITHUB_REF", "").split("/")[-2]
files = fetch_changed_files_pr(repo, pr_number)
- print(f"PR files:")
+ print("PR files:")
print_files(files)
elif event_type == "push":
files = fetch_changed_files_push(repo, sha)
- print(f"Files touched since previous commit:")
+ print("Files touched since previous commit:")
print_files(files)
else:
raise ValueError("Unsupported event type")
diff --git a/scripts/erd/erd.py b/scripts/erd/erd.py
index 0622e0d853..b51cd21652 100644
--- a/scripts/erd/erd.py
+++ b/scripts/erd/erd.py
@@ -27,9 +27,8 @@ from typing import Any, Optional
import click
import jinja2
-from flask.cli import FlaskGroup, with_appcontext
-from superset import app, db
+from superset import db
GROUPINGS: dict[str, Iterable[str]] = {
"Core": [
diff --git a/superset/__init__.py b/superset/__init__.py
index d96697de99..a891207156 100644
--- a/superset/__init__.py
+++ b/superset/__init__.py
@@ -19,19 +19,12 @@
from flask import current_app, Flask
from werkzeug.local import LocalProxy
-from superset.app import create_app
from superset.extensions import (
- appbuilder,
cache_manager,
- db,
- event_logger,
feature_flag_manager,
manifest_processor,
results_backend_manager,
- security_manager,
- talisman,
)
-from superset.security import SupersetSecurityManager
# All of the fields located here should be considered legacy. The correct way
# to declare "global" dependencies is to define it in extensions.py,
diff --git a/superset/commands/chart/importers/v1/__init__.py b/superset/commands/chart/importers/v1/__init__.py
index 7f2537383f..c3f67d4146 100644
--- a/superset/commands/chart/importers/v1/__init__.py
+++ b/superset/commands/chart/importers/v1/__init__.py
@@ -18,7 +18,6 @@
from typing import Any
from marshmallow import Schema
-from sqlalchemy.orm import Session
from superset.charts.schemas import ImportV1ChartSchema
from superset.commands.chart.exceptions import ChartImportError
diff --git a/superset/commands/dashboard/importers/v1/__init__.py b/superset/commands/dashboard/importers/v1/__init__.py
index 77d28696cf..e5f948c911 100644
--- a/superset/commands/dashboard/importers/v1/__init__.py
+++ b/superset/commands/dashboard/importers/v1/__init__.py
@@ -18,7 +18,6 @@
from typing import Any
from marshmallow import Schema
-from sqlalchemy.orm import Session
from sqlalchemy.sql import select
from superset import db
diff --git a/superset/commands/database/create.py b/superset/commands/database/create.py
index 9efb39b75a..4903938eb9 100644
--- a/superset/commands/database/create.py
+++ b/superset/commands/database/create.py
@@ -19,7 +19,6 @@ from typing import Any, Optional
from flask import current_app
from flask_appbuilder.models.sqla import Model
-from flask_babel import gettext as _
from marshmallow import ValidationError
from superset import is_feature_enabled
diff --git a/superset/commands/database/importers/v1/__init__.py b/superset/commands/database/importers/v1/__init__.py
index 203f0e3089..89cfa3b66a 100644
--- a/superset/commands/database/importers/v1/__init__.py
+++ b/superset/commands/database/importers/v1/__init__.py
@@ -18,7 +18,6 @@
from typing import Any
from marshmallow import Schema
-from sqlalchemy.orm import Session
from superset.commands.database.exceptions import DatabaseImportError
from superset.commands.database.importers.v1.utils import import_database
diff --git a/superset/commands/database/update.py b/superset/commands/database/update.py
index 5575d674a8..b63e91c176 100644
--- a/superset/commands/database/update.py
+++ b/superset/commands/database/update.py
@@ -18,7 +18,6 @@ import logging
from typing import Any, Optional
from flask_appbuilder.models.sqla import Model
-from flask_babel import gettext as _
from marshmallow import ValidationError
from superset import is_feature_enabled
diff --git a/superset/commands/dataset/importers/v1/__init__.py b/superset/commands/dataset/importers/v1/__init__.py
index 29f850258c..8218bc8592 100644
--- a/superset/commands/dataset/importers/v1/__init__.py
+++ b/superset/commands/dataset/importers/v1/__init__.py
@@ -18,7 +18,6 @@
from typing import Any
from marshmallow import Schema
-from sqlalchemy.orm import Session
from superset.commands.database.importers.v1.utils import import_database
from superset.commands.dataset.exceptions import DatasetImportError
diff --git a/superset/commands/importers/v1/__init__.py b/superset/commands/importers/v1/__init__.py
index 8d90875fd3..1c69d0521c 100644
--- a/superset/commands/importers/v1/__init__.py
+++ b/superset/commands/importers/v1/__init__.py
@@ -16,9 +16,8 @@
# under the License.
from typing import Any, Optional
-from marshmallow import Schema, validate
+from marshmallow import Schema
from marshmallow.exceptions import ValidationError
-from sqlalchemy.orm import Session
from superset import db
from superset.commands.base import BaseCommand
@@ -26,12 +25,9 @@ from superset.commands.exceptions import CommandException, CommandInvalidError
from superset.commands.importers.v1.utils import (
load_configs,
load_metadata,
- load_yaml,
- METADATA_FILE_NAME,
validate_metadata_type,
)
from superset.daos.base import BaseDAO
-from superset.models.core import Database
class ImportModelsCommand(BaseCommand):
diff --git a/superset/commands/query/importers/v1/__init__.py b/superset/commands/query/importers/v1/__init__.py
index f251759c38..b50ef53db6 100644
--- a/superset/commands/query/importers/v1/__init__.py
+++ b/superset/commands/query/importers/v1/__init__.py
@@ -18,13 +18,11 @@
from typing import Any
from marshmallow import Schema
-from sqlalchemy.orm import Session
from superset.commands.database.importers.v1.utils import import_database
from superset.commands.importers.v1 import ImportModelsCommand
from superset.commands.query.exceptions import SavedQueryImportError
from superset.commands.query.importers.v1.utils import import_saved_query
-from superset.connectors.sqla.models import SqlaTable
from superset.daos.query import SavedQueryDAO
from superset.databases.schemas import ImportV1DatabaseSchema
from superset.queries.saved_queries.schemas import ImportV1SavedQuerySchema
diff --git a/superset/connectors/sqla/__init__.py b/superset/connectors/sqla/__init__.py
index ad52fc6d8b..13a83393a9 100644
--- a/superset/connectors/sqla/__init__.py
+++ b/superset/connectors/sqla/__init__.py
@@ -14,4 +14,3 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-from . import models, views
diff --git a/superset/connectors/sqla/models.py b/superset/connectors/sqla/models.py
index 208487299a..d77aaabf81 100644
--- a/superset/connectors/sqla/models.py
+++ b/superset/connectors/sqla/models.py
@@ -1289,10 +1289,10 @@ class SqlaTable(
@property
def dttm_cols(self) -> list[str]:
- l = [c.column_name for c in self.columns if c.is_dttm]
- if self.main_dttm_col and self.main_dttm_col not in l:
- l.append(self.main_dttm_col)
- return l
+ columns_with_dttm = [c.column_name for c in self.columns if c.is_dttm]
+ if self.main_dttm_col and self.main_dttm_col not in columns_with_dttm:
+ columns_with_dttm.append(self.main_dttm_col)
+ return columns_with_dttm
@property
def num_cols(self) -> list[str]:
diff --git a/superset/daos/chart.py b/superset/daos/chart.py
index eb8b3e809e..844b36b6b3 100644
--- a/superset/daos/chart.py
+++ b/superset/daos/chart.py
@@ -28,7 +28,7 @@ from superset.models.slice import Slice
from superset.utils.core import get_user_id
if TYPE_CHECKING:
- from superset.connectors.sqla.models import BaseDatasource
+ pass
logger = logging.getLogger(__name__)
diff --git a/superset/daos/dataset.py b/superset/daos/dataset.py
index 4647e02ce6..23b46e3329 100644
--- a/superset/daos/dataset.py
+++ b/superset/daos/dataset.py
@@ -245,7 +245,7 @@ class DatasetDAO(BaseDAO[SqlaTable]):
[
{**properties, "table_id": model.id}
for properties in property_columns
- if not "id" in properties
+ if "id" not in properties
],
)
@@ -297,7 +297,7 @@ class DatasetDAO(BaseDAO[SqlaTable]):
[
{**properties, "table_id": model.id}
for properties in property_metrics
- if not "id" in properties
+ if "id" not in properties
],
)
diff --git a/superset/db_engine_specs/duckdb.py b/superset/db_engine_specs/duckdb.py
index 56539d6652..89c45fb572 100644
--- a/superset/db_engine_specs/duckdb.py
+++ b/superset/db_engine_specs/duckdb.py
@@ -23,7 +23,7 @@ from typing import Any, TYPE_CHECKING, TypedDict
from apispec import APISpec
from apispec.ext.marshmallow import MarshmallowPlugin
-from flask_babel import gettext as __, lazy_gettext as _
+from flask_babel import gettext as __
from marshmallow import fields, Schema
from sqlalchemy import types
from sqlalchemy.engine.reflection import Inspector
diff --git a/superset/db_engine_specs/hive.py b/superset/db_engine_specs/hive.py
index 2655ed6c9a..618059fe05 100644
--- a/superset/db_engine_specs/hive.py
+++ b/superset/db_engine_specs/hive.py
@@ -50,8 +50,6 @@ from superset.superset_typing import ResultSetColumnType
if TYPE_CHECKING:
# prevent circular imports
- from pyhive.hive import Cursor
- from TCLIService.ttypes import TFetchOrientation
from superset.models.core import Database
@@ -392,8 +390,8 @@ class HiveEngineSpec(PrestoEngineSpec):
# Wait for job id before logging things out
# this allows for prefixing all log lines and becoming
# searchable in something like Kibana
- for l in log_lines[last_log_line:]:
- logger.info("Query %s: [%s] %s", str(query_id), str(job_id), l)
+ for log in log_lines[last_log_line:]:
+ logger.info("Query %s: [%s] %s", str(query_id), str(job_id), log)
last_log_line = len(log_lines)
if needs_commit:
db.session.commit()
diff --git a/superset/db_engine_specs/ocient.py b/superset/db_engine_specs/ocient.py
index 77c906fe77..34ab672404 100644
--- a/superset/db_engine_specs/ocient.py
+++ b/superset/db_engine_specs/ocient.py
@@ -19,7 +19,7 @@ import contextlib
import re
import threading
from re import Pattern
-from typing import Any, Callable, List, NamedTuple, Optional
+from typing import Any, Callable, NamedTuple, Optional
from flask_babel import gettext as __
from sqlalchemy.engine.reflection import Inspector
@@ -204,7 +204,7 @@ try:
TypeCodes.ST_LINESTRING: _linestring_to_geo_json,
TypeCodes.ST_POLYGON: _polygon_to_geo_json,
}
-except ImportError as e:
+except ImportError:
_sanitized_ocient_type_codes = {}
diff --git a/superset/db_engine_specs/presto.py b/superset/db_engine_specs/presto.py
index a8143c87ed..2d902a6159 100644
--- a/superset/db_engine_specs/presto.py
+++ b/superset/db_engine_specs/presto.py
@@ -447,10 +447,10 @@ class PrestoBaseEngineSpec(BaseEngineSpec, metaclass=ABCMeta):
limit_clause = f"LIMIT {limit}" if limit else ""
order_by_clause = ""
if order_by:
- l = []
+ order_clauses = []
for field, desc in order_by:
- l.append(field + " DESC" if desc else "")
- order_by_clause = "ORDER BY " + ", ".join(l)
+ order_clauses.append(field + " DESC" if desc else "")
+ order_by_clause = "ORDER BY " + ", ".join(order_clauses)
where_clause = ""
if filters:
diff --git a/superset/examples/data_loading.py b/superset/examples/data_loading.py
index 7b79adfcf4..a835ec14e8 100644
--- a/superset/examples/data_loading.py
+++ b/superset/examples/data_loading.py
@@ -15,21 +15,3 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=unused-import
-from .bart_lines import load_bart_lines
-from .big_data import load_big_data
-from .birth_names import load_birth_names
-from .country_map import load_country_map_data
-from .css_templates import load_css_templates
-from .deck import load_deck_dash
-from .energy import load_energy
-from .flights import load_flights
-from .long_lat import load_long_lat_data
-from .misc_dashboard import load_misc_dashboard
-from .multiformat_time_series import load_multiformat_time_series
-from .paris import load_paris_iris_geojson
-from .random_time_series import load_random_time_series_data
-from .sf_population_polygons import load_sf_population_polygons
-from .supported_charts_dashboard import load_supported_charts_dashboard
-from .tabbed_dashboard import load_tabbed_dashboard
-from .utils import load_examples_from_configs
-from .world_bank import load_world_bank_health_n_pop
diff --git a/superset/models/__init__.py b/superset/models/__init__.py
index 067d6ae831..13a83393a9 100644
--- a/superset/models/__init__.py
+++ b/superset/models/__init__.py
@@ -14,4 +14,3 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-from . import core, dynamic_plugins, sql_lab, user_attributes
diff --git a/superset/reports/notifications/__init__.py b/superset/reports/notifications/__init__.py
index b9fff48cf7..d804070a27 100644
--- a/superset/reports/notifications/__init__.py
+++ b/superset/reports/notifications/__init__.py
@@ -16,8 +16,6 @@
# under the License.
from superset.reports.models import ReportRecipients
from superset.reports.notifications.base import BaseNotification, NotificationContent
-from superset.reports.notifications.email import EmailNotification
-from superset.reports.notifications.slack import SlackNotification
def create_notification(
diff --git a/superset/row_level_security/api.py b/superset/row_level_security/api.py
index fc505e724f..86956683cb 100644
--- a/superset/row_level_security/api.py
+++ b/superset/row_level_security/api.py
@@ -299,7 +299,7 @@ class RLSRestApi(BaseSupersetModelRestApi):
exc_info=True,
)
return self.response_422(message=str(ex))
- except RLSRuleNotFoundError as ex:
+ except RLSRuleNotFoundError:
return self.response_404()
@expose("/", methods=("DELETE",))
diff --git a/superset/sql_validators/__init__.py b/superset/sql_validators/__init__.py
index ad048a86a5..8a8cf45aae 100644
--- a/superset/sql_validators/__init__.py
+++ b/superset/sql_validators/__init__.py
@@ -17,7 +17,6 @@
from typing import Optional
from . import base, postgres, presto_db
-from .base import SQLValidationAnnotation
def get_validator_by_name(name: str) -> Optional[type[base.BaseSQLValidator]]:
diff --git a/superset/sqllab/execution_context_convertor.py b/superset/sqllab/execution_context_convertor.py
index a1e7a86d0a..587e027555 100644
--- a/superset/sqllab/execution_context_convertor.py
+++ b/superset/sqllab/execution_context_convertor.py
@@ -28,8 +28,6 @@ from superset.sqllab.utils import apply_display_max_row_configuration_if_require
logger = logging.getLogger(__name__)
if TYPE_CHECKING:
- from superset.models.sql_lab import Query
- from superset.sqllab.sql_json_executer import SqlResults
from superset.sqllab.sqllab_execution_context import SqlJsonExecutionContext
diff --git a/superset/tasks/celery_app.py b/superset/tasks/celery_app.py
index e9ab10c050..85b966530c 100644
--- a/superset/tasks/celery_app.py
+++ b/superset/tasks/celery_app.py
@@ -32,7 +32,6 @@ flask_app = create_app()
# Need to import late, as the celery_app will have been setup by "create_app()"
# pylint: disable=wrong-import-position, unused-import
-from . import cache, scheduler # isort:skip
# Export the celery app globally for Celery (as run on the cmd line) to find
app = celery_app
diff --git a/superset/utils/log.py b/superset/utils/log.py
index cb5343470d..65355c175b 100644
--- a/superset/utils/log.py
+++ b/superset/utils/log.py
@@ -35,7 +35,7 @@ from superset.extensions import stats_logger_manager
from superset.utils.core import get_user_id, LoggerLevel, to_int
if TYPE_CHECKING:
- from superset.stats_logger import BaseStatsLogger
+ pass
logger = logging.getLogger(__name__)
diff --git a/superset/views/__init__.py b/superset/views/__init__.py
index 838e92aca2..13a83393a9 100644
--- a/superset/views/__init__.py
+++ b/superset/views/__init__.py
@@ -14,15 +14,3 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-from . import (
- alerts,
- api,
- base,
- core,
- css_templates,
- dynamic_plugins,
- health,
- sql_lab,
- tags,
-)
-from .log import api as log_api, views
diff --git a/superset/viz.py b/superset/viz.py
index 447b36d53d..78e71a839d 100644
--- a/superset/viz.py
+++ b/superset/viz.py
@@ -83,7 +83,6 @@ from superset.utils.date_parser import get_since_until, parse_past_timedelta
from superset.utils.hashing import md5_sha_from_str
if TYPE_CHECKING:
- from superset.common.query_context_factory import QueryContextFactory
from superset.connectors.sqla.models import BaseDatasource
config = app.config