hatch_build.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. """Custom build hook for Hatch."""
  2. import pathlib
  3. import subprocess
  4. import sys
  5. from typing import Any
  6. from hatchling.builders.hooks.plugin.interface import BuildHookInterface
  7. class CustomBuilder(BuildHookInterface):
  8. """Custom build hook for Hatch."""
  9. PLUGIN_NAME = "custom"
  10. def marker(self) -> pathlib.Path:
  11. """Get the marker file path.
  12. Returns:
  13. The marker file path.
  14. """
  15. return (
  16. pathlib.Path(self.directory)
  17. / f".reflex-{self.metadata.version}.pyi_generated"
  18. )
  19. def finalize(
  20. self, version: str, build_data: dict[str, Any], artifact_path: str
  21. ) -> None:
  22. """Finalize the build process.
  23. Args:
  24. version: The version of the package.
  25. build_data: The build data.
  26. artifact_path: The path to the artifact.
  27. """
  28. if self.marker().exists():
  29. return
  30. if not (pathlib.Path(self.root) / "scripts").exists():
  31. return
  32. for file in (pathlib.Path(self.root) / "reflex").rglob("**/*.pyi"):
  33. file.unlink(missing_ok=True)
  34. subprocess.run(
  35. [sys.executable, "-m", "reflex.utils.pyi_generator"],
  36. check=True,
  37. )
  38. self.marker().touch()