Skip to content

Commit

Permalink
refactor(import): Remove meaningless underscore imports (#2375)
Browse files Browse the repository at this point in the history
tyty
Signed-off-by: Chi-Sheng Liu <[email protected]>
Signed-off-by: Jan Fiedler <[email protected]>
  • Loading branch information
MortalHappiness authored and fiedlerNr9 committed Jul 25, 2024
1 parent e99f994 commit 1b2d5c3
Show file tree
Hide file tree
Showing 30 changed files with 401 additions and 405 deletions.
66 changes: 33 additions & 33 deletions flytekit/bin/entrypoint.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import asyncio
import contextlib
import datetime as _datetime
import datetime
import inspect
import os
import pathlib
import signal
import subprocess
import tempfile
import traceback as _traceback
import traceback
from sys import exit
from typing import List, Optional

import click as _click
import click
from flyteidl.core import literals_pb2 as _literals_pb2

from flytekit.configuration import (
Expand Down Expand Up @@ -153,7 +153,7 @@ def _dispatch_execute(
# dispatch_execute) as recoverable system exceptions.
except Exception as e:
# Step 3c
exc_str = _traceback.format_exc()
exc_str = traceback.format_exc()
output_file_dict[_constants.ERROR_FILE_NAME] = _error_models.ErrorDocument(
_error_models.ContainerError(
"SYSTEM:Unknown",
Expand Down Expand Up @@ -249,7 +249,7 @@ def setup_execution(
domain=exe_domain,
name=exe_name,
),
execution_date=_datetime.datetime.now(_datetime.timezone.utc),
execution_date=datetime.datetime.now(datetime.timezone.utc),
stats=_get_stats(
cfg=StatsConfig.auto(),
# Stats metric path will be:
Expand Down Expand Up @@ -450,24 +450,24 @@ def normalize_inputs(
return raw_output_data_prefix, checkpoint_path, prev_checkpoint


@_click.group()
@click.group()
def _pass_through():
pass


@_pass_through.command("pyflyte-execute")
@_click.option("--inputs", required=True)
@_click.option("--output-prefix", required=True)
@_click.option("--raw-output-data-prefix", required=False)
@_click.option("--checkpoint-path", required=False)
@_click.option("--prev-checkpoint", required=False)
@_click.option("--test", is_flag=True)
@_click.option("--dynamic-addl-distro", required=False)
@_click.option("--dynamic-dest-dir", required=False)
@_click.option("--resolver", required=False)
@_click.argument(
@click.option("--inputs", required=True)
@click.option("--output-prefix", required=True)
@click.option("--raw-output-data-prefix", required=False)
@click.option("--checkpoint-path", required=False)
@click.option("--prev-checkpoint", required=False)
@click.option("--test", is_flag=True)
@click.option("--dynamic-addl-distro", required=False)
@click.option("--dynamic-dest-dir", required=False)
@click.option("--resolver", required=False)
@click.argument(
"resolver-args",
type=_click.UNPROCESSED,
type=click.UNPROCESSED,
nargs=-1,
)
def execute_task_cmd(
Expand All @@ -484,7 +484,7 @@ def execute_task_cmd(
):
logger.info(get_version_message())
# We get weird errors if there are no click echo messages at all, so emit an empty string so that unit tests pass.
_click.echo("")
click.echo("")
raw_output_data_prefix, checkpoint_path, prev_checkpoint = normalize_inputs(
raw_output_data_prefix, checkpoint_path, prev_checkpoint
)
Expand All @@ -510,9 +510,9 @@ def execute_task_cmd(


@_pass_through.command("pyflyte-fast-execute")
@_click.option("--additional-distribution", required=False)
@_click.option("--dest-dir", required=False)
@_click.argument("task-execute-cmd", nargs=-1, type=_click.UNPROCESSED)
@click.option("--additional-distribution", required=False)
@click.option("--dest-dir", required=False)
@click.argument("task-execute-cmd", nargs=-1, type=click.UNPROCESSED)
def fast_execute_task_cmd(additional_distribution: str, dest_dir: str, task_execute_cmd: List[str]):
"""
Downloads a compressed code distribution specified by additional-distribution and then calls the underlying
Expand Down Expand Up @@ -544,19 +544,19 @@ def handle_sigterm(signum, frame):


@_pass_through.command("pyflyte-map-execute")
@_click.option("--inputs", required=True)
@_click.option("--output-prefix", required=True)
@_click.option("--raw-output-data-prefix", required=False)
@_click.option("--max-concurrency", type=int, required=False)
@_click.option("--test", is_flag=True)
@_click.option("--dynamic-addl-distro", required=False)
@_click.option("--dynamic-dest-dir", required=False)
@_click.option("--resolver", required=True)
@_click.option("--checkpoint-path", required=False)
@_click.option("--prev-checkpoint", required=False)
@_click.argument(
@click.option("--inputs", required=True)
@click.option("--output-prefix", required=True)
@click.option("--raw-output-data-prefix", required=False)
@click.option("--max-concurrency", type=int, required=False)
@click.option("--test", is_flag=True)
@click.option("--dynamic-addl-distro", required=False)
@click.option("--dynamic-dest-dir", required=False)
@click.option("--resolver", required=True)
@click.option("--checkpoint-path", required=False)
@click.option("--prev-checkpoint", required=False)
@click.argument(
"resolver-args",
type=_click.UNPROCESSED,
type=click.UNPROCESSED,
nargs=-1,
)
def map_execute_task_cmd(
Expand Down
30 changes: 15 additions & 15 deletions flytekit/clients/auth/auth_client.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
from __future__ import annotations

import base64 as _base64
import hashlib as _hashlib
import base64
import hashlib
import http.server as _BaseHTTPServer
import logging
import multiprocessing
import os as _os
import re as _re
import os
import re
import typing
import urllib.parse as _urlparse
import webbrowser as _webbrowser
import webbrowser
from dataclasses import dataclass
from http import HTTPStatus as _StatusCodes
from multiprocessing import get_context
from urllib.parse import urlencode as _urlencode

import click
import requests as _requests
import requests

from .default_html import get_default_success_html
from .exceptions import AccessTokenNotFoundError
Expand All @@ -33,9 +33,9 @@ def _generate_code_verifier():
Adapted from https://github.com/openstack/deb-python-oauth2client/blob/master/oauth2client/_pkce.py.
:return str:
"""
code_verifier = _base64.urlsafe_b64encode(_os.urandom(_code_verifier_length)).decode(_utf_8)
code_verifier = base64.urlsafe_b64encode(os.urandom(_code_verifier_length)).decode(_utf_8)
# Eliminate invalid characters.
code_verifier = _re.sub(r"[^a-zA-Z0-9_\-.~]+", "", code_verifier)
code_verifier = re.sub(r"[^a-zA-Z0-9_\-.~]+", "", code_verifier)
if len(code_verifier) < 43:
raise ValueError("Verifier too short. number of bytes must be > 30.")
elif len(code_verifier) > 128:
Expand All @@ -44,9 +44,9 @@ def _generate_code_verifier():


def _generate_state_parameter():
state = _base64.urlsafe_b64encode(_os.urandom(_random_seed_length)).decode(_utf_8)
state = base64.urlsafe_b64encode(os.urandom(_random_seed_length)).decode(_utf_8)
# Eliminate invalid characters.
code_verifier = _re.sub("[^a-zA-Z0-9-_.,]+", "", state)
code_verifier = re.sub("[^a-zA-Z0-9-_.,]+", "", state)
return code_verifier


Expand All @@ -56,8 +56,8 @@ def _create_code_challenge(code_verifier):
:param str code_verifier: represents a code verifier generated by generate_code_verifier()
:return str: urlsafe base64-encoded sha256 hash digest
"""
code_challenge = _hashlib.sha256(code_verifier.encode(_utf_8)).digest()
code_challenge = _base64.urlsafe_b64encode(code_challenge).decode(_utf_8)
code_challenge = hashlib.sha256(code_verifier.encode(_utf_8)).digest()
code_challenge = base64.urlsafe_b64encode(code_challenge).decode(_utf_8)
# Eliminate invalid characters
code_challenge = code_challenge.replace("=", "")
return code_challenge
Expand Down Expand Up @@ -186,7 +186,7 @@ def __init__(
redirect_uri: typing.Optional[str] = None,
endpoint_metadata: typing.Optional[EndpointMetadata] = None,
verify: typing.Optional[typing.Union[bool, str]] = None,
session: typing.Optional[_requests.Session] = None,
session: typing.Optional[requests.Session] = None,
request_auth_code_params: typing.Optional[typing.Dict[str, str]] = None,
request_access_token_params: typing.Optional[typing.Dict[str, str]] = None,
refresh_access_token_params: typing.Optional[typing.Dict[str, str]] = None,
Expand Down Expand Up @@ -237,7 +237,7 @@ def __init__(
self._state = state
self._verify = verify
self._headers = {"content-type": "application/x-www-form-urlencoded"}
self._session = session or _requests.Session()
self._session = session or requests.Session()

self._request_auth_code_params = {
"client_id": client_id, # This must match the Client ID of the OAuth application.
Expand Down Expand Up @@ -283,7 +283,7 @@ def _request_authorization_code(self):
endpoint = _urlparse.urlunparse((scheme, netloc, path, None, query, None))
logging.debug(f"Requesting authorization code through {endpoint}")

success = _webbrowser.open_new_tab(endpoint)
success = webbrowser.open_new_tab(endpoint)
if not success:
click.secho(f"Please open the following link in your browser to authenticate: {endpoint}")

Expand Down
16 changes: 8 additions & 8 deletions flytekit/clients/auth/keyring.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import typing
from dataclasses import dataclass

import keyring as _keyring
import keyring
from keyring.errors import NoKeyringError, PasswordDeleteError


Expand Down Expand Up @@ -32,18 +32,18 @@ class KeyringStore:
def store(credentials: Credentials) -> Credentials:
try:
if credentials.refresh_token:
_keyring.set_password(
keyring.set_password(
credentials.for_endpoint,
KeyringStore._refresh_token_key,
credentials.refresh_token,
)
_keyring.set_password(
keyring.set_password(
credentials.for_endpoint,
KeyringStore._access_token_key,
credentials.access_token,
)
if credentials.id_token:
_keyring.set_password(
keyring.set_password(
credentials.for_endpoint,
KeyringStore._id_token_key,
credentials.id_token,
Expand All @@ -55,9 +55,9 @@ def store(credentials: Credentials) -> Credentials:
@staticmethod
def retrieve(for_endpoint: str) -> typing.Optional[Credentials]:
try:
refresh_token = _keyring.get_password(for_endpoint, KeyringStore._refresh_token_key)
access_token = _keyring.get_password(for_endpoint, KeyringStore._access_token_key)
id_token = _keyring.get_password(for_endpoint, KeyringStore._id_token_key)
refresh_token = keyring.get_password(for_endpoint, KeyringStore._refresh_token_key)
access_token = keyring.get_password(for_endpoint, KeyringStore._access_token_key)
id_token = keyring.get_password(for_endpoint, KeyringStore._id_token_key)
except NoKeyringError as e:
logging.debug(f"KeyRing not available, tokens will not be cached. Error: {e}")
return None
Expand All @@ -70,7 +70,7 @@ def retrieve(for_endpoint: str) -> typing.Optional[Credentials]:
def delete(for_endpoint: str):
def _delete_key(key):
try:
_keyring.delete_password(for_endpoint, key)
keyring.delete_password(for_endpoint, key)
except PasswordDeleteError as e:
logging.debug(f"Key {key} not found in key store, Ignoring. Error: {e}")
except NoKeyringError as e:
Expand Down
Loading

0 comments on commit 1b2d5c3

Please sign in to comment.