Skip to content

Commit

Permalink
Follow D401 style in openlineage, slack, and tableau providers (#37312)
Browse files Browse the repository at this point in the history
* Follow D401 style in openlineage provider

* Follow D401 style in slack and tableau providers

GitOrigin-RevId: 326f9789cd0b255956be0b547f0463da44e6439f
  • Loading branch information
jmelot authored and Cloud Composer Team committed Jul 19, 2024
1 parent d399b22 commit 84f0c9e
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 32 deletions.
6 changes: 3 additions & 3 deletions airflow/providers/openlineage/plugins/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def start_task(
run_facets: dict[str, BaseFacet] | None = None, # Custom run facets
):
"""
Emits openlineage event of type START.
Emit openlineage event of type START.
:param run_id: globally unique identifier of task in dag run
:param job_name: globally unique identifier of task in dag
Expand Down Expand Up @@ -202,7 +202,7 @@ def complete_task(
task: OperatorLineage,
):
"""
Emits openlineage event of type COMPLETE.
Emit openlineage event of type COMPLETE.
:param run_id: globally unique identifier of task in dag run
:param job_name: globally unique identifier of task between dags
Expand Down Expand Up @@ -239,7 +239,7 @@ def fail_task(
task: OperatorLineage,
):
"""
Emits openlineage event of type FAIL.
Emit openlineage event of type FAIL.
:param run_id: globally unique identifier of task in dag run
:param job_name: globally unique identifier of task between dags
Expand Down
8 changes: 4 additions & 4 deletions airflow/providers/openlineage/sqlparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def generate_openlineage_metadata_from_sql(
database: str | None = None,
sqlalchemy_engine: Engine | None = None,
) -> OperatorLineage:
"""Parses SQL statement(s) and generates OpenLineage metadata.
"""Parse SQL statement(s) and generate OpenLineage metadata.
Generated OpenLineage metadata contains:
Expand Down Expand Up @@ -271,7 +271,7 @@ def create_namespace(database_info: DatabaseInfo) -> str:

@classmethod
def normalize_sql(cls, sql: list[str] | str) -> str:
"""Makes sure to return a semicolon-separated SQL statements."""
"""Make sure to return a semicolon-separated SQL statement."""
return ";\n".join(stmt.rstrip(" ;\r\n") for stmt in cls.split_sql_string(sql))

@classmethod
Expand Down Expand Up @@ -309,7 +309,7 @@ def create_information_schema_query(
database: str | None = None,
sqlalchemy_engine: Engine | None = None,
) -> str:
"""Creates SELECT statement to query information schema table."""
"""Create SELECT statement to query information schema table."""
tables_hierarchy = cls._get_tables_hierarchy(
tables,
normalize_name=normalize_name,
Expand All @@ -333,7 +333,7 @@ def _get_tables_hierarchy(
is_cross_db: bool = False,
) -> TablesHierarchy:
"""
Creates a hierarchy of database -> schema -> table name.
Create a hierarchy of database -> schema -> table name.
This helps to create simpler information schema query grouped by
database and schema.
Expand Down
4 changes: 2 additions & 2 deletions airflow/providers/openlineage/utils/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def create_information_schema_query(
use_flat_cross_db_query: bool = False,
sqlalchemy_engine: Engine | None = None,
) -> str:
"""Creates query for getting table schemas from information schema."""
"""Create query for getting table schemas from information schema."""
metadata = MetaData(sqlalchemy_engine)
select_statements = []
# Don't iterate over tables hierarchy, just pass it to query single information schema table
Expand Down Expand Up @@ -201,7 +201,7 @@ def create_filter_clauses(
uppercase_names: bool = False,
) -> ClauseElement:
"""
Creates comprehensive filter clauses for all tables in one database.
Create comprehensive filter clauses for all tables in one database.
:param mapping: a nested dictionary of database, schema names and list of tables in each
:param information_schema_table: `sqlalchemy.Table` instance used to construct clauses
Expand Down
10 changes: 5 additions & 5 deletions airflow/providers/slack/hooks/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def _get_conn_params(self) -> dict[str, Any]:

def call(self, api_method: str, **kwargs) -> SlackResponse:
"""
Calls Slack WebClient `WebClient.api_call` with given arguments.
Call Slack WebClient `WebClient.api_call` with given arguments.
:param api_method: The target Slack API method. e.g. 'chat.postMessage'. Required.
:param http_verb: HTTP Verb. Optional (defaults to 'POST')
Expand Down Expand Up @@ -244,7 +244,7 @@ def send_file_v2(
initial_comment: str | None = None,
) -> SlackResponse:
"""
Sends one or more files to a Slack channel using the Slack SDK Client method `files_upload_v2`.
Send one or more files to a Slack channel using the Slack SDK Client method `files_upload_v2`.
:param channel_id: The ID of the channel to send the file to.
If omitting this parameter, then file will send to workspace.
Expand Down Expand Up @@ -329,7 +329,7 @@ def send_file_v1_to_v2(

def get_channel_id(self, channel_name: str) -> str:
"""
Retrieves a Slack channel id by a channel name.
Retrieve a Slack channel id by a channel name.
It continuously iterates over all Slack channels (public and private)
until it finds the desired channel name in addition cache results for further usage.
Expand Down Expand Up @@ -383,7 +383,7 @@ def test_connection(self):

@classmethod
def get_connection_form_widgets(cls) -> dict[str, Any]:
"""Returns dictionary of widgets to be added for the hook to handle extra values."""
"""Return dictionary of widgets to be added for the hook to handle extra values."""
from flask_appbuilder.fieldwidgets import BS3TextFieldWidget
from flask_babel import lazy_gettext
from wtforms import IntegerField, StringField
Expand Down Expand Up @@ -411,7 +411,7 @@ def get_connection_form_widgets(cls) -> dict[str, Any]:

@classmethod
def get_ui_field_behaviour(cls) -> dict[str, Any]:
"""Returns custom field behaviour."""
"""Return custom field behaviour."""
return {
"hidden_fields": ["login", "port", "host", "schema", "extra"],
"relabeling": {
Expand Down
12 changes: 6 additions & 6 deletions airflow/providers/slack/hooks/slack_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@


def check_webhook_response(func: Callable) -> Callable:
"""Function decorator that check WebhookResponse and raise an error if status code != 200."""
"""Check WebhookResponse and raise an error if status code != 200."""

@wraps(func)
def wrapper(*args, **kwargs) -> Callable:
Expand Down Expand Up @@ -175,7 +175,7 @@ def _get_conn_params(self) -> dict[str, Any]:
@check_webhook_response
def send_dict(self, body: dict[str, Any] | str, *, headers: dict[str, str] | None = None):
"""
Performs a Slack Incoming Webhook request with given JSON data block.
Perform a Slack Incoming Webhook request with given JSON data block.
:param body: JSON data structure, expected dict or JSON-string.
:param headers: Request headers for this request.
Expand Down Expand Up @@ -220,7 +220,7 @@ def send(
**kwargs,
):
"""
Performs a Slack Incoming Webhook request with given arguments.
Perform a Slack Incoming Webhook request with given arguments.
:param text: The text message
(even when having blocks, setting this as well is recommended as it works as fallback).
Expand Down Expand Up @@ -257,7 +257,7 @@ def send_text(
headers: dict[str, str] | None = None,
):
"""
Performs a Slack Incoming Webhook request with given text.
Perform a Slack Incoming Webhook request with given text.
:param text: The text message.
:param unfurl_links: Option to indicate whether text url should unfurl.
Expand All @@ -268,7 +268,7 @@ def send_text(

@classmethod
def get_connection_form_widgets(cls) -> dict[str, Any]:
"""Returns dictionary of widgets to be added for the hook to handle extra values."""
"""Return dictionary of widgets to be added for the hook to handle extra values."""
from flask_appbuilder.fieldwidgets import BS3TextFieldWidget
from flask_babel import lazy_gettext
from wtforms import IntegerField, StringField
Expand All @@ -291,7 +291,7 @@ def get_connection_form_widgets(cls) -> dict[str, Any]:

@classmethod
def get_ui_field_behaviour(cls) -> dict[str, Any]:
"""Returns custom field behaviour."""
"""Return custom field behaviour."""
return {
"hidden_fields": ["login", "port", "extra"],
"relabeling": {
Expand Down
4 changes: 2 additions & 2 deletions airflow/providers/slack/operators/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ def hook(self) -> SlackHook:
)

def construct_api_call_params(self) -> Any:
"""API call parameters used by the execute function.
"""Construct API call parameters used by the execute function.
Allows templating on the source fields of the ``api_call_params`` dict
Allow templating on the source fields of the ``api_call_params`` dict
before construction.
Child classes should override this. Each SlackAPIOperator child class is
Expand Down
5 changes: 4 additions & 1 deletion airflow/providers/tableau/hooks/tableau.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ def _auth_via_password(self) -> Auth.contextmgr:
category=AirflowProviderDeprecationWarning,
)
def _auth_via_token(self) -> Auth.contextmgr:
"""The method is deprecated. Please, use the authentication via password instead."""
"""Authenticate via personal access token.
This method is deprecated. Please, use the authentication via password instead.
"""
tableau_auth = PersonalAccessTokenAuth(
token_name=self.conn.extra_dejson["token_name"],
personal_access_token=self.conn.extra_dejson["personal_access_token"],
Expand Down
2 changes: 1 addition & 1 deletion airflow/providers/tableau/operators/tableau.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def __init__(

def execute(self, context: Context) -> str:
"""
Executes the Tableau API resource and pushes the job id or downloaded file URI to xcom.
Execute the Tableau API resource and push the job id or downloaded file URI to xcom.
:param context: The task context during execution.
:return: the id of the job that executes the extract refresh or downloaded file URI.
Expand Down
8 changes: 0 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1481,9 +1481,6 @@ combine-as-imports = true
"airflow/providers/mysql/transfers/s3_to_mysql.py" = ["D401"]
"airflow/providers/neo4j/hooks/neo4j.py" = ["D401"]
"airflow/providers/openfaas/hooks/openfaas.py" = ["D401"]
"airflow/providers/openlineage/plugins/adapter.py" = ["D401"]
"airflow/providers/openlineage/sqlparser.py" = ["D401"]
"airflow/providers/openlineage/utils/sql.py" = ["D401"]
"airflow/providers/opensearch/hooks/opensearch.py" = ["D401"]
"airflow/providers/opensearch/operators/opensearch.py" = ["D401"]
"airflow/providers/oracle/hooks/oracle.py" = ["D401"]
Expand All @@ -1499,11 +1496,6 @@ 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/slack/hooks/slack.py" = ["D401"]
"airflow/providers/slack/hooks/slack_webhook.py" = ["D401"]
"airflow/providers/slack/operators/slack.py" = ["D401"]
"airflow/providers/tableau/hooks/tableau.py" = ["D401"]
"airflow/providers/tableau/operators/tableau.py" = ["D401"]
"airflow/providers/telegram/hooks/telegram.py" = ["D401"]
"airflow/providers/telegram/operators/telegram.py" = ["D401"]
"airflow/providers/trino/hooks/trino.py" = ["D401"]
Expand Down

0 comments on commit 84f0c9e

Please sign in to comment.