Skip to content

Commit

Permalink
Further make sure graphviz is truly optional feature on MacOS
Browse files Browse the repository at this point in the history
For our development, Pygraphviz is quite a difficul dependency to
install on MacOS. That's why we disable it by default on MacOS -
it was attempted in #43604, but it turned out some other dependencies
pulled it in as well.

This PR removes all the graphviz dependencies as being required,
and providers more readable error message and iink to documuentation
explaining how to install graphviz if needed.
  • Loading branch information
potiuk committed Nov 11, 2024
1 parent cf3f9c7 commit c00234c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
7 changes: 5 additions & 2 deletions hatch_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,11 @@
],
"doc-gen": [
"apache-airflow[doc]",
"diagrams>=0.23.4",
"eralchemy2>=1.3.8",
# The graphviz package creates friction when installing on MacOS as it needs graphviz system package to
# be installed, and it's really only used for very obscure features of Airflow, so we can skip it on MacOS
# Instead, if someone attempts to use it on MacOS, they will get explanatory error on how to install it
"diagrams>=0.23.4; sys_platform != 'darwin'",
"eralchemy2>=1.3.8; sys_platform != 'darwin'",
],
# END OF doc extras
}
Expand Down
14 changes: 12 additions & 2 deletions scripts/ci/pre_commit/generate_airflow_diagrams.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,19 @@ def main():
hash_file = source_file.with_suffix(".md5sum")
if not hash_file.exists() or not hash_file.read_text().strip() == str(checksum).strip():
console.print(f"[bright_blue]Changes in {source_file}. Regenerating the image.")
subprocess.run(
[sys.executable, source_file.resolve().as_posix()], check=True, cwd=source_file.parent
process = subprocess.run(
[sys.executable, source_file.resolve().as_posix()], check=False, cwd=source_file.parent
)
if process.returncode != 0:
if sys.platform == "darwin":
console.print(
"[red]Likely you have no graphviz installed[/]"
"Please install eralchemy2 package to run this script. "
"This will require to install graphviz, "
"and installing graphviz might be difficult for MacOS. Please follow: "
"https://pygraphviz.github.io/documentation/stable/install.html#macos ."
)
sys.exit(1)
hash_file.write_text(str(checksum) + "\n")
else:
console.print(f"[bright_blue]No changes in {source_file}. Not regenerating the image.")
Expand Down
15 changes: 13 additions & 2 deletions scripts/in_container/run_prepare_er_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from __future__ import annotations

import os
import sys
from pathlib import Path

from checksumdir import dirhash
Expand All @@ -34,9 +35,19 @@

MIGRATIONS_DIR = AIRFLOW_SOURCES_ROOT / "airflow" / "migrations"
if __name__ == "__main__":
from eralchemy2 import render_er

console = Console(width=400, color_system="standard")
try:
from eralchemy2 import render_er
except ImportError:
if sys.platform == "darwin":
console.print(
"[red]Likely you have no graphviz installed[/]"
"Please install eralchemy2 package to run this script. "
"This will require to install graphviz, "
"and installing graphviz might be difficult for MacOS. Please follow: "
"https://pygraphviz.github.io/documentation/stable/install.html#macos ."
)
exit(1)

console.print("[bright_blue]Preparing diagram for Airflow ERD")
sha256hash = dirhash(
Expand Down

0 comments on commit c00234c

Please sign in to comment.