Skip to content

Commit

Permalink
Merge branch 'work/ver-manager' into 'master'
Browse files Browse the repository at this point in the history
Work/ver manager

See merge request deep-learning/tensornet!11
  • Loading branch information
gzm55 committed Jun 22, 2024
2 parents a9ab223 + 01195a6 commit 9a70b75
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 28 deletions.
21 changes: 21 additions & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[bumpversion]
current_version = 0.1.3-dev2
commit = False
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+)(?P<build>\d*))?
serialize =
{major}.{minor}.{patch}-{release}{build}
{major}.{minor}.{patch}-{release}
{major}.{minor}.{patch}-post{build}
{major}.{minor}.{patch}

[bumpversion:part:release]
optional_value = prod
values =
dev
rc
prod

[bumpversion:part:build]

[bumpversion:file:tensornet/version.py]
115 changes: 88 additions & 27 deletions manager
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
#!/usr/bin/env bash

set -eufo pipefail

[[ ${DEBUG-} != true ]] || set -x

readonly WORKSPACE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly TN_BUILD_ENV_NAME=tn_build
WORKSPACE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TN_BUILD_ENV_NAME=tn_build
readonly WORKSPACE_DIR TN_BUILD_ENV_NAME

export MAMBA_EXE=${HOME}/.local/bin/micromamba
export MAMBA_ROOT_PREFIX=${HOME}/micromamba

: ${NEED_PREPARE_ENV:=false}
: ${NEED_ACTIVATE_ENV:=true}
: "${NEED_PREPARE_ENV:=false}"
: "${NEED_ACTIVATE_ENV:=true}"

die() {
local err=$? err_fmt=
Expand All @@ -24,19 +27,19 @@ _prepare_mamba_env(){
fi
_mamba_source
[[ -z ${NEXUS3_HEADER} ]] || {
${MAMBA_EXE} config set --file "${MAMBA_ROOT_PREFIX}/.mambarc" channel_alias ${NEXUS3_HEADER}/conda
${MAMBA_EXE} config set --file "${MAMBA_ROOT_PREFIX}/.mambarc" channel_alias "${NEXUS3_HEADER}/conda"
}
micromamba create -y -f ${WORKSPACE_DIR}/config/${TN_BUILD_ENV_NAME}.yaml
micromamba activate ${TN_BUILD_ENV_NAME}
micromamba create -y -f "${WORKSPACE_DIR}/config/${TN_BUILD_ENV_NAME}.yaml"
micromamba activate "${TN_BUILD_ENV_NAME}"
}

_mamba_source() {
[[ -e ${MAMBA_EXE} ]] || { echo "no micromamba exe found, run ./manager prepare_build_env to create env"; exit 1;}
__mamba_setup="$("$MAMBA_EXE" shell hook --shell bash --root-prefix "$MAMBA_ROOT_PREFIX" 2> /dev/null)"
if [ $? -eq 0 ]; then
local __mamba_setup=''
if __mamba_setup="$("$MAMBA_EXE" shell hook --shell bash --root-prefix "$MAMBA_ROOT_PREFIX" 2> /dev/null)"; then
eval "$__mamba_setup"
else
alias micromamba="$MAMBA_EXE" # Fallback on help from mamba activate
alias micromamba='$MAMBA_EXE' # Fallback on help from mamba activate
fi
unset __mamba_setup
}
Expand All @@ -54,7 +57,7 @@ _prepare_compile_env() {

_build_config(){
CUR_ENV_PATH=$(ompi_info --parsable --path prefix 2>/dev/null | awk -F":" '{print $NF}')
cd ${WORKSPACE_DIR}; bash configure.sh --openmpi_path ${CUR_ENV_PATH}
cd -- "${WORKSPACE_DIR}"; bash configure.sh --openmpi_path "${CUR_ENV_PATH}"
_prepare_compile_env
}

Expand Down Expand Up @@ -89,7 +92,7 @@ start_test(){
cd examples
rm -rf data model || true
python gen_example_data.py
python main.py
python main.py
}


Expand All @@ -104,16 +107,15 @@ start_only_upload(){
exit 0
fi
[[ -z ${NEXUS3_PYPI_HOST} ]] && { echo "need pypi host address, export NEXUS3_PYPI_HOST=xxx"; exit 0; }
twine upload --verbose --repository-url ${NEXUS3_PYPI_HOST} dist/*
twine upload --verbose --repository-url "${NEXUS3_PYPI_HOST}" dist/*
}

start_create_dist(){
[[ ${NEED_PREPARE_ENV} == true ]] && _prepare_mamba_env
[[ ${NEED_ACTIVATE_ENV} == true ]] && _activate_env
rm -rf dist/* || true
[[ $# > 0 ]] && export TN_VERSION=$1
PY_VERSION=$(python -c "import sys; print('cp' + ''.join(map(str, sys.version_info[:2])))")
python setup.py bdist_wheel --plat-name manylinux2010_x86_64 --python-tag ${PY_VERSION}
python setup.py bdist_wheel --plat-name manylinux2010_x86_64 --python-tag "${PY_VERSION}"
twine check dist/*
}

Expand All @@ -123,6 +125,53 @@ start_upload(){
start_only_upload
}

bump_dev_version() {
hash bumpversion >/dev/null || die "cannot find bumpversion command"
local mode=${1:-patch}
case "$mode" in
(major|minor|patch) bumpversion --commit "$mode" ;;
(build)
local release_part=''
release_part=$(bumpversion --allow-dirty build --dry-run --list | grep '^current_version=' | cut -s -d - -f 2-)
case "${release_part-}" in
(dev*) bumpversion --commit "$mode" ;;
(*) die "use '$0 release ...' to bump the build number of a release version." ;;
esac
;;
(*) die "Unknown mode ($mode) for bump_dev_version" ;;
esac
}

bump_release_version() {
hash bumpversion >/dev/null || die "cannot find bumpversion command"
local mode=${1:-prod} release_part=''
release_part=$(bumpversion --allow-dirty build --dry-run --list | grep '^current_version=' | cut -s -d - -f 2-)

case "$mode" in
(rc)
case "${release_part-}" in
(dev*) bumpversion --commit --tag release ;;
(rc*) bumpversion --commit --tag build ;;
(''|post*) die "An production version cannot do a pre-release" ;;
(*) die "Unknown release part ($release_part) for bump_release_version" ;;
esac
;;
(prod)
case "${release_part-}" in
(dev*)
local release_version=''
release_version=$(bumpversion --allow-dirty build --dry-run --list | grep '^current_version=' | cut -s -d - -f 1 | cut -s -d = -f 2)
bumpversion --commit --tag --new-version "$release_version" release # prod release, skip rc
;;
(rc*) bumpversion --commit --tag release ;;
(''|post*) bumpversion --commit --tag build ;;
(*) die "Unknown release part ($release_part) for bump_release_version" ;;
esac
;;
(*) die "Unknown mode ($mode) for bump_release_version" ;;
esac
}

case "$1" in
(prepare_build_env)
_prepare_mamba_env
Expand All @@ -137,35 +186,47 @@ case "$1" in
;;
(deploy)
shift 1
start_upload "$@"
start_upload
;;
(copy-libs)
start_copy_libs
start_copy_libs
;;
(create_dist)
shift 1
start_create_dist "$@"
start_create_dist
;;
(test)
shift 1
start_test "$@"
;;
(help)
(bump-version)
shift 1
bump_dev_version "$@"
;;
(release)
shift 1
bump_release_version "$@"
;;
(''|help)
cmd=$(basename -- "$0")
cat <<-END
Usage:
$cmd help - Print this help.
Usage:
$cmd [help] - Print this help.
$cmd prepare_build_env - install micromamba environment.
$cmd build [args..] - Build tn so file.
$cmd prepare_build_env - install micromamba environment.
$cmd only-build [args..] - Build tn so file without config mpi
$cmd build [args..] - Build tn so file.
$cmd deploy - deploy tn to pypi
$cmd only-build [args..] - Build tn so file without config mpi
$cmd create_dist - create setup dist without upload
$cmd deploy [version] - deploy tn to pypi
$cmd bump-version <major|minor|[patch]|build> - bump major/minor/patch/build version, always generates a *-dev version.
$cmd create_dist [version] - create setup dist without upload
END
$cmd release <rc|[prod]> - generate a new (rc) release, and tag the new commit.
END
;;
(*) die Unknown command "$1" ;;
esac
2 changes: 1 addition & 1 deletion tensornet/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = "0.1.3.dev2"
VERSION = "0.1.3-dev2"

0 comments on commit 9a70b75

Please sign in to comment.