File: build-pyenvs.sh

package info (click to toggle)
cmd2 2.5.11%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,244 kB
  • sloc: python: 19,643; makefile: 73; sh: 67; javascript: 30
file content (53 lines) | stat: -rw-r--r-- 1,733 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env bash
#

# create pyenv environments for each minor version of python
# supported by this project
#
# this script uses terms from Semantic Versioning https://semver.org/
# version numbers are: major.minor.patch
#
# this script will delete and recreate existing virtualenvs named
# cmd2-3.8, etc. It will also create a .python-version
#
# Prerequisites:
#   - *nix-ish environment like macOS or Linux
#   - pyenv installed
#   - pyenv-virtualenv installed
#   - readline and openssl libraries installed so pyenv can
#     build pythons
#

# Make a array of the python minor versions we want to install.
# Order matters in this list, because it's the order that the
# virtualenvs will be added to '.python-version'. Feel free to modify
# this list, but note that this script intentionally won't install
# dev, rc, or beta python releases
declare -a pythons=("3.8" "3.9" "3.10" "3.11", "3.12")

# function to find the latest patch of a minor version of python
function find_latest_version {
    pyenv install -l | \
    sed -En -e "s/^ *//g" -e "/(dev|b|rc)/d" -e "/^$1/p" | \
    tail -1
}

# empty out '.python-version'
> .python-version

# loop through the pythons
for minor_version in "${pythons[@]}"
do
    patch_version=$( find_latest_version "$minor_version" )
    # use pyenv to install the latest versions of python
    # if it's already installed don't install it again
    pyenv install -s "$patch_version"

    envname="cmd2-$minor_version"
    # remove the associated virtualenv
    pyenv uninstall -f "$envname"
    # create a new virtualenv
    pyenv virtualenv -p "python$minor_version" "$patch_version" "$envname"
    # append the virtualenv to .python-version
    echo "$envname" >> .python-version
done