Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI] Update scripts to build wheel #65

Merged
merged 4 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ jobs:

- name: Build hidet
run: |
bash scripts/build_wheel.sh
WHEEL=$(find ./scripts/ -maxdepth 1 -name '*.whl')
bash scripts/wheel/build_wheel.sh
WHEEL=$(find ./scripts/wheel/built_wheel -maxdepth 1 -name '*.whl')
echo "WHEEL_NAME=$WHEEL" >> $GITHUB_ENV
echo "Built wheel: ${{ env.WHEEL_NAME }}"

Expand Down
76 changes: 0 additions & 76 deletions scripts/update_version.py

This file was deleted.

28 changes: 18 additions & 10 deletions scripts/build_wheel.sh → scripts/wheel/build_wheel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,33 @@ set -e # exit immediately if a command exits with a non-zero status.
###############################################################################

# work in the same directory of this script
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
cd $SCRIPT_DIR
CURRENT_SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
ROOT_DIR=$(cd -- "$CURRENT_SCRIPT_DIR/../.." &> /dev/null && pwd)
cd $CURRENT_SCRIPT_DIR

# create a new build directory
rm -rf build; mkdir build;

# build
cd build; cmake ../..; make -j4; cd ..
cd build; cmake $ROOT_DIR; make -j4; cd ..

# copy the built libraries and headers to python module
cp ../setup.py ./setup.py
cp ../MANIFEST.in ./MANIFEST.in
cp ../README.md ./README.md
cp -r ../python ./
cp -r ./build/lib ./python/hidet
cp -r ../include ./python/hidet
cp $ROOT_DIR/setup.py ./setup.py
cp $ROOT_DIR/MANIFEST.in ./MANIFEST.in
cp $ROOT_DIR/README.md ./README.md
cp -r $ROOT_DIR/python ./
cp -r $ROOT_DIR/include ./python/hidet
cp -r $CURRENT_SCRIPT_DIR/build/lib ./python/hidet

# update version if needed
if [ $# -eq 1 ]; then
echo "Updating version to $1"
python3 $CURRENT_SCRIPT_DIR/update_version.py --version $1
fi

# build wheel
pip wheel --no-deps .
mkdir -p built_wheel;
cd built_wheel; pip wheel --no-deps ..; cd ..

# remove all intermediate directories
rm -rf ./python
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ bash ./dockerfiles/manylinux1/build_image.sh
echo $HIDET_DIR

# run the docker image
docker run --rm -v $HIDET_DIR:/io hidet-manylinux1-build bash /io/scripts/build_wheel.sh
docker run --rm -v $HIDET_DIR:/io hidet-manylinux1-build bash /io/scripts/wheel/build_wheel.sh $1
56 changes: 56 additions & 0 deletions scripts/wheel/current_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/python3
"""
Get the current the version string in python/hidet/version.py

Usage
-----
$ python scripts/wheel/current_version.py

"""
import os
import argparse
import datetime

parser = argparse.ArgumentParser("current_version.py")

parser.add_argument(
"--root",
type=str,
default="./",
help="root directory of the project, under which setup.py is located. Default: ./",
)
parser.add_argument(
"--nightly",
action="store_true",
help="If set, the version will be set to the nightly version. ",
)


def main():
args = parser.parse_args()

root_dir = os.path.abspath(os.path.expanduser(args.root))
version_py = os.path.realpath(
os.path.join(root_dir, "python", "hidet", "version.py")
)
if not os.path.exists(version_py) or not os.path.isfile(version_py):
raise FileNotFoundError(version_py)
output_version = None
with open(version_py, "r") as f:
lines = f.readlines()
for line in lines:
if line.startswith("__version__ = "):
version = line.split("=")[1].strip()[1:-1]
if args.nightly:
date_string = datetime.datetime.now().strftime("%Y%m%d")
if version.endswith(".dev"):
version = version.replace(".dev", ".dev{}".format(date_string))
output_version = version
break
if output_version is None:
raise RuntimeError('The occurrence of "__version__ = " in version.py is not')
print(output_version, end="")


if __name__ == "__main__":
main()
96 changes: 96 additions & 0 deletions scripts/wheel/update_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/usr/bin/python3
"""
Update the version string in setup.py and python/hidet/version.py

Usage
-----
$ python scripts/wheel/update_version.py <version>

For example, to update the version to 0.0.2, run
$ python scripts/wheel/update_version.py 0.0.2
"""
import os
import argparse
import re

parser = argparse.ArgumentParser("update_version.py")

parser.add_argument(
"--root",
type=str,
default="./",
help="root directory of the project, under which setup.py is located. Default: ./",
)
parser.add_argument("--version", type=str, required=True, help="Version to update to")


def update_setup_py(setup_py, version):
print("Updating version in {} to {}".format(setup_py, version))

with open(setup_py, "r") as f:
lines = f.readlines()

count = 0
for i, line in enumerate(lines):
if line.startswith(' version="'):
lines[i] = ' version="{}",\n'.format(version)
count += 1
if count != 1:
raise RuntimeError("The occurrence of version= in setup.py is not 1")

with open(setup_py, "w") as f:
f.writelines(lines)


def update_version_py(version_py, version):
print("Updating version in {} to {}".format(version_py, version))

with open(version_py, "r") as f:
lines = f.readlines()

count = 0
for i, line in enumerate(lines):
if line.startswith("__version__ = "):
lines[i] = '__version__ = "{}"\n'.format(version)
count += 1
if count != 1:
raise RuntimeError('The occurrence of "__version__ = " in version.py is not 1')

with open(version_py, "w") as f:
f.writelines(lines)


def check_version(version: str):
patterns = [
r"^\d+\.\d+(\.\d+)?$", # 0.1.1 or 0.2
r"^\d+\.\d+(\.\d+)?(\.dev\d*)?$", # 0.1.1.dev1 or 0.2.dev2 or 0.2.dev20220101
]
for pattern in patterns:
if re.match(pattern, version):
return
raise ValueError("Invalid version: {}".format(version))


def main():
args = parser.parse_args()

version = args.version

check_version(version)

# Update version in setup.py
root_dir = os.path.abspath(os.path.expanduser(args.root))
setup_py = os.path.realpath(os.path.join(root_dir, "setup.py"))
version_py = os.path.realpath(
os.path.join(root_dir, "python", "hidet", "version.py")
)
if not os.path.exists(setup_py) or not os.path.isfile(setup_py):
raise FileNotFoundError(setup_py)
if not os.path.exists(version_py) or not os.path.isfile(version_py):
raise FileNotFoundError(version_py)
update_setup_py(setup_py, version)
update_version_py(version_py, version)


if __name__ == "__main__":
main()
File renamed without changes.