From 8604cad704e1136771da80d90acd87f90df046b4 Mon Sep 17 00:00:00 2001 From: Elizabeth Thompson Date: Mon, 15 Nov 2021 09:59:36 -0800 Subject: [PATCH] run black --- superset/config.py | 14 +++---------- superset/utils/webdriver.py | 40 ++++++++++--------------------------- 2 files changed, 14 insertions(+), 40 deletions(-) diff --git a/superset/config.py b/superset/config.py index 047afec32e20..05d7b8ecd706 100644 --- a/superset/config.py +++ b/superset/config.py @@ -848,8 +848,6 @@ class CeleryConfig: # pylint: disable=too-few-public-methods CSV_TO_HIVE_UPLOAD_DIRECTORY = "EXTERNAL_HIVE_TABLES/" # Function that creates upload directory dynamically based on the # database used, user and schema provided. - - def CSV_TO_HIVE_UPLOAD_DIRECTORY_FUNC( # pylint: disable=invalid-name database: "Database", user: "models.User", # pylint: disable=unused-argument @@ -953,9 +951,7 @@ def CSV_TO_HIVE_UPLOAD_DIRECTORY_FUNC( # pylint: disable=invalid-name # Provide a callable that receives a tracking_url and returns another # URL. This is used to translate internal Hadoop job tracker URL # into a proxied one -def TRACKING_URL_TRANSFORMER(x): # pylint: disable=invalid-name - return x - +TRACKING_URL_TRANSFORMER = lambda x: x # Interval between consecutive polls when using Hive Engine HIVE_POLL_INTERVAL = int(timedelta(seconds=5).total_seconds()) @@ -1223,9 +1219,7 @@ def SQL_QUERY_MUTATOR( # pylint: disable=invalid-name,unused-argument # to allow mutating the object with this callback. # This can be used to set any properties of the object based on naming # conventions and such. You can find examples in the tests. -def SQLA_TABLE_MUTATOR(table): # pylint: disable=invalid-name - return table - +SQLA_TABLE_MUTATOR = lambda table: table # Global async query config options. # Requires GLOBAL_ASYNC_QUERIES feature flag to be enabled. @@ -1312,9 +1306,7 @@ def SQLA_TABLE_MUTATOR(table): # pylint: disable=invalid-name elif importlib.util.find_spec("superset_config") and not is_test(): try: import superset_config # pylint: disable=import-error - - # type: ignore # pylint: disable=import-error,wildcard-import,unused-wildcard-import - from superset_config import * + from superset_config import * # type: ignore # pylint: disable=import-error,wildcard-import,unused-wildcard-import print(f"Loaded your LOCAL configuration at [{superset_config.__file__}]") except Exception: diff --git a/superset/utils/webdriver.py b/superset/utils/webdriver.py index 02396810aac7..9cedc0f93452 100644 --- a/superset/utils/webdriver.py +++ b/superset/utils/webdriver.py @@ -51,40 +51,28 @@ class DashboardStandaloneMode(Enum): class WebDriverProxy: - def __init__( - self, - driver_type: str, - window: Optional[WindowSize] = None, - ): + def __init__(self, driver_type: str, window: Optional[WindowSize] = None): self._driver_type = driver_type self._window: WindowSize = window or (800, 600) self._screenshot_locate_wait = current_app.config["SCREENSHOT_LOCATE_WAIT"] self._screenshot_load_wait = current_app.config["SCREENSHOT_LOAD_WAIT"] def create(self) -> WebDriver: - pixel_density = current_app.config["WEBDRIVER_WINDOW"].get( - "pixel_density", 1) + pixel_density = current_app.config["WEBDRIVER_WINDOW"].get("pixel_density", 1) if self._driver_type == "firefox": driver_class = firefox.webdriver.WebDriver options = firefox.options.Options() profile = FirefoxProfile() - profile.set_preference( - "layout.css.devPixelsPerPx", - str(pixel_density), - ) - kwargs: Dict[Any, Any] = dict( - options=options, firefox_profile=profile) + profile.set_preference("layout.css.devPixelsPerPx", str(pixel_density)) + kwargs: Dict[Any, Any] = dict(options=options, firefox_profile=profile) elif self._driver_type == "chrome": driver_class = chrome.webdriver.WebDriver options = chrome.options.Options() - options.add_argument( - f"--force-device-scale-factor={pixel_density}") - options.add_argument( - f"--window-size={self._window[0]},{self._window[1]}") + options.add_argument(f"--force-device-scale-factor={pixel_density}") + options.add_argument(f"--window-size={self._window[0]},{self._window[1]}") kwargs = dict(options=options) else: - raise Exception( - f"Webdriver name ({self._driver_type}) not supported") + raise Exception(f"Webdriver name ({self._driver_type}) not supported") # Prepare args for the webdriver init # Add additional configured options @@ -117,10 +105,7 @@ def destroy(driver: WebDriver, tries: int = 2) -> None: pass def get_screenshot( - self, - url: str, - element_name: str, - user: "User", + self, url: str, element_name: str, user: "User" ) -> Optional[bytes]: params = {"standalone": DashboardStandaloneMode.REPORT.value} req = PreparedRequest() @@ -153,14 +138,12 @@ def get_screenshot( selenium_animation_wait = current_app.config[ "SCREENSHOT_SELENIUM_ANIMATION_WAIT" ] - logger.debug("Wait %i seconds for chart animation", - selenium_animation_wait) + logger.debug("Wait %i seconds for chart animation", selenium_animation_wait) sleep(selenium_animation_wait) logger.info("Taking a PNG screenshot of url %s", url) img = element.screenshot_as_png except TimeoutException: - logger.warning( - "Selenium timed out requesting url %s", url, exc_info=True) + logger.warning("Selenium timed out requesting url %s", url, exc_info=True) img = element.screenshot_as_png except StaleElementReferenceException: logger.error( @@ -171,6 +154,5 @@ def get_screenshot( except WebDriverException as ex: logger.error(ex, exc_info=True) finally: - self.destroy( - driver, current_app.config["SCREENSHOT_SELENIUM_RETRIES"]) + self.destroy(driver, current_app.config["SCREENSHOT_SELENIUM_RETRIES"]) return img