Skip to content

Commit

Permalink
Added D401 support to http, smtp and sftp provider (#37303)
Browse files Browse the repository at this point in the history
  • Loading branch information
guptarohit committed Feb 10, 2024
1 parent 2bc8e17 commit bb414f0
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 26 deletions.
2 changes: 1 addition & 1 deletion airflow/providers/http/operators/http.py
Expand Up @@ -233,7 +233,7 @@ def execute_complete(
self, context: Context, event: dict, paginated_responses: None | list[Response] = None
):
"""
Callback for when the trigger fires - returns immediately.
Execute callback when the trigger fires; returns immediately.
Relies on trigger to throw an exception, otherwise it assumes execution was successful.
"""
Expand Down
8 changes: 4 additions & 4 deletions airflow/providers/http/triggers/http.py
Expand Up @@ -71,7 +71,7 @@ def __init__(
self.extra_options = extra_options

def serialize(self) -> tuple[str, dict[str, Any]]:
"""Serializes HttpTrigger arguments and classpath."""
"""Serialize HttpTrigger arguments and classpath."""
return (
"airflow.providers.http.triggers.http.HttpTrigger",
{
Expand All @@ -86,7 +86,7 @@ def serialize(self) -> tuple[str, dict[str, Any]]:
)

async def run(self) -> AsyncIterator[TriggerEvent]:
"""Makes a series of asynchronous http calls via an http hook."""
"""Make a series of asynchronous http calls via a http hook."""
hook = HttpAsyncHook(
method=self.method,
http_conn_id=self.http_conn_id,
Expand Down Expand Up @@ -162,7 +162,7 @@ def __init__(
self.poke_interval = poke_interval

def serialize(self) -> tuple[str, dict[str, Any]]:
"""Serializes HttpTrigger arguments and classpath."""
"""Serialize HttpTrigger arguments and classpath."""
return (
"airflow.providers.http.triggers.http.HttpSensorTrigger",
{
Expand All @@ -176,7 +176,7 @@ def serialize(self) -> tuple[str, dict[str, Any]]:
)

async def run(self) -> AsyncIterator[TriggerEvent]:
"""Makes a series of asynchronous http calls via an http hook."""
"""Make a series of asynchronous http calls via an http hook."""
hook = self._get_async_hook()
while True:
try:
Expand Down
2 changes: 1 addition & 1 deletion airflow/providers/sftp/decorators/sensors/sftp.py
Expand Up @@ -59,7 +59,7 @@ def __init__(

def sftp_sensor_task(python_callable: Callable | None = None, **kwargs) -> TaskDecorator:
"""
Wraps a function into an Airflow operator.
Wrap a function into an Airflow operator.
Accepts kwargs for operator kwarg. Can be reused in a single DAG.
:param python_callable: Function to decorate
Expand Down
10 changes: 5 additions & 5 deletions airflow/providers/sftp/hooks/sftp.py
Expand Up @@ -117,7 +117,7 @@ def __init__(
super().__init__(*args, **kwargs)

def get_conn(self) -> paramiko.SFTPClient: # type: ignore[override]
"""Opens an SFTP connection to the remote host."""
"""Open an SFTP connection to the remote host."""
if self.conn is None:
# TODO: remove support for ssh_hook when it is removed from SFTPOperator
if self.ssh_hook is not None:
Expand All @@ -127,7 +127,7 @@ def get_conn(self) -> paramiko.SFTPClient: # type: ignore[override]
return self.conn

def close_conn(self) -> None:
"""Closes the SFTP connection."""
"""Close the SFTP connection."""
if self.conn is not None:
self.conn.close()
self.conn = None
Expand Down Expand Up @@ -516,7 +516,7 @@ async def _get_conn(self) -> asyncssh.SSHClientConnection:
return ssh_client_conn

async def list_directory(self, path: str = "") -> list[str] | None:
"""Returns a list of files on the SFTP server at the provided path."""
"""Return a list of files on the SFTP server at the provided path."""
ssh_conn = await self._get_conn()
sftp_client = await ssh_conn.start_sftp_client()
try:
Expand All @@ -526,7 +526,7 @@ async def list_directory(self, path: str = "") -> list[str] | None:
return None

async def read_directory(self, path: str = "") -> Sequence[asyncssh.sftp.SFTPName] | None:
"""Returns a list of files along with their attributes on the SFTP server at the provided path."""
"""Return a list of files along with their attributes on the SFTP server at the provided path."""
ssh_conn = await self._get_conn()
sftp_client = await ssh_conn.start_sftp_client()
try:
Expand All @@ -551,7 +551,7 @@ async def get_files_and_attrs_by_pattern(

async def get_mod_time(self, path: str) -> str:
"""
Makes SFTP async connection.
Make SFTP async connection.
Looks for last modified time in the specific file path and returns last modification time for
the file path.
Expand Down
2 changes: 1 addition & 1 deletion airflow/providers/sftp/operators/sftp.py
Expand Up @@ -194,7 +194,7 @@ def execute(self, context: Any) -> str | list[str] | None:

def get_openlineage_facets_on_start(self):
"""
Returns OpenLineage datasets.
Return OpenLineage datasets.
Dataset will have the following structure:
input: file://<local_host>/path
Expand Down
2 changes: 1 addition & 1 deletion airflow/providers/sftp/sensors/sftp.py
Expand Up @@ -155,7 +155,7 @@ def execute(self, context: Context) -> Any:

def execute_complete(self, context: dict[str, Any], event: Any = None) -> None:
"""
Callback for when the trigger fires - returns immediately.
Execute callback when the trigger fires; returns immediately.
Relies on trigger to throw an exception, otherwise it assumes execution was
successful.
Expand Down
4 changes: 2 additions & 2 deletions airflow/providers/sftp/triggers/sftp.py
Expand Up @@ -61,7 +61,7 @@ def __init__(
self.poke_interval = poke_interval

def serialize(self) -> tuple[str, dict[str, Any]]:
"""Serializes SFTPTrigger arguments and classpath."""
"""Serialize SFTPTrigger arguments and classpath."""
return (
"airflow.providers.sftp.triggers.sftp.SFTPTrigger",
{
Expand All @@ -75,7 +75,7 @@ def serialize(self) -> tuple[str, dict[str, Any]]:

async def run(self) -> AsyncIterator[TriggerEvent]:
"""
Makes a series of asynchronous calls to sftp servers via async sftp hook. It yields a Trigger.
Make a series of asynchronous calls to sftp servers via async sftp hook. It yields a Trigger.
- If file matching file pattern exists at the specified path return it,
- If file pattern was not provided, it looks directly into the specific path which was provided.
Expand Down
6 changes: 3 additions & 3 deletions airflow/providers/smtp/hooks/smtp.py
Expand Up @@ -136,7 +136,7 @@ def _build_client(self) -> smtplib.SMTP_SSL | smtplib.SMTP:

@classmethod
def get_connection_form_widgets(cls) -> dict[str, Any]:
"""Returns connection widgets to add to connection form."""
"""Return connection widgets to add to connection form."""
from flask_appbuilder.fieldwidgets import BS3TextFieldWidget
from flask_babel import lazy_gettext
from wtforms import BooleanField, IntegerField, StringField
Expand Down Expand Up @@ -308,7 +308,7 @@ def _build_mime_message(

def _get_email_address_list(self, addresses: str | Iterable[str]) -> list[str]:
"""
Returns a list of email addresses from the provided input.
Return a list of email addresses from the provided input.
:param addresses: A string or iterable of strings containing email addresses.
:return: A list of email addresses.
Expand Down Expand Up @@ -380,7 +380,7 @@ def use_ssl(self) -> bool:

@classmethod
def get_ui_field_behaviour(cls) -> dict[str, Any]:
"""Returns custom field behaviour."""
"""Return custom field behaviour."""
return {
"hidden_fields": ["schema", "extra"],
"relabeling": {},
Expand Down
8 changes: 0 additions & 8 deletions pyproject.toml
Expand Up @@ -1492,8 +1492,6 @@ combine-as-imports = true
"airflow/providers/google/suite/hooks/sheets.py" = ["D401"]
"airflow/providers/hashicorp/_internal_client/vault_client.py" = ["D401"]
"airflow/providers/hashicorp/hooks/vault.py" = ["D401"]
"airflow/providers/http/operators/http.py" = ["D401"]
"airflow/providers/http/triggers/http.py" = ["D401"]
"airflow/providers/imap/hooks/imap.py" = ["D401"]
"airflow/providers/microsoft/azure/hooks/adx.py" = ["D401"]
"airflow/providers/microsoft/azure/hooks/asb.py" = ["D401"]
Expand Down Expand Up @@ -1542,15 +1540,9 @@ combine-as-imports = true
"airflow/providers/samba/hooks/samba.py" = ["D401"]
"airflow/providers/samba/transfers/gcs_to_samba.py" = ["D401"]
"airflow/providers/segment/hooks/segment.py" = ["D401"]
"airflow/providers/sftp/decorators/sensors/sftp.py" = ["D401"]
"airflow/providers/sftp/hooks/sftp.py" = ["D401"]
"airflow/providers/sftp/operators/sftp.py" = ["D401"]
"airflow/providers/sftp/sensors/sftp.py" = ["D401"]
"airflow/providers/sftp/triggers/sftp.py" = ["D401"]
"airflow/providers/slack/hooks/slack.py" = ["D401"]
"airflow/providers/slack/hooks/slack_webhook.py" = ["D401"]
"airflow/providers/slack/operators/slack.py" = ["D401"]
"airflow/providers/smtp/hooks/smtp.py" = ["D401"]
"airflow/providers/tableau/hooks/tableau.py" = ["D401"]
"airflow/providers/tableau/operators/tableau.py" = ["D401"]
"airflow/providers/telegram/hooks/telegram.py" = ["D401"]
Expand Down

0 comments on commit bb414f0

Please sign in to comment.