Avoid redownloading python-build, use asdf_dir instead of hard-coded path, close #11

This commit is contained in:
Daniel Perez 2017-01-22 18:31:29 +09:00
parent c2bd01edf0
commit 331e65d419
6 changed files with 38 additions and 31 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/pyenv

View file

@ -1,13 +1,13 @@
#!/usr/bin/env bash
get_legacy_version() {
current_directory=$1
python_version_file="$current_directory/.python-version"
local current_directory="$1"
local python_version_file="$current_directory/.python-version"
# Get version from .python-version file. .python-version is used by pyenv
if [ -f $python_version_file ]; then
cat $python_version_file
if [ -f "$python_version_file" ]; then
cat "$python_version_file"
fi
}
get_legacy_version $1
get_legacy_version "$1"

View file

@ -1,27 +1,20 @@
#!/usr/bin/env bash
source $(dirname $0)/utils.sh
install_python() {
local version="$1"
local install_path="$2"
local tmp_download_dir="$(mktemp -d -t asdf-python.XXX)"
local tmp_dir="$(mktemp -d -t asdf-python.XXX)"
echo "Downloading python-build..."
download_python_build $tmp_download_dir > /dev/null 2>&1
local python_build="$tmp_download_dir/pyenv/plugins/python-build/bin/python-build"
ensure_python_build_installed
ASDF_CONCURRENCY="${ASDF_CONCURRENCY:-1}"
echo "python-build $version $install_path"
MAKE_OPTS="$MAKE_OPTS -j$ASDF_CONCURRENCY" TMP_DIR="$tmp_download_dir" $python_build $version $install_path
MAKE_OPTS="$MAKE_OPTS -j$ASDF_CONCURRENCY" TMP_DIR="$tmp_dir" $(python_build_path) $version $install_path
echo "Cleaning up"
rm -rf "$tmp_download_dir"
}
download_python_build() {
local tmp_dir="$1"
local pyenv_url="git://github.com/yyuu/pyenv.git"
git clone $pyenv_url $tmp_dir/pyenv
rm -rf "$tmp_dir"
}
install_python $ASDF_INSTALL_VERSION $ASDF_INSTALL_PATH

View file

@ -1,17 +1,11 @@
#!/usr/bin/env bash
source $(dirname $0)/utils.sh
list_all() {
local tmp_download_dir="$(mktemp -d -t asdf-python.XXX)"
download_python_build $tmp_download_dir > /dev/null 2>&1
local python_build="$tmp_download_dir/pyenv/plugins/python-build/bin/python-build"
$python_build --definitions | tr '\n' ' '
ensure_python_build_installed
$(python_build_path) --definitions | tr '\n' ' '
rm -rf "$tmp_download_dir"
}
download_python_build() {
local tmp_dir="$1"
local pyenv_url="git://github.com/yyuu/pyenv.git"
git clone $pyenv_url $tmp_dir/pyenv
}
list_all

19
bin/utils.sh Normal file
View file

@ -0,0 +1,19 @@
ensure_python_build_installed() {
if [ ! -f "$(python_build_path)" ]; then
download_python_build
fi
}
download_python_build() {
echo "Downloading python-build..."
local pyenv_url="git://github.com/yyuu/pyenv.git"
git clone $pyenv_url "$(pyenv_path)"
}
python_build_path() {
echo "$(pyenv_path)/plugins/python-build/bin/python-build"
}
pyenv_path() {
echo "$(dirname $(dirname $0))/pyenv"
}

View file

@ -3,9 +3,9 @@
source $(dirname $(dirname $0))/lib/utils.sh
run_python() {
plugin_name="python"
local plugin_name="python"
full_version=$(get_preset_version_for $plugin_name)
local full_version=$(get_preset_version_for $plugin_name)
if [ "$full_version" == "" ]; then
echo "No version set for ${plugin_name}"
@ -16,7 +16,7 @@ run_python() {
local short_python_version="${splitted_version[0]}.${splitted_version[1]}"
exec $HOME/.asdf/bin/private/asdf-exec python bin/python${short_python_version} "$@"
exec $(asdf_dir)/bin/private/asdf-exec python bin/python${short_python_version} "$@"
}
run_python "$@"