build.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env bash
  2. set -o errexit
  3. set -o nounset
  4. set -o pipefail
  5. ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
  6. source "${ROOT_DIR}/hack/lib/init.sh"
  7. function build() {
  8. uv build
  9. }
  10. function prepare_dependencies() {
  11. DEPS_ONLY=true bash "${ROOT_DIR}/hack/install.sh"
  12. }
  13. function set_version() {
  14. local version_file="${ROOT_DIR}/gpustack/__init__.py"
  15. local pyproject_file="${ROOT_DIR}/pyproject.toml"
  16. local git_commit="${GIT_COMMIT:-HEAD}"
  17. local git_commit_short="${git_commit:0:7}"
  18. gpustack::log::info "setting version to $GIT_VERSION"
  19. gpustack::log::info "setting git commit to $git_commit_short"
  20. # Replace the __version__ variable in the __init__.py file
  21. gpustack::util::sed "s/__version__ = .*/__version__ = '${GIT_VERSION}'/" "${version_file}"
  22. gpustack::util::sed "s/__git_commit__ = .*/__git_commit__ = '${git_commit_short}'/" "${version_file}"
  23. # Update the version in pyproject.toml
  24. gpustack::util::sed "s/^version = .*/version = \"${GIT_VERSION}\"/" "${pyproject_file}"
  25. }
  26. function restore_version_file() {
  27. local version_file="${ROOT_DIR}/gpustack/__init__.py"
  28. local pyproject_file="${ROOT_DIR}/pyproject.toml"
  29. # In Docker build contexts (bind mounts), files may not be tracked by git.
  30. # Since the wheel is already built, restoration is only needed for local dev.
  31. if git ls-files --error-unmatch "${version_file}" &>/dev/null && \
  32. git ls-files --error-unmatch "${pyproject_file}" &>/dev/null; then
  33. git checkout -- "${version_file}" "${pyproject_file}"
  34. fi
  35. }
  36. #
  37. # main
  38. #
  39. gpustack::log::info "+++ BUILD +++"
  40. prepare_dependencies
  41. set_version
  42. build
  43. restore_version_file
  44. gpustack::log::info "--- BUILD ---"