Skip to content

Commit

Permalink
cli: python-tools: Use requirements.txt file for Pip dependencies
Browse files Browse the repository at this point in the history
This makes dependencies easier to track and opens up the possibility for Dependabot to update them.
  • Loading branch information
ColorfulRhino authored and igorpecovnik committed Jun 25, 2024
1 parent de81f10 commit 7aadb80
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
33 changes: 11 additions & 22 deletions lib/functions/general/python-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,6 @@
# If you know to tame it, teach me. I'd rather not know about PYTHONUSERBASE and such.
# --rpardini

function early_prepare_pip3_dependencies_for_python_tools() {
# This is like a stupid version of requirements.txt
declare -a -g python3_pip_dependencies=(
"unidiff==0.7.5" # for parsing unified diff
"GitPython==3.1.43" # for manipulating git repos
"unidecode==1.3.8" # for converting strings to ascii
"coloredlogs==15.0.1" # for colored logging
"PyYAML==6.0.1" # for parsing/writing YAML
"oras==0.1.30" # for OCI stuff in mapper-oci-update
"Jinja2==3.1.4" # for templating
"rich==13.7.1" # for rich text formatting
"dtschema" # for checking dts files and dt bindings (use latest version)
"yamllint" # for checking dts files and dt bindings (use latest version)
)
return 0
}

# call: prepare_python_and_pip # this defines global PYTHON3_INFO dict and PYTHON3_VARS array
function prepare_python_and_pip() {
assert_prepared_host # this needs a prepared host to work; avoid fake errors about "python3-pip" not being installed
Expand Down Expand Up @@ -76,9 +59,15 @@ function prepare_python_and_pip() {
display_alert "pip3 version" "${pip3_version_number}: '${pip3_version}'" "info"

# Hash the contents of the dependencies array + the Python version + the release
declare python3_pip_dependencies_path
declare python3_pip_dependencies_hash
early_prepare_pip3_dependencies_for_python_tools
python3_pip_dependencies_hash="$(echo "${HOSTRELEASE}" "${python3_version}" "${pip3_version}" "${python3_pip_dependencies[*]}" | sha256sum | cut -d' ' -f1)"

python3_pip_dependencies_path="${SRC}/requirements.txt"
# Check for the existence of requirements.txt, fail if not found
[[ ! -f "${python3_pip_dependencies_path}" ]] && exit_with_error "Python Pip requirements.txt file not found at path: ${python3_pip_dependencies_path}"

# Calculate the hash for the Pip requirements
python3_pip_dependencies_hash="$(echo "${HOSTRELEASE}" "${python3_version}" "${pip3_version}" "$(cat "${python3_pip_dependencies_path}")" | sha256sum | cut -d' ' -f1)"

declare non_cache_dir="/armbian-pip"
declare python_pip_cache="${SRC}/cache/pip"
Expand Down Expand Up @@ -117,8 +106,8 @@ function prepare_python_and_pip() {
[USERBASE]="${python3_user_base}"
[MODULES_PATH]="${python3_modules_path}"
[PYCACHEPREFIX]="${python3_pycache}"
[HASH]="${python3_pip_dependencies_hash}"
[DEPS]="${python3_pip_dependencies[*]}"
[REQUIREMENTS_HASH]="${python3_pip_dependencies_hash}"
[REQUIREMENTS_PATH]="${python3_pip_dependencies_path}"
[VERSION]="${python3_version}"
[VERSION_STRING]="${python3_version_string}"
[PIP_VERSION]="${pip3_version}"
Expand All @@ -139,7 +128,7 @@ function prepare_python_and_pip() {
# remove the old hashes matching base, don't leave junk behind
run_host_command_logged rm -fv "${python_hash_base}*"

run_host_command_logged env -i "${PYTHON3_VARS[@]@Q}" "${PYTHON3_INFO[BIN]}" -m pip install "${pip3_extra_args[@]}" "${python3_pip_dependencies[@]}"
run_host_command_logged env -i "${PYTHON3_VARS[@]@Q}" "${PYTHON3_INFO[BIN]}" -m pip install "${pip3_extra_args[@]}" -r "${python3_pip_dependencies_path}"

# Create the hash file
run_host_command_logged touch "${python_hash_file}"
Expand Down
17 changes: 17 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Requirements/dependencies for various Python scripts used in the Armbian Build Framework
#
# IMPORTANT NOTES:
# When adding a new requirements, please leave a comment to explain its purpose.
# Always use a fixed version, this is important for correct hashing.
# Dependabot will keep these versions up to date.

unidiff == 0.7.5 # for parsing unified diff
GitPython == 3.1.43 # for manipulating git repos
unidecode == 1.3.8 # for converting strings to ascii
coloredlogs == 15.0.1 # for colored logging
PyYAML == 6.0.1 # for parsing/writing YAML
oras == 0.1.30 # for OCI stuff in mapper-oci-update
Jinja2 == 3.1.4 # for templating
rich == 13.7.1 # for rich text formatting
dtschema == 2024.5 # for checking dts files and dt bindings
yamllint == 1.35.1 # for checking dts files and dt bindings

6 comments on commit 7aadb80

@igorpecovnik
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[🐳|🌱] Python3 version [ 3.10.12 - 'Python 3.10.12' ]
[🐳|🌱] pip3 version [ 22.0.2: 'pip 22.0.2 from /usr/lib/python3/dist-packages/pip (python 3.10)' ]
[🐳|💥] error! [ Python Pip requirements.txt file not found at path: /armbian/requirements.txt ]
Error: error! Python Pip requirements.txt file not found at path: /armbian/requirements.txt

@igorpecovnik
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After:

index b521ef465..40e35e399 100644
--- a/lib/functions/host/docker.sh
+++ b/lib/functions/host/docker.sh
@@ -227,6 +227,7 @@ function docker_cli_prepare_dockerfile() {
                !/compile.sh
                !/lib
                !/extensions
+               !/requirements.txt
                !/config/sources
                !/config/templates
                ${docker_un_ignore_dot_git}

something seems to be bumped too high
https://paste.armbian.com/ezuliwofij.bash

@igorpecovnik
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't find solution in decent time, disabling with #6798

@ColorfulRhino
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@igorpecovnik It seems that the source of the error is

collect2: fatal error: cannot find ‘ld’

Which means ld is missing in PATH. I think I have fixed it, will send a PR soon.

Also, your build host (Ubuntu 22?) seems to use a quite old version of setuptools.

ERROR: setuptools==59.6.0 is used in combination with setuptools_scm>=8.x
[🐳|🔨]         
[🐳|🔨]         Your build configuration is incomplete and previously worked by accident!
[🐳|🔨]         setuptools_scm requires setuptools>=61

I might fix this too.

@igorpecovnik
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, your build host (Ubuntu 22?) seems to use a quite old version of setuptools.

Jammy build host must be support for at least one year.

@ColorfulRhino
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jammy build host must be support for at least one year.

Yes, see my solution here: #6799

Please sign in to comment.