From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Cc: "Michał Górny" <mgorny@gentoo.org>
Subject: [gentoo-dev] [PATCH 03/11] install-qa-check.d: Rewrite 60python-pyc to use gpep517
Date: Fri, 29 Jul 2022 12:30:55 +0200 [thread overview]
Message-ID: <20220729103103.1185162-4-mgorny@gentoo.org> (raw)
In-Reply-To: <20220729103103.1185162-1-mgorny@gentoo.org>
Signed-off-by: Michał Górny <mgorny@gentoo.org>
---
metadata/install-qa-check.d/60python-pyc | 168 +++++++++++++----------
1 file changed, 96 insertions(+), 72 deletions(-)
diff --git a/metadata/install-qa-check.d/60python-pyc b/metadata/install-qa-check.d/60python-pyc
index 47e9a3eea908..fd9434994f2f 100644
--- a/metadata/install-qa-check.d/60python-pyc
+++ b/metadata/install-qa-check.d/60python-pyc
@@ -4,86 +4,110 @@
# QA check: ensure that Python modules are compiled after installing
# Maintainer: Python project <python@gentoo.org>
-# EAPI guard to prevent errors from trying to import python-utils-r1
-# in unsupported EAPIs. Please keep the list in sync with the eclass!
-if [[ ${EAPI} == [6-8] ]]; then
- inherit python-utils-r1
+python_pyc_check() {
+ local save=$(shopt -p nullglob)
+ shopt -s nullglob
+ local progs=( "${EPREFIX}"/usr/lib/python-exec/*/gpep517 )
+ ${save}
- python_pyc_check() {
- local impl missing=() outdated=()
- for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
- _python_export "${impl}" EPYTHON PYTHON
- [[ -x ${PYTHON} ]] || continue
- local sitedir=$(python_get_sitedir "${impl}")
+ local invalid=()
+ local mismatched_timestamp=()
+ local mismatched_data=()
+ local missing=()
+ local stray=()
- if [[ -d ${D}${sitedir} ]]; then
- local suffixes=() subdir=
- case ${EPYTHON} in
- python2*)
- suffixes=( .py{c,o} )
- ;;
- pypy)
- suffixes=( .pyc )
- ;;
- python3*|pypy3*)
- local tag=$("${PYTHON}" -c 'import sys; print(sys.implementation.cache_tag)')
- suffixes=( ".${tag}"{,.opt-{1,2}}.pyc )
- subdir=__pycache__/
- ;;
- *)
- # skip testing unknown impl
- continue
- ;;
- esac
+ for prog in "${progs[@]}"; do
+ local impl=${prog%/*}
+ impl=${impl##*/}
+ einfo "Verifying compiled files for ${impl}"
+ local kind pyc py
+ while IFS=: read -r kind pyc py extra; do
+ case ${kind} in
+ invalid)
+ invalid+=( "${pyc}" )
+ ;;
+ mismatched)
+ case ${extra} in
+ timestamp)
+ mismatched_timestamp+=( "${pyc}" )
+ ;;
+ *)
+ mismatched_data+=( "${pyc}" )
+ ;;
+ esac
+ ;;
+ missing)
+ missing+=( "${pyc}" )
+ ;;
+ older)
+ # older warnings were produced by earlier version
+ # of gpep517 but the check was incorrect, so we just
+ # ignore them
+ ;;
+ stray)
+ stray+=( "${pyc}" )
+ ;;
+ esac
+ done < <("${prog}" verify-pyc --destdir "${D}" --prefix "${EPREFIX}"/usr)
+ done
- einfo "Verifying compiled files in ${sitedir}"
- local f s
- while read -d $'\0' -r f; do
- local dir=${f%/*}
- local basename=${f##*/}
- basename=${basename%.py}
+ local found=
+ if [[ ${missing[@]} ]]; then
+ eqawarn
+ eqawarn "QA Notice: This package installs one or more Python modules that are"
+ eqawarn "not byte-compiled."
+ eqawarn "The following files are missing:"
+ eqawarn
+ eqatag -v python-pyc.missing "${missing[@]}"
+ found=1
+ fi
- for s in "${suffixes[@]}"; do
- local cache=${dir}/${subdir}${basename}${s}
- if [[ ! -f ${cache} ]]; then
- missing+=( "${cache}" )
- elif [[ ${f} -nt ${cache} ]]; then
- outdated+=( "${cache}" )
- fi
- done
- done < <(find "${D}${sitedir}" -name '*.py' -print0)
- fi
- done
+ if [[ ${invalid[@]} ]]; then
+ eqawarn
+ eqawarn "QA Notice: This package installs one or more compiled Python modules"
+ eqawarn "that seem to be invalid (do not have the correct header)."
+ eqawarn "The following files are invalid:"
+ eqawarn
+ eqatag -v python-pyc.invalid "${invalid[@]}"
+ found=1
+ fi
- if [[ ${missing[@]} ]]; then
- eqawarn
- eqawarn "QA Notice: This package installs one or more Python modules that are"
- eqawarn "not byte-compiled."
- eqawarn "The following files are missing:"
- eqawarn
- eqatag -v python-pyc.missing "${missing[@]#${D}}"
- fi
+ if [[ ${mismatched_data[@]} ]]; then
+ eqawarn
+ eqawarn "QA Notice: This package installs one or more compiled Python modules whose"
+ eqawarn ".py files have different content (size or hash) than recorded:"
+ eqawarn
+ eqatag -v python-pyc.mismatched.data "${mismatched_data[@]}"
+ found=1
+ fi
- if [[ ${outdated[@]} ]]; then
- eqawarn
- eqawarn "QA Notice: This package installs one or more compiled Python modules that have"
- eqawarn "older timestamps than the corresponding source files:"
- eqawarn
- eqatag -v python-pyc.outdated "${outdated[@]#${D}}"
- fi
+ if [[ ${mismatched_timestamp[@]} ]]; then
+ eqawarn
+ eqawarn "QA Notice: This package installs one or more compiled Python modules whose"
+ eqawarn ".py files have different timestamps than recorded:"
+ eqawarn
+ eqatag -v python-pyc.mismatched.timestamp "${mismatched_timestamp[@]}"
+ found=1
+ fi
- if [[ ${missing[@]} || ${outdated[@]} ]]; then
- eqawarn
- eqawarn "Please either fix the upstream build system to byte-compile Python modules"
- eqawarn "correctly, or call python_optimize after installing them. For more"
- eqawarn "information, see:"
- eqawarn "https://projects.gentoo.org/python/guide/helper.html#byte-compiling-python-modules"
- eqawarn
- fi
- }
+ if [[ ${stray[@]} ]]; then
+ eqawarn
+ eqawarn "QA Notice: This package installs one or more compiled Python modules"
+ eqawarn "that do not match installed modules (or their implementation)."
+ eqawarn "The following files are stray:"
+ eqawarn
+ eqatag -v python-pyc.stray "${stray[@]}"
+ found=1
+ fi
- python_pyc_check
-fi
+ if [[ ${found} ]]; then
+ eqawarn
+ eqawarn "For more information on bytecode files and related issues, please see:"
+ eqawarn " https://projects.gentoo.org/python/guide/qawarn.html#compiled-bytecode-related-warnings"
+ fi
+}
+
+python_pyc_check
: # guarantee successful exit
--
2.35.1
next prev parent reply other threads:[~2022-07-29 10:32 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-29 10:30 [gentoo-dev] [PATCH 00/11] distutils-r1.eclass: Support for gpep517-9+ --optimize + minor changes Michał Górny
2022-07-29 10:30 ` [gentoo-dev] [PATCH 01/11] distutils-r1.eclass: Update pyproject.toml advice for PEP517 mode Michał Górny
2022-07-29 10:30 ` [gentoo-dev] [PATCH 02/11] distutils-r1.eclass: Require gpep517 >= 8 Michał Górny
2022-07-29 10:30 ` Michał Górny [this message]
2022-07-29 10:30 ` [gentoo-dev] [PATCH 04/11] distutils-r1.eclass: Bump dev-python/sip dependency Michał Górny
2022-07-29 10:30 ` [gentoo-dev] [PATCH 05/11] distutils-r1.eclass: Pass EPREFIX to addpredict Michał Górny
2022-07-29 10:30 ` [gentoo-dev] [PATCH 06/11] distutils-r1.eclass: Let gpep517 compile bytecode when 9+ is used Michał Górny
2022-07-29 10:30 ` [gentoo-dev] [PATCH 07/11] dev-python/installer: Call python_optimize explicitly Michał Górny
2022-07-29 10:31 ` [gentoo-dev] [PATCH 08/11] dev-python/tomli: " Michał Górny
2022-07-29 10:31 ` [gentoo-dev] [PATCH 09/11] net-wireless/blueman: Invoke eautomake to fix py-compile script Michał Górny
2022-07-29 12:59 ` Ulrich Mueller
2022-07-29 10:31 ` [gentoo-dev] [PATCH 10/11] dev-python/pygobject: Call python_optimize explicitly Michał Górny
2022-07-29 10:31 ` [gentoo-dev] [PATCH 11/11] python-utils-r1.eclass: Sterilize pytest-sugar plugin Michał Górny
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220729103103.1185162-4-mgorny@gentoo.org \
--to=mgorny@gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox