Repository: apache/airflow
File: providers/edge3/hatch_build.py (Python)

Code before:
    # https://hatch.pypa.io/latest/plugins/build-hook/custom/#example
    PLUGIN_NAME = "custom"

    @staticmethod
    def clean_dir(path: Path) -> None:
        log.warning("Cleaning directory: %s", path)
        shutil.rmtree(path, ignore_errors=True)

    def clean(self, directory: str, versions: Iterable[str]) -> None:
        work_dir = Path(self.root)
        log.warning("Cleaning generated files in directory: %s", work_dir)
        edge3_package_src = work_dir / "src" / "airflow" / "providers" / "edge3"
        edge3_ui_path = edge3_package_src / "plugins" / "www"
        self.clean_dir(edge3_ui_path / ".pnpm-store")
        self.clean_dir(edge3_ui_path / "dist")
        self.clean_dir(edge3_ui_path / "node_modules")

    def get_version_api(self) -> dict[str, Callable[..., str]]:
        """Get custom build target for standard package preparation."""
        return {"standard": self.build_standard}

    def build_standard(self, directory: str, artifacts: Any, **build_data: Any) -> str:
        self.write_git_version()
        # run this in the airflow repo root
        work_dir = Path(self.root).parents[1].resolve()
        cmd = ["prek", "run", "--hook-stage", "manual", "compile-edge-assets", "--all-files"]
        log.warning("Running command: %s", " ".join(cmd))
        run(cmd, cwd=work_dir.as_posix(), check=True)
        dist_path = Path(self.root) / "src" / "airflow" / "providers" / "edge3" / "plugins" / "www" / "dist"
        return dist_path.resolve().as_posix()

    def get_git_version(self) -> str:
        """
        Return a version to identify the state of the underlying git repo.

        The version will indicate whether the head of the current git-backed working directory
        is tied to a release tag or not. It will indicate the former with a 'release:{version}'
        prefix and the latter with a '.dev0' suffix. Following the prefix will be a sha of the
        current branch head. Finally, a "dirty" suffix is appended to indicate that uncommitted
        changes are present.

        Example pre-release version: ".dev0+2f635dc265e78db6708f59f68e8009abb92c1e65".
        Example release version: ".release+2f635dc265e78db6708f59f68e8009abb92c1e65".
        Example modified release version: ".release+2f635dc265e78db6708f59f68e8009abb92c1e65".dirty

        :return: Found Airflow version in Git repo.
        """
        try:
            import git

            try:

Review comment (suggestion):
I think we should move the prek hooks to `edge3` folder for this to make sense (including scripts prek needs to use to run the hook.

Code after:
    # https://hatch.pypa.io/latest/plugins/build-hook/custom/#example
    PLUGIN_NAME = "custom"

    @staticmethod
    def clean_dir(path: Path) -> None:
        log.warning("Cleaning directory: %s", path)
        shutil.rmtree(path, ignore_errors=True)

    def clean(self, directory: str, versions: Iterable[str]) -> None:
        work_dir = Path(self.root)
        log.warning("Cleaning generated files in directory: %s", work_dir)
        edge3_package_src = work_dir / "src" / "airflow" / "providers" / "edge3"
        edge3_ui_path = edge3_package_src / "plugins" / "www"
        self.clean_dir(edge3_ui_path / ".pnpm-store")
        self.clean_dir(edge3_ui_path / "dist")
        self.clean_dir(edge3_ui_path / "node_modules")
        (work_dir / "www-hash.txt").unlink(missing_ok=True)

    def get_version_api(self) -> dict[str, Callable[..., str]]:
        """Get custom build target for standard package preparation."""
        return {"standard": self.build_standard}

    def build_standard(self, directory: str, artifacts: Any, **build_data: Any) -> str:
        # run this in the airflow repo root
        work_dir = Path(self.root).parents[1].resolve()
        cmd = ["prek", "run", "compile-edge-assets", "--all-files"]
        log.warning("Running command: %s", " ".join(cmd))
        run(cmd, cwd=work_dir.as_posix(), check=True)
        dist_path = Path(self.root) / "src" / "airflow" / "providers" / "edge3" / "plugins" / "www" / "dist"
        return dist_path.resolve().as_posix()