Skip to content

Commit

Permalink
ci(docker-build): add python layer
Browse files Browse the repository at this point in the history
  • Loading branch information
vpayno committed Jan 16, 2024
1 parent 187e193 commit 50491b3
Show file tree
Hide file tree
Showing 9 changed files with 500 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/citools/common/gh-setup-env
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,26 @@ main() {

print_ruler

source /etc/profile.d/python.sh || track_errors

printf "Adding Python paths to GITHUB_PATH...\n"
printf "%s\n" "/usr/local/pyenv/bin" "/usr/local/pyenv/shims" | tee -a "${GITHUB_PATH}"

echo Adding source /etc/profile.d/ruby.sh to ~/.bashrc
echo '. /etc/profile.d/ruby.sh' | tee -a "${HOME}/.bashrc" || track_errors
printf "\n"

printf "Setup Python symlinks for github user:\n"
cd "${HOME}" || track_errors
if [[ ! -d .pyenv ]]; then
ln -sv "/usr/local/pyenv" .pyenv || track_errors
fi
ls -l ~/.pyenv
cd - || track_errors
printf "\n"

print_ruler

tail -n 1000 -v "${GITHUB_PATH}"

print_ruler
Expand Down
27 changes: 27 additions & 0 deletions .github/citools/includes/wrapper-library
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,30 @@ show_tool_versions_node() {
# md_code_tag
printf "\n"
} # show_tool_versions_node()

show_tool_versions_python_short() {
# md_code_tag text
printf "Python versions:\n"
printf "\n"
python --version | paste /dev/null -
pyenv --version | paste /dev/null -
pip --version | paste /dev/null -
pdm --version | paste /dev/null -
# md_code_tag
printf "\n"
} # show_tool_versions_python_short()

show_tool_versions_python() {
show_tool_versions_python_short

if [[ -z ${GITHUB_ACTIONS} ]]; then
return
fi

# md_code_tag text
printf "Installed Python packages:\n"
printf "\n"
pip list | paste /dev/null -
# md_code_tag
printf "\n"
} # show_tool_versions_python()
26 changes: 26 additions & 0 deletions .github/citools/python/python-lint-formatter
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
#
# .github/citools/python/python-lint-formatter
#

# shellcheck disable=SC1091
source ../../.github/citools/includes/wrapper-library || exit

declare -i retval=0

main() {
printf "\nRunning Python Formatter\n\n"

show_tool_versions_python_short

print_ruler

run_command ruff .

print_ruler

echo Exit code: "${retval}"
return "${retval}"
}

time main "${@}"
24 changes: 24 additions & 0 deletions .github/citools/python/python-setup-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
#
# .github/citools/python/python-setup-config
#

# shellcheck disable=SC1091
source ../../.github/citools/includes/wrapper-library || exit

declare -i retval=0

main() {
printf "Setup Python Environment\n\n"

print_ruler

../../.github/citools/common/gh-setup-env || track_errors

print_ruler

echo Exit code: "${retval}"
return "${retval}"
}

time main "${@}"
227 changes: 227 additions & 0 deletions .github/citools/python/python-setup-install
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
#!/bin/bash
#
# .github/citools/python/python-setup-install
#

# shellcheck disable=SC1091
source ../../.github/citools/includes/wrapper-library || exit

declare -i retval=0

main() {
printf "Python Installation\n\n"

print_ruler

echo Running: sudo apt update
time sudo apt update || track_errors

print_ruler

local -a debs
debs=(
autoconf
automake
bc
bison
build-essential
curl
g++
gcc
git
gnupg
libbz2-dev
libc6-dev
libffi-dev
libgdbm-dev
libgmp-dev
liblzma-dev
libncurses5-dev
libreadline-dev
libsqlite3-dev
libssl-dev
libtool
libyaml-dev
make
pkg-config
sqlite3
zlib1g-dev
)

echo Running: sudo apt install -y "${debs[@]}"
time sudo apt install -y "${debs[@]}" || track_errors

print_ruler

echo Running: export PYTHON_CONFIGURE_OPTS="--enable-shared"
export PYTHON_CONFIGURE_OPTS="--enable-shared"

print_ruler

export PYENV_ROOT="/usr/local/pyenv"

echo Running: git clone --depth=1 https://github.com/pyenv/pyenv.git "${PYENV_ROOT}"
git clone --depth=1 https://github.com/pyenv/pyenv.git "${PYENV_ROOT}" || track_errors

print_ruler

echo Running: git clone https://github.com/pyenv/pyenv-virtualenv.git "${PYENV_ROOT}"/plugins/pyenv-virtualenv
git clone https://github.com/pyenv/pyenv-virtualenv.git "${PYENV_ROOT}"/plugins/pyenv-virtualenv || track_errors

print_ruler

{ cd "${PYENV_ROOT}" && time src/configure && time make -C src; } || track_errors

print_ruler

printf "Configuring Shell: "
tee /etc/profile.d/python.sh <<-EOF
#
# /etc/profile.d/python.sh
#
export PYENV_ROOT="/usr/local/pyenv"
if [[ ! \${PATH} =~ \${PYENV_ROOT}/bin ]]; then
export PATH="\${PYENV_ROOT}/bin:\${PATH}"
fi
if command -v pyenv 1>/dev/null 2>&1; then
if [[ ! \${PATH} =~ \${PYENV_ROOT}/shims ]]; then
eval "\$(pyenv init --path)"
fi
if [[ -z \${PYENV_SHELL} ]]; then
eval "\$(pyenv init -)"
fi
if [[ ! \${PATH} =~ \${PYENV_ROOT}/plugins/pyenv-virtualenv/shims ]]; then
eval "\$(pyenv virtualenv-init -)"
fi
fi
EOF
printf "done\n"

# shellcheck disable=SC1090
echo Running: source /etc/profile.d/python.sh
source /etc/profile.d/python.sh || track_errors
printf "done\n"

print_ruler

echo Running: pyenv -v
time pyenv -v || track_errors

print_ruler

echo Running: pyenv install --list
time pyenv install --list || track_errors

print_ruler

local python_version
python_version="$(pyenv install --list | grep -E "^\s+3" | grep -v -- -dev | grep -v "[a-z]" | tr -d ' ' | tail -n 1)" || track_errors

echo Running: pyenv install "${python_version}"
time pyenv install "${python_version}" || track_errors

print_ruler

echo Running: pyenv global "${python_version}"
time pyenv global "${python_version}" || track_errors

print_ruler

echo Running: python --version
time python --version || track_errors

print_ruler

local -a pip_packages
pip_packages=(
ansible-lint
bandit[toml]
black
coverage
dagger-io
db-sqlite3
flake8
flawfinder
flynt
ipykernel
ipython
isort
itsdangerous
jsonlint
jsonschema
mccabe
mypy
mypy-extensions
pep8
pep8-naming
pexpect
proselint
prospector
pycobertura
pycodestyle
pydantic
pydocstyle
pyflakes
pylint
pylint-flask
pyright
pysqlite3
pytest
pytest-cov
pytest-docker
pytest-randomly
python-dateutil
python-lsp-black
python-lsp-jsonrpc
python-lsp-ruff
python-lsp-server
python-utils
pytype
refurb
rich-cli
ruff
safety
textual[dev]
textualize_see
tmuxp
toml
tomli
tomlkit
typeguard
types-Pygments
types-colorama
types-docutils
types-mock
types-setuptools
typing_extensions
xmlformatter
yamlfix
yamllint
yapf
)

echo Running: pip install --upgrade pip
time pip install --upgrade pip || track_errors

print_ruler

echo Running: pip install pdm
time pip install pdm || track_errors

print_ruler

echo Running: pip install "${pip_packages[@]}"
time pip install "${pip_packages[@]}" || track_errors

print_ruler

echo Exit code: "${retval}"
return "${retval}"
}

time main "${@}"
59 changes: 59 additions & 0 deletions .github/citools/python/python-setup-verify
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash
#
# .github/citools/python/python-setup-verify
#

# shellcheck disable=SC1091
source ../../.github/citools/includes/wrapper-library || exit

declare -i retval=0

declare -A python_cmds

python_cmds=(
[python]=$(
command -v python >&/dev/null
echo "$?"
)
[pyenv]=$(
command -v pyenv >&/dev/null
echo "$?"
)
[pip]=$(
command -v pip >&/dev/null
echo "$?"
)
)

main() {
printf "Verifying Python Installation\n\n"

print_ruler

echo Running: source /etc/profile.d/python.sh
source /etc/profile.d/python.sh || track_errors

print_ruler

for key in "${!python_cmds[@]}"; do
if [[ ${python_cmds[${key}]} -ne 0 ]]; then
printf "ERROR: command [%s] not found.\n" "${key}"
((retval++))
fi
done

if [[ ${retval} -ne 0 ]]; then
return "${retval}"
fi

print_ruler

show_tool_versions_python

print_ruler

echo Exit code: "${retval}"
return "${retval}"
}

time main "${@}"
Loading

0 comments on commit 50491b3

Please sign in to comment.