Skip to content

Commit

Permalink
Make warnings more visible (apache#12204)
Browse files Browse the repository at this point in the history
This PR proposes to use custom showwarning function that
provides users with better information about warnings using
rich library to highlight the warning.
  • Loading branch information
turbaszek authored Nov 9, 2020
1 parent badd890 commit cc12db7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ The text of each license is also included at licenses/LICENSE-[project].txt.
(MIT License) moment-strftime v0.5.0 (https://github.com/benjaminoakes/moment-strftime)
(MIT License) python-slugify v4.0.0 (https://github.com/un33k/python-slugify)
(MIT License) python-nvd3 v0.15.0 (https://github.com/areski/python-nvd3)
(MIT License) rich v9.2.0 (https://github.com/willmcgugan/rich)
(MIT License) eonasdan-bootstrap-datetimepicker v4.17.37 (https://github.com/eonasdan/bootstrap-datetimepicker/)

========================================================================
Expand Down
13 changes: 13 additions & 0 deletions airflow/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
import logging
import os
import sys
import warnings
from typing import Optional

import pendulum
import rich
from sqlalchemy import create_engine, exc
from sqlalchemy.engine import Engine
from sqlalchemy.orm import scoped_session, sessionmaker
Expand Down Expand Up @@ -94,6 +96,17 @@
}


def custom_show_warning(message, category, filename, lineno, file=None, line=None):
"""Custom function to print rich and visible warnings"""
msg = f"[bold]{line}" if line else f"[bold][yellow]{filename}:{lineno}"
msg += f" {category.__name__}[/bold]: {message}[/yellow]"
file = file or sys.stderr
rich.print(msg, file=file)


warnings.showwarning = custom_show_warning


def policy(task): # pylint: disable=unused-argument
"""
This policy setting allows altering tasks after they are loaded in
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ def is_package_excluded(package: str, exclusion_list: List[str]):
'python-nvd3~=0.15.0',
'python-slugify>=3.0.0,<5.0',
'requests>=2.20.0, <3',
'rich==9.2.0',
'setproctitle>=1.1.8, <2',
'sqlalchemy>=1.3.18, <2',
'sqlalchemy_jsonfield~=0.9',
Expand Down

0 comments on commit cc12db7

Please sign in to comment.