Skip to content

Commit

Permalink
Remove outdated compat imports/code from providers (#28507)
Browse files Browse the repository at this point in the history
  • Loading branch information
Taragolis committed Dec 21, 2022
1 parent 020c164 commit 38e40c6
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 66 deletions.
15 changes: 7 additions & 8 deletions airflow/providers/amazon/aws/secrets/secrets_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from urllib.parse import unquote

from airflow.compat.functools import cached_property
from airflow.providers.amazon.aws.utils import get_airflow_version, trim_none_values
from airflow.providers.amazon.aws.utils import trim_none_values
from airflow.secrets import BaseSecretsBackend
from airflow.utils.log.logging_mixin import LoggingMixin

Expand Down Expand Up @@ -254,13 +254,12 @@ def get_conn_uri(self, conn_id: str) -> str | None:
:param conn_id: the connection id
:return: deserialized Connection
"""
if get_airflow_version() >= (2, 3):
warnings.warn(
f"Method `{self.__class__.__name__}.get_conn_uri` is deprecated and will be removed "
"in a future release. Please use method `get_conn_value` instead.",
DeprecationWarning,
stacklevel=2,
)
warnings.warn(
f"Method `{self.__class__.__name__}.get_conn_uri` is deprecated and will be removed "
"in a future release. Please use method `get_conn_value` instead.",
DeprecationWarning,
stacklevel=2,
)
return self.get_conn_value(conn_id)

def get_variable(self, key: str) -> str | None:
Expand Down
29 changes: 0 additions & 29 deletions airflow/providers/cncf/kubernetes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,3 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from __future__ import annotations

import sys

if sys.version_info < (3, 7):
# This is needed because the Python Kubernetes client >= 12.0 contains a logging object, meaning that
# v1.Pod et al. are not pickleable on Python 3.6.

# Python 3.7 added this via https://bugs.python.org/issue30520 in 2017 -- but Python 3.6 doesn't have this
# method.

# This is duplicated/backported from airflow.logging_config in 2.2, but by having it here as well it means
# that we can update the version used in this provider and have it work for older versions
import copyreg
import logging

def _reduce_Logger(logger):
if logging.getLogger(logger.name) is not logger:
import pickle

raise pickle.PicklingError("logger cannot be pickled")
return logging.getLogger, (logger.name,)

def _reduce_RootLogger(logger):
return logging.getLogger, ()

if logging.Logger not in copyreg.dispatch_table:
copyreg.pickle(logging.Logger, _reduce_Logger)
copyreg.pickle(logging.RootLogger, _reduce_RootLogger)
7 changes: 1 addition & 6 deletions airflow/providers/microsoft/winrm/hooks/winrm.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@

from airflow.exceptions import AirflowException
from airflow.hooks.base import BaseHook

try:
from airflow.utils.platform import getuser
except ImportError:
from getpass import getuser # type: ignore[misc]

from airflow.utils.platform import getuser

# TODO: Fixme please - I have too complex implementation

Expand Down
10 changes: 1 addition & 9 deletions airflow/providers/presto/hooks/presto.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,7 @@
from airflow.configuration import conf
from airflow.models import Connection
from airflow.providers.common.sql.hooks.sql import DbApiHook
from airflow.utils.operator_helpers import AIRFLOW_VAR_NAME_FORMAT_MAPPING

try:
from airflow.utils.operator_helpers import DEFAULT_FORMAT_PREFIX
except ImportError:
# This is from airflow.utils.operator_helpers,
# For the sake of provider backward compatibility, this is hardcoded if import fails
# https://github.com/apache/airflow/pull/22416#issuecomment-1075531290
DEFAULT_FORMAT_PREFIX = "airflow.ctx."
from airflow.utils.operator_helpers import AIRFLOW_VAR_NAME_FORMAT_MAPPING, DEFAULT_FORMAT_PREFIX


def generate_presto_client_info() -> str:
Expand Down
6 changes: 1 addition & 5 deletions airflow/providers/ssh/hooks/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@
from airflow.compat.functools import cached_property
from airflow.exceptions import AirflowException
from airflow.hooks.base import BaseHook

try:
from airflow.utils.platform import getuser
except ImportError:
from getpass import getuser # type: ignore[misc]
from airflow.utils.platform import getuser

TIMEOUT_DEFAULT = 10

Expand Down
10 changes: 1 addition & 9 deletions airflow/providers/trino/hooks/trino.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,7 @@
from airflow.configuration import conf
from airflow.models import Connection
from airflow.providers.common.sql.hooks.sql import DbApiHook
from airflow.utils.operator_helpers import AIRFLOW_VAR_NAME_FORMAT_MAPPING

try:
from airflow.utils.operator_helpers import DEFAULT_FORMAT_PREFIX
except ImportError:
# This is from airflow.utils.operator_helpers,
# For the sake of provider backward compatibility, this is hardcoded if import fails
# https://github.com/apache/airflow/pull/22416#issuecomment-1075531290
DEFAULT_FORMAT_PREFIX = "airflow.ctx."
from airflow.utils.operator_helpers import AIRFLOW_VAR_NAME_FORMAT_MAPPING, DEFAULT_FORMAT_PREFIX


def generate_trino_client_info() -> str:
Expand Down

0 comments on commit 38e40c6

Please sign in to comment.