Repository: apache/airflow
File: scripts/ci/prek/compile_provider_assets.py (Python)

Code before:
    },
    "edge": {
        "root": PROVIDERS_ROOT / "edge3",
        "www": PROVIDERS_ROOT / "edge3" / "src" / "airflow" / "providers" / "edge3" / "plugins" / "www",
        "dist": PROVIDERS_ROOT
        / "edge3"
        / "src"
        / "airflow"
        / "providers"
        / "edge3"
        / "plugins"
        / "www"
        / "dist",
        "hash": PROVIDERS_ROOT / "edge3" / "www-hash.txt",
    },
}
PROVIDERS_BUILD = {
    "fab": "yarn",
    "edge": "pnpm",
}


def get_directory_hash(directory: Path, skip_path_regexps: list[str]) -> str:
    files = sorted(directory.rglob("*"))
    for skip_path_regexp in skip_path_regexps:
        matcher = re.compile(skip_path_regexp)
        files = [file for file in files if not matcher.match(os.fspath(file.resolve()))]
    sha = hashlib.sha256()
    for file in files:
        if file.is_file() and not file.name.startswith("."):
            sha.update(file.read_bytes())
    return sha.hexdigest()


if __name__ not in ("__main__", "__mp_main__"):
    raise SystemExit(
        "This file is intended to be executed as an executable program. You cannot use it as a module."
        f"To run this script, run the ./{__file__} command"
    )

INTERNAL_SERVER_ERROR = "500 Internal Server Error"

SKIP_PATH_REGEXPS = [".*/node_modules.*", ".*/.pnpm-store.*"]


def compile_assets(provider_name: str):
    if provider_name not in PROVIDERS_PATHS:
        raise ValueError(
            f"Provider '{provider_name}' is not supported. Supported providers: {list(PROVIDERS_PATHS.keys())}"
        )
    provider_paths = PROVIDERS_PATHS[provider_name]

Review comment (suggestion):
nit, Make PROVIDERS_BUILD encode the full commands instead of just the package manager name, so there's no inline conditional logic ?
```suggestion
  PROVIDERS_BUILD = {
      "fab": {
          "install": ["yarn", "install", "--frozen-lockfile"],
          "build": ["yarn", "run", "build"],
      },
      "edge": {
          "install": ["pnpm", "install", "--frozen-lockfile"],
          "build": ["pnpm", "build"],
      },
  }
```

Code after:
    },
    "edge": {
        "root": PROVIDERS_ROOT / "edge3",
        "www": PROVIDERS_ROOT / "edge3" / "src" / "airflow" / "providers" / "edge3" / "plugins" / "www",
        "dist": PROVIDERS_ROOT
        / "edge3"
        / "src"
        / "airflow"
        / "providers"
        / "edge3"
        / "plugins"
        / "www"
        / "dist",
        "hash": PROVIDERS_ROOT / "edge3" / "www-hash.txt",
    },
}
PROVIDERS_BUILD = {
    "fab": {
        "install": ["yarn", "install", "--frozen-lockfile"],
        "build": ["yarn", "run", "build"],
    },
    "edge": {
        "install": ["pnpm", "install", "--frozen-lockfile"],
        "build": ["pnpm", "build"],
    },
}


def get_directory_hash(directory: Path, skip_path_regexps: list[str]) -> str:
    files = sorted(directory.rglob("*"))
    for skip_path_regexp in skip_path_regexps:
        matcher = re.compile(skip_path_regexp)
        files = [file for file in files if not matcher.match(os.fspath(file.resolve()))]
    sha = hashlib.sha256()
    for file in files:
        if file.is_file() and not file.name.startswith("."):
            sha.update(file.read_bytes())
    return sha.hexdigest()


if __name__ not in ("__main__", "__mp_main__"):
    raise SystemExit(
        "This file is intended to be executed as an executable program. You cannot use it as a module."
        f"To run this script, run the ./{__file__} command"
    )

INTERNAL_SERVER_ERROR = "500 Internal Server Error"

SKIP_PATH_REGEXPS = [".*/node_modules.*", ".*/.pnpm-store.*"]