Skip to content

Commit

Permalink
run black
Browse files Browse the repository at this point in the history
  • Loading branch information
eschutho committed Nov 15, 2021
1 parent 42027f1 commit 8604cad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 40 deletions.
14 changes: 3 additions & 11 deletions superset/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
40 changes: 11 additions & 29 deletions superset/utils/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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(
Expand All @@ -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

0 comments on commit 8604cad

Please sign in to comment.