Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
kiyoon committed Oct 16, 2024
1 parent a3ed43f commit d3e4fde
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 37 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# some files created when calling apbs?
io.mc
.DS_Store

# Created by https://www.toptal.com/developers/gitignore/api/python
# Edit at https://www.toptal.com/developers/gitignore?templates=python
Expand Down
83 changes: 46 additions & 37 deletions build_python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,68 +18,77 @@ fi
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
mkdir -p "$SCRIPT_DIR/dist"

TEMP_DIR=$(mktemp -d)
PYTHON_BUILD_DIR="$TEMP_DIR/python"
PYTHON_PACKAGE_DIR="$PYTHON_BUILD_DIR/src/apbs_binary"
echo "Temp directory: $TEMP_DIR"
echo "Python build directory: $PYTHON_BUILD_DIR"

# copy the python project to the temp directory
cp -r python "$TEMP_DIR"
cp "$SCRIPT_DIR/README.md" "$PYTHON_BUILD_DIR"
mkdir "$PYTHON_BUILD_DIR/src/apbs_binary/bin"

# Replace version = "0.0.0" with the desired version
$SED -i "s/version = \"0.0.0\"/version = \"$PY_PACKAGE_VERSION\"/g" "$PYTHON_BUILD_DIR/pyproject.toml" || { echo "Failure"; exit 1; }
# Replace __version__ = "0.0.0" with the desired version
$SED -i "s/__version__ = \"0.0.0\"/__version__ = \"$PY_PACKAGE_VERSION\"/g" "$PYTHON_PACKAGE_DIR/__init__.py" || { echo "Failure"; exit 1; }
prepare_python_in_temp_dir() {
TEMP_DIR=$(mktemp -d)
PYTHON_BUILD_DIR="$TEMP_DIR/python"
PYTHON_PACKAGE_DIR="$PYTHON_BUILD_DIR/src/apbs_binary"
echo "Temp directory: $TEMP_DIR"
echo "Python build directory: $PYTHON_BUILD_DIR"

# copy the python project to the temp directory
cp -r "$SCRIPT_DIR/python" "$TEMP_DIR"
cp "$SCRIPT_DIR/README.md" "$PYTHON_BUILD_DIR"
mkdir "$PYTHON_BUILD_DIR/src/apbs_binary/bin"

# Replace version = "0.0.0" with the desired version
$SED -i "s/version = \"0.0.0\"/version = \"$PY_PACKAGE_VERSION\"/g" "$PYTHON_BUILD_DIR/pyproject.toml" || { echo "Failure"; exit 1; }
# Replace __version__ = "0.0.0" with the desired version
$SED -i "s/__version__ = \"0.0.0\"/__version__ = \"$PY_PACKAGE_VERSION\"/g" "$PYTHON_PACKAGE_DIR/__init__.py" || { echo "Failure"; exit 1; }
}

build_wheel() {
cd "$PYTHON_BUILD_DIR" || { echo "Failure"; exit 1; }
pyproject-build --installer=uv --wheel
wheel tags --python-tag py3 --abi-tag none --platform "$PLATFORM_NAME" dist/*.whl --remove
mv "$PYTHON_BUILD_DIR/dist/"*.whl "$SCRIPT_DIR/dist"
}

# extract each binary in the temp directory
# 1. macosx_12_0_arm64
prepare_python_in_temp_dir

PLATFORM_NAME="macosx_12_0_arm64"
tar xvzf "$SCRIPT_DIR/data/apbs-$APBS_VERSION/apbs-${APBS_VERSION}_2-macosx_12_0_arm64.tar.gz" -C "$TEMP_DIR"
mv "$TEMP_DIR/${APBS_VERSION}_2/bin/apbs" "$PYTHON_PACKAGE_DIR/bin"
mv "$TEMP_DIR/${APBS_VERSION}_2/share/apbs/tools/bin/"* "$PYTHON_PACKAGE_DIR/bin"
cd "$PYTHON_BUILD_DIR" || { echo "Failure"; exit 1; }
pyproject-build --installer=uv --wheel
wheel tags --python-tag py3 --abi-tag none --platform "$PLATFORM_NAME" dist/*.whl --remove
mv "$PYTHON_BUILD_DIR/dist/"*.whl "$SCRIPT_DIR/dist"

build_wheel

# 2. macosx_11_0_x86_64
prepare_python_in_temp_dir

PLATFORM_NAME="macosx_11_6_x86_64"
rm -rf "${PYTHON_PACKAGE_DIR:?}/bin" # ${var:?} to ensure it doesn't expand to /bin !
mkdir "$PYTHON_PACKAGE_DIR/bin"
# rm -rf "${PYTHON_PACKAGE_DIR:?}/bin" # ${var:?} to ensure it doesn't expand to /bin !
# mkdir "$PYTHON_PACKAGE_DIR/bin"
unzip "$SCRIPT_DIR/data/apbs-${APBS_VERSION}/APBS-${APBS_VERSION}.Darwin.zip" -d "$TEMP_DIR"
mv "$TEMP_DIR/APBS-${APBS_VERSION}.Darwin/bin/apbs" "$PYTHON_PACKAGE_DIR/bin"
mv "$TEMP_DIR/APBS-${APBS_VERSION}.Darwin/share/apbs/tools/bin/"* "$PYTHON_PACKAGE_DIR/bin"
cd "$PYTHON_BUILD_DIR" || { echo "Failure"; exit 1; }
pyproject-build --installer=uv --wheel
wheel tags --python-tag py3 --abi-tag none --platform "$PLATFORM_NAME" dist/*.whl --remove
mv "$PYTHON_BUILD_DIR/dist/"*.whl "$SCRIPT_DIR/dist"

build_wheel

# 3. Linux
prepare_python_in_temp_dir

# NOTE: the actual platform is manylinux_2_30_x86_64, but it won't be compatible with uv pip compile.
# Thus we use manylinux_2_28_x86_64, for now.
# It will crash when running in Ubuntu 18.04 but still succeed to install.
PLATFORM_NAME="manylinux_2_28_x86_64"
rm -rf "${PYTHON_PACKAGE_DIR:?}/bin" # ${var:?} to ensure it doesn't expand to /bin !
mkdir "$PYTHON_PACKAGE_DIR/bin"
# rm -rf "${PYTHON_PACKAGE_DIR:?}/bin" # ${var:?} to ensure it doesn't expand to /bin !
# mkdir "$PYTHON_PACKAGE_DIR/bin"
unzip "$SCRIPT_DIR/data/apbs-${APBS_VERSION}/APBS-${APBS_VERSION}.Linux.zip" -d "$TEMP_DIR"
mv "$TEMP_DIR/APBS-${APBS_VERSION}.Linux/bin/apbs" "$PYTHON_PACKAGE_DIR/bin"
mv "$TEMP_DIR/APBS-${APBS_VERSION}.Linux/share/apbs/tools/bin/"* "$PYTHON_PACKAGE_DIR/bin"
cd "$PYTHON_BUILD_DIR" || { echo "Failure"; exit 1; }
pyproject-build --installer=uv --wheel
wheel tags --python-tag py3 --abi-tag none --platform "$PLATFORM_NAME" dist/*.whl --remove
mv "$PYTHON_BUILD_DIR/dist/"*.whl "$SCRIPT_DIR/dist"

build_wheel

# 4. Windows
prepare_python_in_temp_dir

PLATFORM_NAME="win_amd64"
rm -rf "${PYTHON_PACKAGE_DIR:?}/bin" # ${var:?} to ensure it doesn't expand to /bin !
mkdir "$PYTHON_PACKAGE_DIR/bin"
# rm -rf "${PYTHON_PACKAGE_DIR:?}/bin" # ${var:?} to ensure it doesn't expand to /bin !
# mkdir "$PYTHON_PACKAGE_DIR/bin"
unzip "$SCRIPT_DIR/data/apbs-${APBS_VERSION}/APBS-${APBS_VERSION}.Windows.zip" -d "$TEMP_DIR"
mv "$TEMP_DIR/APBS-${APBS_VERSION}.Windows/bin/apbs.exe" "$PYTHON_PACKAGE_DIR/bin"
mv "$TEMP_DIR/APBS-${APBS_VERSION}.Windows/share/apbs/tools/bin/"*.exe "$PYTHON_PACKAGE_DIR/bin"
cd "$PYTHON_BUILD_DIR" || { echo "Failure"; exit 1; }
pyproject-build --installer=uv --wheel
wheel tags --python-tag py3 --abi-tag none --platform "$PLATFORM_NAME" dist/*.whl --remove
mv "$PYTHON_BUILD_DIR/dist/"*.whl "$SCRIPT_DIR/dist"

build_wheel

0 comments on commit d3e4fde

Please sign in to comment.