From 84f0c9ea34e629e382be7af807de40108f8ad05d Mon Sep 17 00:00:00 2001 From: Jennifer Melot Date: Sat, 10 Feb 2024 17:29:07 -0500 Subject: [PATCH] Follow D401 style in openlineage, slack, and tableau providers (#37312) * Follow D401 style in openlineage provider * Follow D401 style in slack and tableau providers GitOrigin-RevId: 326f9789cd0b255956be0b547f0463da44e6439f --- airflow/providers/openlineage/plugins/adapter.py | 6 +++--- airflow/providers/openlineage/sqlparser.py | 8 ++++---- airflow/providers/openlineage/utils/sql.py | 4 ++-- airflow/providers/slack/hooks/slack.py | 10 +++++----- airflow/providers/slack/hooks/slack_webhook.py | 12 ++++++------ airflow/providers/slack/operators/slack.py | 4 ++-- airflow/providers/tableau/hooks/tableau.py | 5 ++++- airflow/providers/tableau/operators/tableau.py | 2 +- pyproject.toml | 8 -------- 9 files changed, 27 insertions(+), 32 deletions(-) diff --git a/airflow/providers/openlineage/plugins/adapter.py b/airflow/providers/openlineage/plugins/adapter.py index 6f16b017067..e2ee8a26950 100644 --- a/airflow/providers/openlineage/plugins/adapter.py +++ b/airflow/providers/openlineage/plugins/adapter.py @@ -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 @@ -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 @@ -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 diff --git a/airflow/providers/openlineage/sqlparser.py b/airflow/providers/openlineage/sqlparser.py index d54c19dbc85..c27dedc53c5 100644 --- a/airflow/providers/openlineage/sqlparser.py +++ b/airflow/providers/openlineage/sqlparser.py @@ -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: @@ -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 @@ -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, @@ -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. diff --git a/airflow/providers/openlineage/utils/sql.py b/airflow/providers/openlineage/utils/sql.py index da08fa68d49..f959745b936 100644 --- a/airflow/providers/openlineage/utils/sql.py +++ b/airflow/providers/openlineage/utils/sql.py @@ -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 @@ -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 diff --git a/airflow/providers/slack/hooks/slack.py b/airflow/providers/slack/hooks/slack.py index adbfd0ab88d..f046a9c5fcd 100644 --- a/airflow/providers/slack/hooks/slack.py +++ b/airflow/providers/slack/hooks/slack.py @@ -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') @@ -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. @@ -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. @@ -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 @@ -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": { diff --git a/airflow/providers/slack/hooks/slack_webhook.py b/airflow/providers/slack/hooks/slack_webhook.py index fcf25e44aa4..9eb376227cd 100644 --- a/airflow/providers/slack/hooks/slack_webhook.py +++ b/airflow/providers/slack/hooks/slack_webhook.py @@ -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: @@ -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. @@ -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). @@ -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. @@ -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 @@ -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": { diff --git a/airflow/providers/slack/operators/slack.py b/airflow/providers/slack/operators/slack.py index 838786f332f..2fdafe36892 100644 --- a/airflow/providers/slack/operators/slack.py +++ b/airflow/providers/slack/operators/slack.py @@ -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 diff --git a/airflow/providers/tableau/hooks/tableau.py b/airflow/providers/tableau/hooks/tableau.py index 723eb0c02f1..e679133a156 100644 --- a/airflow/providers/tableau/hooks/tableau.py +++ b/airflow/providers/tableau/hooks/tableau.py @@ -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"], diff --git a/airflow/providers/tableau/operators/tableau.py b/airflow/providers/tableau/operators/tableau.py index 5eb8a92a3ec..e4a447a6545 100644 --- a/airflow/providers/tableau/operators/tableau.py +++ b/airflow/providers/tableau/operators/tableau.py @@ -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. diff --git a/pyproject.toml b/pyproject.toml index f8e949739e4..3f81303bb10 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"] @@ -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"]