├── test └── test_helper.bash ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md └── bin └── pyenv-update /test/test_helper.bash: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.swo 2 | *.swp 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | install: git clone https://github.com/sstephenson/bats.git 3 | script: bats/bin/bats --tap test 4 | language: c 5 | notifications: 6 | email: 7 | on_success: never 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Yamashita, Yuu 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pyenv-update 2 | 3 | [![Build Status](https://travis-ci.org/pyenv/pyenv-update.svg?branch=master)](https://travis-ci.org/pyenv/pyenv-update) 4 | 5 | pyenv-update is a [pyenv](https://github.com/pyenv/pyenv) plugin 6 | that provides a `pyenv update` command to update pyenv and its plugins. 7 | 8 | This plugin was inspired from [rbenv-update](https://github.com/rkh/rbenv-update). 9 | 10 | ## Installation 11 | 12 | ### Installing as a pyenv plugin 13 | 14 | Installing pyenv-update as a pyenv plugin will give you access to the 15 | `pyenv update` command. 16 | 17 | ```sh 18 | git clone https://github.com/pyenv/pyenv-update.git $(pyenv root)/plugins/pyenv-update 19 | ``` 20 | 21 | ## Usage 22 | 23 | To update pyenv and plugins (including pyenv-update itself), just type `pyenv update`. 24 | 25 | ```sh 26 | pyenv update 27 | ``` 28 | 29 | ## Version History 30 | 31 | #### 20130531 32 | 33 | * Initial public release. 34 | 35 | ### License 36 | 37 | (The MIT License) 38 | 39 | * Copyright (c) 2013 Yamashita, Yuu 40 | 41 | Permission is hereby granted, free of charge, to any person obtaining 42 | a copy of this software and associated documentation files (the 43 | "Software"), to deal in the Software without restriction, including 44 | without limitation the rights to use, copy, modify, merge, publish, 45 | distribute, sublicense, and/or sell copies of the Software, and to 46 | permit persons to whom the Software is furnished to do so, subject to 47 | the following conditions: 48 | 49 | The above copyright notice and this permission notice shall be 50 | included in all copies or substantial portions of the Software. 51 | 52 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 53 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 54 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 55 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 56 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 57 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 58 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 59 | -------------------------------------------------------------------------------- /bin/pyenv-update: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Summary: Update pyenv, its plugins including the list of available versions 4 | # 5 | # Usage: pyenv update 6 | # 7 | 8 | set -e 9 | [ -n "$PYENV_DEBUG" ] && set -x 10 | 11 | if [ -z "$PYENV_ROOT" ]; then 12 | PYENV_ROOT="${HOME}/.pyenv" 13 | fi 14 | 15 | REMOTE="${PYENV_REMOTE:-origin}" 16 | BRANCH="${PYENV_BRANCH}" 17 | 18 | BRANCH_CHOICE= 19 | ACCEPTED_BRANCHES="master main" 20 | 21 | verify_repo_remote() { 22 | ( cd "$1" && git remote show -n "${REMOTE}" 1>/dev/null 2>&1 ) 23 | } 24 | 25 | verify_repo_branch() { 26 | local name="$(cd "$1" && git name-rev --refs='refs/heads/*' --name-only HEAD 2>/dev/null)" 27 | if [ -z $BRANCH ]; then 28 | [[ " $ACCEPTED_BRANCHES " =~ " ${name} " ]] && BRANCH_CHOICE=$name 29 | else 30 | [[ "${name}" == "${BRANCH}" ]] && BRANCH_CHOICE=$BRANCH 31 | fi 32 | } 33 | 34 | verify_repo_clean() { 35 | ! ( cd "$1" && git status --porcelain ) | grep -q -v '^[!?][!?]' 36 | } 37 | 38 | verify_repo() { 39 | local stat=0 40 | verify_repo_remote "$1" || { 41 | stat="$?" 42 | error "pyenv-update: $1 does not have ${REMOTE}." 43 | } 44 | verify_repo_branch "$1" || { 45 | stat="$?" 46 | if [ -z $BRANCH ]; then 47 | error "pyenv-update: $1 is not on one of the branches: ${ACCEPTED_BRANCHES// /, }" 48 | else 49 | error "pyenv-update: $1 is not on ${BRANCH} branch." 50 | fi 51 | } 52 | verify_repo_clean "$1" || { 53 | stat="$?" 54 | error "pyenv-update: $1 is not clean" 55 | } 56 | return "$stat" 57 | } 58 | 59 | update_repo() { 60 | info "Updating $1..." 61 | verify_repo "$1" && 62 | # pyenv-installer makes the repos shallow, so tags are not fetched by default 63 | # Git 1.8.3 (RHEL/CentOS 7)'s `pull' doesn't support `--tags' 64 | # so we have to fetch as a separate step. 65 | ( 66 | cd "${repo}" && \ 67 | git fetch --tags "${REMOTE}" "${BRANCH_CHOICE}" && \ 68 | git merge --ff "${REMOTE}" "${BRANCH_CHOICE}" 69 | ) 70 | } 71 | 72 | info() { 73 | { printf "\x1B[2;32m" 74 | echo "$@" 75 | printf "\x1B[0m" 76 | } 77 | } 78 | 79 | error() { 80 | { printf "\x1B[1;31m" 81 | echo "$@" 82 | printf "\x1B[0m" 83 | } 1>&2 84 | } 85 | 86 | STATUS=0 87 | shopt -s nullglob 88 | for repo in "${PYENV_ROOT}" "${PYENV_ROOT}/plugins/"*; do 89 | if [ -d "${repo}/.git" ]; then 90 | update_repo "${repo}" || STATUS="$?" 91 | fi 92 | done 93 | shopt -u nullglob 94 | 95 | pyenv rehash || STATUS="$?" 96 | 97 | exit "$STATUS" 98 | --------------------------------------------------------------------------------