Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(docker-build): add python layer #339

Merged
merged 2 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions .github/citools/common/gh-setup-env
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ main() {

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

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

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

printf "Setup NodeJs symlinks for github user:\n"
printf "Setup NodeJS symlinks for github user:\n"
cd "${HOME}" || track_errors
if [[ ! -d .nodenv ]]; then
ln -sv "/usr/local/nodenv" .nodenv || track_errors
Expand All @@ -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 "${@}"
Loading
Loading