18
18
from __future__ import annotations
19
19
20
20
import hashlib
21
+ import importlib .util
21
22
import os
22
23
import re
23
24
import shutil
24
25
import subprocess
25
- import sys
26
26
from pathlib import Path
27
27
28
28
# NOTE!. This script is executed from node environment created by pre-commit and this environment
@@ -52,17 +52,18 @@ def get_directory_hash(directory: Path, skip_path_regexp: str | None = None) ->
52
52
f"To run this script, run the ./{ __file__ } command"
53
53
)
54
54
55
- if __name__ == "__main__" :
56
- www_directory = AIRFLOW_SOURCES_PATH / "airflow" / "www"
55
+
56
+ def compile_assets ( www_directory : Path , www_hash_file_name : str ):
57
57
node_modules_directory = www_directory / "node_modules"
58
58
dist_directory = www_directory / "static" / "dist"
59
- WWW_HASH_FILE .parent .mkdir (exist_ok = True , parents = True )
59
+ www_hash_file = AIRFLOW_SOURCES_PATH / ".build" / "www" / www_hash_file_name
60
+ www_hash_file .parent .mkdir (exist_ok = True , parents = True )
60
61
if node_modules_directory .exists () and dist_directory .exists ():
61
- old_hash = WWW_HASH_FILE .read_text () if WWW_HASH_FILE .exists () else ""
62
+ old_hash = www_hash_file .read_text () if www_hash_file .exists () else ""
62
63
new_hash = get_directory_hash (www_directory , skip_path_regexp = r".*node_modules.*" )
63
64
if new_hash == old_hash :
64
65
print ("The WWW directory has not changed! Skip regeneration." )
65
- sys . exit ( 0 )
66
+ return
66
67
else :
67
68
shutil .rmtree (node_modules_directory , ignore_errors = True )
68
69
shutil .rmtree (dist_directory , ignore_errors = True )
@@ -71,4 +72,20 @@ def get_directory_hash(directory: Path, skip_path_regexp: str | None = None) ->
71
72
subprocess .check_call (["yarn" , "install" , "--frozen-lockfile" ], cwd = os .fspath (www_directory ))
72
73
subprocess .check_call (["yarn" , "run" , "build" ], cwd = os .fspath (www_directory ), env = env )
73
74
new_hash = get_directory_hash (www_directory , skip_path_regexp = r".*node_modules.*" )
74
- WWW_HASH_FILE .write_text (new_hash )
75
+ www_hash_file .write_text (new_hash )
76
+
77
+
78
+ def is_fab_provider_installed () -> bool :
79
+ return importlib .util .find_spec ("airflow.providers.fab" ) is not None
80
+
81
+
82
+ if __name__ == "__main__" :
83
+ # Compile assets for main
84
+ main_www_directory = AIRFLOW_SOURCES_PATH / "airflow" / "www"
85
+ compile_assets (main_www_directory , "hash.txt" )
86
+ if is_fab_provider_installed ():
87
+ # Compile assets for fab provider
88
+ fab_provider_www_directory = (
89
+ AIRFLOW_SOURCES_PATH / "providers" / "src" / "airflow" / "providers" / "fab" / "www"
90
+ )
91
+ compile_assets (fab_provider_www_directory , "hash_fab.txt" )
0 commit comments