Rework requirements.txt files
cover Rework requirements.txt files
Hey all,
A challenge we've run in to is making it easier for more people to use various python tools that we include in the tree. Part of the problem is that when we have a requirements.txt file, aside from the doc one we share with the kernel, I created it using "pip freeze". And while this might have been a best (or at least OK) practice at the time, that's no longer the case and is why our files have so many things in them. What this series does is create multiple files, one per project/tool and then has CI install them as needed. There's a few places here where this means that we update the requirements as well, but we keep a few big things where they are currently. This is because updating them introduces problems of their own and delaing with that would best be a follow up series. I've put this through GitLab and Azure to make sure everything is still going fine on both platforms.
Signature · 1 line
Tom
PATCH 1/6 python: Create requirements.txt files for each "project"
Rather than have a requirements.txt file that's shared between multiple python projects within U-Boot, create one for each using "pipreqs".
---
Cc: Simon Glass <[email protected]>
--- tools/binman/requirements.txt | 5 +++++ tools/patman/requirements.txt | 5 +++++ tools/u_boot_pylib/requirements.txt | 1 + 3 files changed, 11 insertions(+) create mode 100644 tools/binman/requirements.txt create mode 100644 tools/patman/requirements.txt create mode 100644 tools/u_boot_pylib/requirements.txt
tools/binman/requirements.txt new file +5 -0
@@ -0,0 +1,5 @@ +importlib_resources==6.5.2 +jsonschema==4.23.0 +pycryptodomex==3.21.0 +pyelftools==0.31 +yamllint==1.35.1
tools/patman/requirements.txt new file +5 -0
@@ -0,0 +1,5 @@ +ConfigParser==7.1.0 +importlib_resources==6.5.2 +pygit2==1.13.3 +Requests==2.32.3 +setuptools==75.8.0
tools/u_boot_pylib/requirements.txt new file +1 -0
@@ -0,0 +1 @@ +concurrencytest==0.1.2
Signature · 1 line
2.43.0
PATCH 2/6 CI: Be consistent in creating and starting our virtualenv
In reply to Tom RiniBefore we invoke pip we should always have first created and started our virtualenv. This was done most of the time, but not always.
--- .azure-pipelines.yml | 8 ++++++-- .gitlab-ci.yml | 10 ++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-)
.azure-pipelines.yml +6 -2
@@ -162,6 +162,8 @@ stages: - script: | git config --global --add safe.directory $(work_dir) export USER=azure + virtualenv -p /usr/bin/python3 /tmp/venv + . /tmp/venv/bin/activate pip install -r test/py/requirements.txt pip install -r tools/buildman/requirements.txt pip install asteval pylint==2.12.2 pyopenssl
@@ -264,6 +266,8 @@ stages: if [ -n "\${BUILD_ENV}" ]; then export \${BUILD_ENV}; fi + virtualenv -p /usr/bin/python3 /tmp/venv + . /tmp/venv/bin/activate pip install -r tools/buildman/requirements.txt tools/buildman/buildman -o \${UBOOT_TRAVIS_BUILD_DIR} -w -E -W -e --board \${TEST_PY_BD} \${OVERRIDE} cp /opt/grub/grub_x86.efi \${UBOOT_TRAVIS_BUILD_DIR}/
@@ -288,8 +292,6 @@ stages: /opt/coreboot/cbfstool \${UBOOT_TRAVIS_BUILD_DIR}/coreboot.rom remove -n fallback/payload; /opt/coreboot/cbfstool \${UBOOT_TRAVIS_BUILD_DIR}/coreboot.rom add-flat-binary -f \${UBOOT_TRAVIS_BUILD_DIR}/u-boot.bin -n fallback/payload -c LZMA -l 0x1110000 -e 0x1110000; fi - virtualenv -p /usr/bin/python3 /tmp/venv - . /tmp/venv/bin/activate pip install -r test/py/requirements.txt pip install pytest-azurepipelines export PATH=/opt/qemu/bin:/tmp/uboot-test-hooks/bin:\${PATH}
@@ -581,6 +583,8 @@ stages: # make environment variables available as tests are running inside a container export BUILDMAN="${BUILDMAN}" git config --global --add safe.directory ${WORK_DIR} + virtualenv -p /usr/bin/python3 /tmp/venv + . /tmp/venv/bin/activate pip install -r tools/buildman/requirements.txt EOF cat << "EOF" >> build.sh
.gitlab-ci.yml +8 -2
@@ -55,6 +55,9 @@ stages: wget -O /tmp/fip.bin https://artifacts.codelinaro.org/artifactory/linaro-419-sbsa-ref/latest/tf-a/fip.bin; export BINMAN_INDIRS=/tmp; fi + # Prepare python environment + - virtualenv -p /usr/bin/python3 /tmp/venv; + . /tmp/venv/bin/activate; after_script: - cp -v /tmp/${TEST_PY_BD}/*.{html,css,xml} .
@@ -90,8 +93,6 @@ stages: /opt/coreboot/cbfstool ${UBOOT_TRAVIS_BUILD_DIR}/coreboot.rom remove -n fallback/payload; /opt/coreboot/cbfstool ${UBOOT_TRAVIS_BUILD_DIR}/coreboot.rom add-flat-binary -f ${UBOOT_TRAVIS_BUILD_DIR}/u-boot.bin -n fallback/payload -c LZMA -l 0x1110000 -e 0x1110000; fi - - virtualenv -p /usr/bin/python3 /tmp/venv - - . /tmp/venv/bin/activate - pip install -r test/py/requirements.txt # "${var:+"-k $var"}" expands to "" if $var is empty, "-k $var" if not - export PATH=/opt/qemu/bin:/tmp/uboot-test-hooks/bin:${PATH};
@@ -120,6 +121,9 @@ build all platforms in a single job: tags: - ${HOST} script: + # Prepare python environment + - virtualenv -p /usr/bin/python3 /tmp/venv; + . /tmp/venv/bin/activate; - ret=0; git config --global --add safe.directory "${CI_PROJECT_DIR}"; pip install -r tools/buildman/requirements.txt;
@@ -199,6 +203,8 @@ Run pylint: extends: .testsuites script: - git config --global --add safe.directory "${CI_PROJECT_DIR}" + - virtualenv -p /usr/bin/python3 /tmp/venv + - . /tmp/venv/bin/activate - pip install -r test/py/requirements.txt - pip install -r tools/buildman/requirements.txt - pip install asteval pylint==2.12.2 pyopenssl
Signature · 1 line
2.43.0
PATCH 3/6 CI: Consistently install our requirements.txt files
In reply to Tom RiniWe should install all of our requirements.txt files after starting the virtualenv rather than ad-hoc throughout each test.
--- .azure-pipelines.yml | 13 +++++++++++-- .gitlab-ci.yml | 14 ++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-)
.azure-pipelines.yml +11 -2
@@ -134,7 +134,10 @@ stages: virtualenv -p /usr/bin/python3 /tmp/venv . /tmp/venv/bin/activate pip install -r test/py/requirements.txt + pip install -r tools/binman/requirements.txt pip install -r tools/buildman/requirements.txt + pip install -r tools/patman/requirements.txt + pip install -r tools/u_boot_pylib/requirements.txt export UBOOT_TRAVIS_BUILD_DIR=/tmp/tools-only export PYTHONPATH=${UBOOT_TRAVIS_BUILD_DIR}/scripts/dtc/pylibfdt export PATH=${UBOOT_TRAVIS_BUILD_DIR}/scripts/dtc:${PATH}
@@ -165,7 +168,10 @@ stages: virtualenv -p /usr/bin/python3 /tmp/venv . /tmp/venv/bin/activate pip install -r test/py/requirements.txt + pip install -r tools/binman/requirements.txt pip install -r tools/buildman/requirements.txt + pip install -r tools/patman/requirements.txt + pip install -r tools/u_boot_pylib/requirements.txt pip install asteval pylint==2.12.2 pyopenssl export PATH=${PATH}:~/.local/bin echo "[MASTER]" >> .pylintrc
@@ -268,7 +274,11 @@ stages: fi virtualenv -p /usr/bin/python3 /tmp/venv . /tmp/venv/bin/activate + pip install -r tools/binman/requirements.txt pip install -r tools/buildman/requirements.txt + pip install -r test/py/requirements.txt + pip install -r tools/u_boot_pylib/requirements.txt + pip install pytest-azurepipelines tools/buildman/buildman -o \${UBOOT_TRAVIS_BUILD_DIR} -w -E -W -e --board \${TEST_PY_BD} \${OVERRIDE} cp /opt/grub/grub_x86.efi \${UBOOT_TRAVIS_BUILD_DIR}/ cp /opt/grub/grub_x64.efi \${UBOOT_TRAVIS_BUILD_DIR}/
@@ -292,8 +302,6 @@ stages: /opt/coreboot/cbfstool \${UBOOT_TRAVIS_BUILD_DIR}/coreboot.rom remove -n fallback/payload; /opt/coreboot/cbfstool \${UBOOT_TRAVIS_BUILD_DIR}/coreboot.rom add-flat-binary -f \${UBOOT_TRAVIS_BUILD_DIR}/u-boot.bin -n fallback/payload -c LZMA -l 0x1110000 -e 0x1110000; fi - pip install -r test/py/requirements.txt - pip install pytest-azurepipelines export PATH=/opt/qemu/bin:/tmp/uboot-test-hooks/bin:\${PATH} export PYTHONPATH=/tmp/uboot-test-hooks/py/travis-ci # "\${var:+"-k \$var"}" expands to "" if \$var is empty, "-k \$var" if not
@@ -585,6 +593,7 @@ stages: git config --global --add safe.directory ${WORK_DIR} virtualenv -p /usr/bin/python3 /tmp/venv . /tmp/venv/bin/activate + pip install -r tools/binman/requirements.txt pip install -r tools/buildman/requirements.txt EOF cat << "EOF" >> build.sh
.gitlab-ci.yml +12 -2
@@ -58,6 +58,10 @@ stages: # Prepare python environment - virtualenv -p /usr/bin/python3 /tmp/venv; . /tmp/venv/bin/activate; + pip install -r test/py/requirements.txt; + pip install -r tools/binman/requirements.txt; + pip install -r tools/buildman/requirements.txt; + pip install -r tools/u_boot_pylib/requirements.txt; after_script: - cp -v /tmp/${TEST_PY_BD}/*.{html,css,xml} .
@@ -93,7 +97,6 @@ stages: /opt/coreboot/cbfstool ${UBOOT_TRAVIS_BUILD_DIR}/coreboot.rom remove -n fallback/payload; /opt/coreboot/cbfstool ${UBOOT_TRAVIS_BUILD_DIR}/coreboot.rom add-flat-binary -f ${UBOOT_TRAVIS_BUILD_DIR}/u-boot.bin -n fallback/payload -c LZMA -l 0x1110000 -e 0x1110000; fi - - pip install -r test/py/requirements.txt # "${var:+"-k $var"}" expands to "" if $var is empty, "-k $var" if not - export PATH=/opt/qemu/bin:/tmp/uboot-test-hooks/bin:${PATH}; export PYTHONPATH=/tmp/uboot-test-hooks/py/travis-ci;
@@ -124,9 +127,10 @@ build all platforms in a single job: # Prepare python environment - virtualenv -p /usr/bin/python3 /tmp/venv; . /tmp/venv/bin/activate; + pip install -r tools/binman/requirements.txt; + pip install -r tools/buildman/requirements.txt - ret=0; git config --global --add safe.directory "${CI_PROJECT_DIR}"; - pip install -r tools/buildman/requirements.txt; ./tools/buildman/buildman -o /tmp -PEWM -x xtensa || ret=$?; if [[ $ret -ne 0 ]]; then ./tools/buildman/buildman -o /tmp -seP;
@@ -184,7 +188,10 @@ Run binman, buildman, dtoc, Kconfig and patman testsuites: virtualenv -p /usr/bin/python3 /tmp/venv; . /tmp/venv/bin/activate; pip install -r test/py/requirements.txt; + pip install -r tools/binman/requirements.txt; pip install -r tools/buildman/requirements.txt; + pip install -r tools/patman/requirements.txt; + pip install -r tools/u_boot_pylib/requirements.txt; export UBOOT_TRAVIS_BUILD_DIR=/tmp/tools-only; export PYTHONPATH="${UBOOT_TRAVIS_BUILD_DIR}/scripts/dtc/pylibfdt"; export PATH="${UBOOT_TRAVIS_BUILD_DIR}/scripts/dtc:${PATH}";
@@ -206,7 +213,10 @@ Run pylint: - virtualenv -p /usr/bin/python3 /tmp/venv - . /tmp/venv/bin/activate - pip install -r test/py/requirements.txt + - pip install -r tools/binman/requirements.txt - pip install -r tools/buildman/requirements.txt + - pip install -r tools/patman/requirements.txt + - pip install -r tools/u_boot_pylib/requirements.txt - pip install asteval pylint==2.12.2 pyopenssl - export PATH=${PATH}:~/.local/bin - echo "[MASTER]" >> .pylintrc
Signature · 1 line
2.43.0
PATCH 4/6 CI: Invoke pip once rather than multiple times
In reply to Tom RiniWe can invoke pip once to install the various requirements.txt files that we need rather than invoking the tool multiple times.
--- .azure-pipelines.yml | 36 ++++++++++++++++++------------------ .gitlab-ci.yml | 27 ++++++++++----------------- 2 files changed, 28 insertions(+), 35 deletions(-)
.azure-pipelines.yml +18 -18
@@ -133,11 +133,11 @@ stages: export USER=azure virtualenv -p /usr/bin/python3 /tmp/venv . /tmp/venv/bin/activate - pip install -r test/py/requirements.txt - pip install -r tools/binman/requirements.txt - pip install -r tools/buildman/requirements.txt - pip install -r tools/patman/requirements.txt - pip install -r tools/u_boot_pylib/requirements.txt + pip install -r test/py/requirements.txt \ + -r tools/binman/requirements.txt \ + -r tools/buildman/requirements.txt \ + -r tools/patman/requirements.txt \ + -r tools/u_boot_pylib/requirements.txt export UBOOT_TRAVIS_BUILD_DIR=/tmp/tools-only export PYTHONPATH=${UBOOT_TRAVIS_BUILD_DIR}/scripts/dtc/pylibfdt export PATH=${UBOOT_TRAVIS_BUILD_DIR}/scripts/dtc:${PATH}
@@ -167,12 +167,12 @@ stages: export USER=azure virtualenv -p /usr/bin/python3 /tmp/venv . /tmp/venv/bin/activate - pip install -r test/py/requirements.txt - pip install -r tools/binman/requirements.txt - pip install -r tools/buildman/requirements.txt - pip install -r tools/patman/requirements.txt - pip install -r tools/u_boot_pylib/requirements.txt - pip install asteval pylint==2.12.2 pyopenssl + pip install -r test/py/requirements.txt \ + -r tools/binman/requirements.txt \ + -r tools/buildman/requirements.txt \ + -r tools/patman/requirements.txt \ + -r tools/u_boot_pylib/requirements.txt \ + asteval pylint==2.12.2 pyopenssl export PATH=${PATH}:~/.local/bin echo "[MASTER]" >> .pylintrc echo "load-plugins=pylint.extensions.docparams" >> .pylintrc
@@ -274,11 +274,11 @@ stages: fi virtualenv -p /usr/bin/python3 /tmp/venv . /tmp/venv/bin/activate - pip install -r tools/binman/requirements.txt - pip install -r tools/buildman/requirements.txt - pip install -r test/py/requirements.txt - pip install -r tools/u_boot_pylib/requirements.txt - pip install pytest-azurepipelines + pip install -r tools/binman/requirements.txt \ + -r tools/buildman/requirements.txt \ + -r test/py/requirements.txt \ + -r tools/u_boot_pylib/requirements.txt \ + pytest-azurepipelines tools/buildman/buildman -o \${UBOOT_TRAVIS_BUILD_DIR} -w -E -W -e --board \${TEST_PY_BD} \${OVERRIDE} cp /opt/grub/grub_x86.efi \${UBOOT_TRAVIS_BUILD_DIR}/ cp /opt/grub/grub_x64.efi \${UBOOT_TRAVIS_BUILD_DIR}/
@@ -593,8 +593,8 @@ stages: git config --global --add safe.directory ${WORK_DIR} virtualenv -p /usr/bin/python3 /tmp/venv . /tmp/venv/bin/activate - pip install -r tools/binman/requirements.txt - pip install -r tools/buildman/requirements.txt + pip install -r tools/binman/requirements.txt \ + -r tools/buildman/requirements.txt EOF cat << "EOF" >> build.sh if [[ "${BUILDMAN}" != "" ]]; then
.gitlab-ci.yml +10 -17
@@ -58,10 +58,8 @@ stages: # Prepare python environment - virtualenv -p /usr/bin/python3 /tmp/venv; . /tmp/venv/bin/activate; - pip install -r test/py/requirements.txt; - pip install -r tools/binman/requirements.txt; - pip install -r tools/buildman/requirements.txt; - pip install -r tools/u_boot_pylib/requirements.txt; + pip install -r test/py/requirements.txt -r tools/binman/requirements.txt + -r tools/buildman/requirements.txt -r tools/u_boot_pylib/requirements.txt after_script: - cp -v /tmp/${TEST_PY_BD}/*.{html,css,xml} .
@@ -127,8 +125,8 @@ build all platforms in a single job: # Prepare python environment - virtualenv -p /usr/bin/python3 /tmp/venv; . /tmp/venv/bin/activate; - pip install -r tools/binman/requirements.txt; - pip install -r tools/buildman/requirements.txt + pip install -r tools/binman/requirements.txt + -r tools/buildman/requirements.txt - ret=0; git config --global --add safe.directory "${CI_PROJECT_DIR}"; ./tools/buildman/buildman -o /tmp -PEWM -x xtensa || ret=$?;
@@ -187,11 +185,9 @@ Run binman, buildman, dtoc, Kconfig and patman testsuites: export USER=gitlab; virtualenv -p /usr/bin/python3 /tmp/venv; . /tmp/venv/bin/activate; - pip install -r test/py/requirements.txt; - pip install -r tools/binman/requirements.txt; - pip install -r tools/buildman/requirements.txt; - pip install -r tools/patman/requirements.txt; - pip install -r tools/u_boot_pylib/requirements.txt; + pip install -r test/py/requirements.txt -r tools/binman/requirements.txt + -r tools/buildman/requirements.txt -r tools/patman/requirements.txt + -r tools/u_boot_pylib/requirements.txt; export UBOOT_TRAVIS_BUILD_DIR=/tmp/tools-only; export PYTHONPATH="${UBOOT_TRAVIS_BUILD_DIR}/scripts/dtc/pylibfdt"; export PATH="${UBOOT_TRAVIS_BUILD_DIR}/scripts/dtc:${PATH}";
@@ -212,12 +208,9 @@ Run pylint: - git config --global --add safe.directory "${CI_PROJECT_DIR}" - virtualenv -p /usr/bin/python3 /tmp/venv - . /tmp/venv/bin/activate - - pip install -r test/py/requirements.txt - - pip install -r tools/binman/requirements.txt - - pip install -r tools/buildman/requirements.txt - - pip install -r tools/patman/requirements.txt - - pip install -r tools/u_boot_pylib/requirements.txt - - pip install asteval pylint==2.12.2 pyopenssl + - pip install -r test/py/requirements.txt -r tools/binman/requirements.txt + -r tools/buildman/requirements.txt -r tools/patman/requirements.txt + -r tools/u_boot_pylib/requirements.txt asteval pylint==2.12.2 pyopenssl - export PATH=${PATH}:~/.local/bin - echo "[MASTER]" >> .pylintrc - echo "load-plugins=pylint.extensions.docparams" >> .pylintrc
Signature · 1 line
2.43.0
PATCH 5/6 python: Recreate test/py and tools/buildman requirements.txt files
In reply to Tom RiniUse the "pipreqs" tool to re-create these files, with a few manual corrections. We still need to include pytest-xdist which the tool does not detect. We also for now don't upgrade most of the required tools as that creates problems with various tests, which should be resolved independently.
---
Cc: Simon Glass <[email protected]>
--- test/py/requirements.txt | 28 +--------------------------- tools/buildman/requirements.txt | 7 ++----- 2 files changed, 3 insertions(+), 32 deletions(-)
test/py/requirements.txt +1 -27
@@ -1,30 +1,4 @@ -atomicwrites==1.4.1 -attrs==19.3.0 -concurrencytest==0.1.2 -coverage==6.2 -extras==1.0.0 filelock==3.0.12 -fixtures==3.0.0 -importlib-metadata==0.23 -linecache2==1.0.0 -more-itertools==7.2.0 -packaging==24.1 -pbr==5.4.3 -pluggy==0.13.0 -py==1.11.0 -pycryptodomex==3.19.1 -pyelftools==0.27 -pygit2==1.13.3 -pyparsing==3.0.7 +pycryptodomex==3.21.0 pytest==6.2.5 pytest-xdist==2.5.0 -python-mimeparse==1.6.0 -python-subunit==1.3.0 -requests==2.32.3 -setuptools==70.3.0 -six==1.16.0 -testtools==2.3.0 -traceback2==1.4.0 -unittest2==1.1.0 -wcwidth==0.1.7 -zipp==3.19.2
tools/buildman/requirements.txt +2 -5
@@ -1,5 +1,2 @@ -coverage==6.2 -jsonschema==4.17.3 -pycryptodome==3.20 -pyyaml==6.0 -yamllint==1.26.3 +filelock==3.0.12 +importlib_resources==6.5.2
Signature · 1 line
2.43.0
PATCH 6/6 Dockerfile: Update for having more requirements.txt files
In reply to Tom RiniNow that we have more requirements.txt files we need to grab all of them for creating our cache. Also, we do longer should install python3-pyelftools on the host as it's not used.
--- tools/docker/Dockerfile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
tools/docker/Dockerfile +7 -2
@@ -122,7 +122,6 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ python3 \ python3-dev \ python3-pip \ - python3-pyelftools \ python3-sphinx \ python3-virtualenv \ rpm2cpio \
@@ -308,12 +307,18 @@ USER uboot:uboot # COPY / ADD directives don't work as we need them to. RUN wget -O /tmp/pytest-requirements.txt https://source.denx.de/u-boot/u-boot/-/raw/master/test/py/requirements.txt RUN wget -O /tmp/sphinx-requirements.txt https://source.denx.de/u-boot/u-boot/-/raw/master/doc/sphinx/requirements.txt +RUN wget -O /tmp/binman-requirements.txt https://source.denx.de/u-boot/u-boot/-/raw/master/tools/binman/requirements.txt RUN wget -O /tmp/buildman-requirements.txt https://source.denx.de/u-boot/u-boot/-/raw/master/tools/buildman/requirements.txt +RUN wget -O /tmp/patman-requirements.txt https://source.denx.de/u-boot/u-boot/-/raw/master/tools/patman/requirements.txt +RUN wget -O /tmp/u_boot_pylib-requirements.txt https://source.denx.de/u-boot/u-boot/-/raw/master/tools/u_boot_pylib/requirements.txt RUN virtualenv -p /usr/bin/python3 /tmp/venv && \ . /tmp/venv/bin/activate && \ pip install -r /tmp/pytest-requirements.txt \ -r /tmp/sphinx-requirements.txt \ - -r /tmp/buildman-requirements.txt && \ + -r /tmp/binman-requirements.txt \ + -r /tmp/buildman-requirements.txt \ + -r /tmp/patman-requirements.txt \ + -r /tmp/u_boot_pylib-requirements.txt && \ deactivate && \ rm -rf /tmp/venv /tmp/*-requirements.txt
Signature · 1 line
2.43.0
Quoted 16 lines · Tom Rini
Hey all,
A challenge we've run in to is making it easier for more people to use various python tools that we include in the tree. Part of the problem is that when we have a requirements.txt file, aside from the doc one we share with the kernel, I created it using "pip freeze". And while this might have been a best (or at least OK) practice at the time, that's no longer the case and is why our files have so many things in them. What this series does is create multiple files, one per project/tool and then has CI install them as needed. There's a few places here where this means that we update the requirements as well, but we keep a few big things where they are currently. This is because updating them introduces problems of their own and delaing with that would best be a follow up series. I've put this through GitLab and Azure to make sure everything is still going fine on both platforms.
Quoted 1 line
[...]
Applied to u-boot/next, thanks!
Signature · 1 line
Tom