Skip to content

Commit

Permalink
Automatically detect if non-lazy logging interpolation is used (#24910)
Browse files Browse the repository at this point in the history
We used to have pylint check that was preventing it but since
we have no pylint, we need to do some intelligent guessing
based on AST of the python code.
  • Loading branch information
potiuk committed Jul 8, 2022
1 parent bcf2c41 commit acaa063
Show file tree
Hide file tree
Showing 10 changed files with 208 additions and 118 deletions.
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,14 @@ repos:
pass_filenames: true
files: ^docs/apache-airflow-providers-[^/]*/index\.rst$
additional_dependencies: ['rich>=12.4.4', 'pyyaml']
- id: check-lazy-logging
name: Check that all logging methods are lazy
entry: ./scripts/ci/pre_commit/pre_commit_check_lazy_logging.py
language: python
pass_filenames: true
files: \.py$
exclude: ^airflow/_vendor/
additional_dependencies: ['rich>=12.4.4', 'astor']
- id: create-missing-init-py-files-tests
name: Create missing init.py files in tests
entry: ./scripts/ci/pre_commit/pre_commit_check_init_in_tests.py
Expand Down
2 changes: 2 additions & 0 deletions STATIC_CODE_CHECKS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ require Breeze Docker image to be build locally.
+--------------------------------------------------------+------------------------------------------------------------------+---------+
| check-integrations-are-consistent | Check if integration list is consistent in various places | |
+--------------------------------------------------------+------------------------------------------------------------------+---------+
| check-lazy-logging | Check that all logging methods are lazy | |
+--------------------------------------------------------+------------------------------------------------------------------+---------+
| check-merge-conflict | Check that merge conflicts are not being committed | |
+--------------------------------------------------------+------------------------------------------------------------------+---------+
| check-newsfragments-are-valid | Check newsfragments are valid | |
Expand Down
6 changes: 3 additions & 3 deletions airflow/providers/databricks/operators/databricks.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ def _handle_deferrable_databricks_operator_execution(operator, hook, log, contex
"""
if operator.do_xcom_push and context is not None:
context['ti'].xcom_push(key=XCOM_RUN_ID_KEY, value=operator.run_id)
log.info(f'Run submitted with run_id: {operator.run_id}')
log.info('Run submitted with run_id: %s', operator.run_id)

run_page_url = hook.get_run_page_url(operator.run_id)
if operator.do_xcom_push and context is not None:
context['ti'].xcom_push(key=XCOM_RUN_PAGE_URL_KEY, value=run_page_url)
log.info(f'View run status, Spark UI, and logs at {run_page_url}')
log.info('View run status, Spark UI, and logs at %s', run_page_url)

if operator.wait_for_termination:
operator.defer(
Expand All @@ -107,7 +107,7 @@ def _handle_deferrable_databricks_operator_completion(event: dict, log: Logger)
validate_trigger_event(event)
run_state = RunState.from_json(event['run_state'])
run_page_url = event['run_page_url']
log.info(f'View run status, Spark UI, and logs at {run_page_url}')
log.info('View run status, Spark UI, and logs at %s', run_page_url)

if run_state.is_successful:
log.info('Job run completed successfully.')
Expand Down
2 changes: 1 addition & 1 deletion airflow/providers/google/cloud/operators/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -2152,7 +2152,7 @@ def execute(self, context: Any):
)

try:
self.log.info(f"Executing: {self.configuration}")
self.log.info("Executing: %s'", self.configuration)
job = self._submit_job(hook, job_id)
self._handle_job_error(job)
except Conflict:
Expand Down
4 changes: 2 additions & 2 deletions airflow/providers/sftp/hooks/sftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def create_directory(self, path: str, mode: int = 777) -> None:
"""
conn = self.get_conn()
if self.isdir(path):
self.log.info(f"{path} already exists")
self.log.info("%s already exists", path)
return
elif self.isfile(path):
raise AirflowException(f"{path} already exists and is a file")
Expand All @@ -211,7 +211,7 @@ def create_directory(self, path: str, mode: int = 777) -> None:
if dirname and not self.isdir(dirname):
self.create_directory(dirname, mode)
if basename:
self.log.info(f"Creating {path}")
self.log.info("Creating %s", path)
conn.mkdir(path, mode=mode)

def delete_directory(self, path: str) -> None:
Expand Down
2 changes: 1 addition & 1 deletion airflow/providers/sftp/sensors/sftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(

def poke(self, context: 'Context') -> bool:
self.hook = SFTPHook(self.sftp_conn_id)
self.log.info(f"Poking for {self.path}, with pattern {self.file_pattern}")
self.log.info("Poking for %s, with pattern %s", self.path, self.file_pattern)

if self.file_pattern:
file_from_pattern = self.hook.get_file_by_pattern(self.path, self.file_pattern)
Expand Down
1 change: 1 addition & 0 deletions dev/breeze/src/airflow_breeze/pre_commit_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
'check-hooks-apply',
'check-incorrect-use-of-LoggingMixin',
'check-integrations-are-consistent',
'check-lazy-logging',
'check-merge-conflict',
'check-newsfragments-are-valid',
'check-no-providers-in-core-examples',
Expand Down
2 changes: 1 addition & 1 deletion images/breeze/output-commands-hash.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ self-upgrade:b5437c0a1a91533a11ee9d0a9692369c
setup-autocomplete:355b72dee171c2fcba46fc90ac7c97b0
shell:4680295fdd8a276d51518d29360c365c
start-airflow:92cf775a952439a32d409cd2536da507
static-checks:bc6b9a121ea38404ac5f28e727146b90
static-checks:8b4c0a3891e1d65ddf832ec4f5b71491
stop:8ebd8a42f1003495d37b884de5ac7ce6
tests:e39111ecbd33a65ababb3cbfbac2b069
verify-image:a6b3c70957aea96a5d4d261f23359a2d
Expand Down
Loading

0 comments on commit acaa063

Please sign in to comment.
  翻译: