Skip to content

Commit

Permalink
Beautify Output of setup-installation pre-commit (#12218)
Browse files Browse the repository at this point in the history
(cherry picked from commit 08d67ad)
  • Loading branch information
kaxil committed Nov 18, 2020
1 parent 97e23ee commit c7f1587
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ repos:
files: ^setup.py$|^docs/installation.rst$
pass_filenames: false
entry: ./scripts/ci/pre_commit/pre_commit_check_setup_installation.py
additional_dependencies: ['rich==9.2.0']
- id: update-breeze-file
name: Update output of breeze command in BREEZE.rst
entry: "./scripts/ci/pre_commit/pre_commit_breeze_cmd_line.sh"
Expand Down
29 changes: 18 additions & 11 deletions scripts/ci/pre_commit/pre_commit_check_setup_installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
from os.path import dirname
from typing import Dict, List

from rich import print as rprint
from rich.console import Console
from rich.table import Table

AIRFLOW_SOURCES_DIR = os.path.join(dirname(__file__), os.pardir, os.pardir, os.pardir)
SETUP_PY_FILE = 'setup.py'
DOCS_FILE = 'installation.rst'
Expand Down Expand Up @@ -80,30 +84,33 @@ def get_extras_from_docs() -> List[str]:
setup_packages = get_extras_from_setup()
docs_packages = get_extras_from_docs()

output_table = ""
table = Table()
table.add_column("NAME", justify="right", style="cyan")
table.add_column("SETUP", justify="center", style="magenta")
table.add_column("INSTALLATION", justify="center", style="green")

for extras in sorted(setup_packages.keys()):
if not set(setup_packages[extras]).intersection(docs_packages):
output_table += "| {:20} | {:^10} | {:^10} |\n".format(extras, "V", "")
table.add_row(extras, "V", "")

setup_packages_str = str(setup_packages)
for extras in sorted(docs_packages):
if f"'{extras}'" not in setup_packages_str:
output_table += "| {:20} | {:^10} | {:^10} |\n".format(extras, "", "V")
table.add_row(extras, "", "V")

if output_table == "":
if table.row_count == 0:
sys.exit(0)

print(f"""
ERROR
rprint(f"""\
[red bold]ERROR!![/red bold]
"EXTRAS_REQUIREMENTS" section in {SETUP_PY_FILE} should be synchronized
with "Extra Packages" section in documentation file doc/{DOCS_FILE}.
"EXTRAS_REQUIREMENTS" section in [bold yellow]{SETUP_PY_FILE}[/bold yellow] should be synchronized
with "Extra Packages" section in documentation file [bold yellow]doc/{DOCS_FILE}[/bold yellow].
here is a list of packages that are used but are not documented, or
Here is a list of packages that are used but are not documented, or
documented although not used.
""")
print(".{:_^22}.{:_^12}.{:_^12}.".format("NAME", "SETUP", "INSTALLATION"))
print(output_table)
console = Console()
console.print(table)

sys.exit(1)

0 comments on commit c7f1587

Please sign in to comment.