Re: [gentoo-dev] Feature request for pkgcheck (was: pkgdev new release v0.2.1 with breaking change)

2022-06-04 Thread Sam James


> On 5 Jun 2022, at 00:34, Anna V  wrote:
> 
> I'd like pkgcheck to detect if RDEPEND was changed without revbump.
> 

pkgcheck scan --commits does. A solution for when _other_ people did this could 
be
done by diffing metadata, I think.


signature.asc
Description: Message signed with OpenPGP


[gentoo-dev] [PATCH v3 2/2] eclass/tests/esed.sh: tests for esed.eclass

2022-06-04 Thread Ionen Wolkens
Bit sloppy, but should cover most of it.

Signed-off-by: Ionen Wolkens 
---
 eclass/tests/esed.sh | 263 +++
 1 file changed, 263 insertions(+)
 create mode 100755 eclass/tests/esed.sh

diff --git a/eclass/tests/esed.sh b/eclass/tests/esed.sh
new file mode 100755
index 000..d9dfe699e42
--- /dev/null
+++ b/eclass/tests/esed.sh
@@ -0,0 +1,263 @@
+#!/usr/bin/env bash
+# Copyright 2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+source tests-common.sh || exit
+
+inherit esed
+
+cd "${WORKDIR:-/dev/null}" || exit
+
+tsddied=n
+tsddie() {
+   tsddied=y
+   tsddiemsg=${*}
+   echo "would die: ${tsddiemsg}" >&2
+   # silence some further errors given didn't actually die
+   sed() { :; }
+   die() { :; }
+}
+
+tsdbegin() {
+   tbegin "${1}"
+   tsddied=n
+   unset -f sed
+   die() { tsddie "${@}"; }
+}
+
+tsdend() {
+   if [[ ${1} == fatal* && ${tsddied} == n ]]; then
+   tend 127 "should have died"
+   elif [[ ${1} == fatal:* && ${tsddied} == y && ${tsddiemsg} != 
*"${1#fatal:}"* ]]; then
+   tend 128 "died as expected but die message does not match 
'*${1#fatal:}*'"
+   elif [[ ${1} == nonfatal && ${tsddied} == y ]]; then
+   tend 129 "should not have died"
+   else
+   tend ${2:-0} "something went wrong(tm)"
+   fi
+}
+
+tsdfile() {
+   local file
+   for file in "${@}"; do
+   if [[ ${file%:*} ]]; then
+   echo "${file%:*}" > "${file#*:}" || exit
+   elif [[ -e ${file#*:} ]]; then
+   rm -- "${file#*:}" || exit
+   fi
+   done
+}
+
+tsdcmp() {
+   local contents
+   contents=$(<"${1}") || exit
+   if [[ ${contents} != "${2}" ]]; then
+   echo "${FUNCNAME[0]}: '${contents}' != '${2}'"
+   return 1
+   fi
+}
+
+tsdbegin "esed: change on single file"
+tsdfile replace:file
+esed s/replace/new/ file
+tsdcmp file new
+tsdend nonfatal ${?}
+
+tsdbegin "esed: die due to no change on a single file"
+tsdfile keep:file
+esed s/replace/new/ file
+tsdcmp file keep
+tsdend fatal:no-op ${?}
+
+tsdbegin "esed: sequential changes"
+tsdfile replace1:file
+esed -e s/replace1/replace2/ -e s/replace2/new/ file
+tsdcmp file new
+tsdend nonfatal ${?}
+
+tsdbegin "esed: change on at least one of two files with ESED_VERBOSE=1"
+tsdfile keep:file1 replace:file2
+ESED_VERBOSE=1 esed s/replace/new/ file1 file2
+tsdcmp file1 keep &&
+   tsdcmp file2 new
+tsdend nonfatal ${?}
+
+tsdbegin "esed: die due to no change on two files with ESED_VERBOSE=1"
+tsdfile keep:file{1..2}
+ESED_VERBOSE=1 esed s/replace/new/ file1 file2
+tsdcmp file1 keep &&
+   tsdcmp file2 keep
+tsdend fatal:'no-op' ${?}
+
+tsdbegin "esed: -E/-n/-r arguments"
+tsdfile $'hide\nshow\nhide\nthis':file
+esed -E -n -r '/(show|this)/p' file
+tsdcmp file $'show\nthis'
+tsdend nonfatal ${?}
+
+tsdbegin "esed: die due to passing unrecognized -i"
+tsdfile replace:file
+esed -i s/replace/new/ file
+tsdend fatal:'unrecognized option'
+
+tsdbegin "esed: change files with one nicely named '-- -e'"
+tsdfile replace:"-- -e" replace:file
+esed -e s/replace/new/ file -- "-- -e"
+tsdcmp file new &&
+   tsdcmp "-- -e" new
+tsdend nonfatal ${?}
+
+tsdbegin "esed: die due to no files in arguments"
+esed -e s/replace/new/ -e s/replace/new/
+tsdend fatal:'no files in'
+
+tsdbegin "esed: die due to missing file"
+tsdfile :missing
+esed s/replace/new/ missing
+tsdend fatal:'not a file'
+
+tsdbegin "enewsed: change on a new file"
+tsdfile replace:file :newfile
+enewsed s/replace/new/ file newfile
+tsdcmp file replace &&
+   tsdcmp newfile new
+tsdend nonfatal ${?}
+
+tsdbegin "enewsed: die due to too many files"
+tsdfile replace:file1 replace:file2 :newfile
+enewsed s/replace/new/ file1 file2 newfile
+tsdend fatal:'exactly one input'
+
+tsdbegin "enewsed: die due to missing output file"
+tsdfile keep:file
+enewsed -e s/replace/new/ -e s/replace/new/ file
+tsdend fatal:'no files in'
+
+tsdbegin "enewsed: die due too few arguments beside files"
+tsdfile keep:file
+enewsed file newfile
+tsdend fatal:'too few arguments'
+
+tsdbegin "erepl: change on a single file"
+tsdfile :file
+erepl 0 1 file
+tsdcmp file 
+tsdend nonfatal ${?}
+
+tsdbegin "erepl: die due to no change on a single file"
+tsdfile keep:file
+erepl missing new file
+tsdcmp file keep
+tsdend fatal:'no-op' ${?}
+
+tsdbegin "erepl: change on at least one of two files with ESED_VERBOSE=1"
+tsdfile keep:file1 replace:file2
+ESED_VERBOSE=1 erepl replace new file1 file2
+tsdcmp file1 keep &&
+   tsdcmp file2 new
+tsdend nonfatal ${?}
+
+tsdbegin "erepl: die due to no change on two files with ESED_VERBOSE=1"
+tsdfile keep:file{1..2}
+ESED_VERBOSE=1 erepl replace new file1 file2
+tsdcmp file1 keep &&
+   tsdcmp file2 keep
+tsdend fatal:'no-op' ${?}
+
+tsdbegin "erepl: change containing 

[gentoo-dev] [PATCH v3 0/2] Add esed.eclass for modifying with checks for no-op

2022-06-04 Thread Ionen Wolkens
Semi-new take on the eclass, also incorporating mgorny's erepl idea
making this more or less a toolbox for replacements with no-op checks
(still named esed.eclass, but could be reconsidered if seems better).

See @EXAMPLE in eclass for quick usage overview, and below for
nvidia-drivers ebuild change example.

Please try it in real ebuilds so can get a better idea of anything
lacking or potentially broken that tests/esed.sh doesn't pickup.

Anything is still up for debate/review, unlikely to be final
(if even added at all).

Updated version also available from github PR[1]

Changelog from v2:
- esed simplified to take only specific arguments
 (parsing can still be a bit jarring, but more linear/deterministic)
- remove esedexps, unneeded given esed now understands -e
- simplified enewsed by using cp and removing concat support
 (with the 3 above, is essentially a rewrite)
- add simple bash-based erepl / erepld / ereplp + enew variants
- convert esedfind to "efind" so it's usable by all functions
 (perhaps feel a bit out of place in this eclass now, albeit similar
  theme given dies if no-ops without files)
- no longer hide null byte warnings and indicate this eclass is
  not for binary files (very uncommon usage either way)
- several new/modified esed.sh tests, also now verifies die
  messages to ensure died in the right place

As an usage example, here's differences for nvidia-drivers ebuild
(these could of course be handled other ways / patched, but between
conditionals, rebasing, and basic things like __USER__, can also
be annoying to):

-sed 's/defined(CONFIG_DRM/defined(CONFIG_DRM_KMS_HELPER/g' \
-   -i kernel{,-module-source/kernel-open}/conftest.sh || die
+erepl 'defined(CONFIG_DRM' 'defined(CONFIG_DRM_KMS_HELPER' \
+   kernel{,-module-source/kernel-open}/conftest.sh

-sed 's/__USER__/nvpd/' \
-   nvidia-persistenced/init/systemd/nvidia-persistenced.service.template \
-   > "${T}"/nvidia-persistenced.service || die
+enewrepl __USER__ nvpd \
+   nvidia-persistenced/init/systemd/nvidia-persistenced.service.template \
+   "${T}"/nvidia-persistenced.service

-use !amd64 || sed -i "s|/usr|${EPREFIX}/opt|" \
-   systemd/system/nvidia-powerd.service || die
+use amd64 && erepl /usr "${EPREFIX}"/opt \
+   systemd/system/nvidia-powerd.service

-use !wayland || sed -i '/^#.*modeset=1$/s/^#//' "${T}"/nvidia.conf || die
+use wayland && ereplp modeset=1 '#' '' "${T}"/nvidia.conf
(almost made this one esed, but ereplp does the uncommenting job too --
 also double negation was to skip if/then given `false && true || die`
 would die, but is now unneeded without || die)

-use wayland || sed -i 's/ WAYLAND_LIB_install$//' \
-   nvidia-settings/src/Makefile || die
+use wayland || ereplp ^install: WAYLAND_LIB_install '' \
+   nvidia-settings/src/Makefile
(not essential but make it safer by checking for ^install: too)

... fairly simple cases so no real need for esed over erepl here.

With ESED_VERBOSE=1 exported, in the build.log there's:

 * ereplp ^install: WAYLAND_LIB_install  nvidia-settings/src/Makefile 
[snip]
-install: NVIDIA_SETTINGS_install NVIDIA_GTKLIB_install WAYLAND_LIB_install
+install: NVIDIA_SETTINGS_install NVIDIA_GTKLIB_install 
[snip]

And if I rewrite it as `ereplp ^instypo: WYALAND_LIB_isntall ''`:

 * ERROR: x11-drivers/nvidia-drivers-515.48.07::gentoo failed (prepare phase):
 *   no-op: ereplp ^instypo: WYALAND_LIB_isntall  nvidia-settings/src/Makefile

[1] https://github.com/gentoo/gentoo/pull/25662

Ionen Wolkens (2):
  esed.eclass: new eclass
  eclass/tests/esed.sh: tests for esed.eclass

 eclass/esed.eclass   | 265 +++
 eclass/tests/esed.sh | 263 ++
 2 files changed, 528 insertions(+)
 create mode 100644 eclass/esed.eclass
 create mode 100755 eclass/tests/esed.sh

-- 
2.35.1




[gentoo-dev] [PATCH v3 1/2] esed.eclass: new eclass

2022-06-04 Thread Ionen Wolkens
Signed-off-by: Ionen Wolkens 
---
 eclass/esed.eclass | 265 +
 1 file changed, 265 insertions(+)
 create mode 100644 eclass/esed.eclass

diff --git a/eclass/esed.eclass b/eclass/esed.eclass
new file mode 100644
index 000..414daceaf8b
--- /dev/null
+++ b/eclass/esed.eclass
@@ -0,0 +1,265 @@
+# Copyright 2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: esed.eclass
+# @MAINTAINER:
+# Ionen Wolkens 
+# @AUTHOR:
+# Ionen Wolkens 
+# @SUPPORTED_EAPIS: 8
+# @BLURB: sed(1) and alike wrappers that die if did not modify any files
+# @EXAMPLE:
+#
+# @CODE
+# # sed(1) wrappers, die if no changes
+# esed s/a/b/ file.c # -i is default
+# enewsed s/a/b/ project.pc.in "${T}"/project.pc
+#
+# # bash-only simple fixed string alternatives, also die if no changes
+# erepl string replace file.c
+# ereplp ^match string replace file.c # like /^match/s:string:replace:g
+# erepld ^match file.c # deletes matching lines, like /^match/d
+# use prefix && enewreplp ^prefix= /usr "${EPREFIX}"/usr pn.pc.in pn.pc
+#
+# # find(1) wrapper that sees shell functions, dies if no files found
+# efind . -name '*.c' -erun esed s/a/b/ # dies if no files changed
+# efind . -name '*.c' -erun sed s/a/b/ # only dies if no files found
+# @CODE
+#
+# Migration notes: be wary of non-deterministic cases involving variables,
+# e.g. s|lib|$(get_libdir)|, s|-O3|${CFLAGS}|, or s|/usr|${EPREFIX}/usr|.
+# erepl/esed() die if these do nothing, like libdir being 'lib' on x86.
+# Either verify, keep sed(1), or ensure a change (extra space, @libdir@).
+#
+# Where possible, it is also good to consider if using patches is more
+# suitable to ensure adequate changes.  These functions are also unsafe
+# for binary files containing null bytes (erepl() will remove them).
+
+case ${EAPI} in
+   8) ;;
+   *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
+esac
+
+if [[ ! ${_ESED_ECLASS} ]]; then
+_ESED_ECLASS=1
+
+# @ECLASS_VARIABLE: ESED_VERBOSE
+# @DEFAULT_UNSET
+# @USER_VARIABLE
+# @DESCRIPTION:
+# If set to a non-empty value, erepl/esed() and wrappers will use diff(1)
+# to display file differences.  Recommended for maintainers to easily
+# confirm the changes being made.
+
+# @FUNCTION: esed
+# @USAGE: [-E|-r|-n] [-e ]... [--] ...
+# @DESCRIPTION:
+# sed(1) wrapper that dies if any of the expressions did not modify any files.
+# sed's -i/--in-place is forced, -e can be omitted if only one expression, and
+# arguments must be passed in the listed order with files last.  Each -e will
+# be a separate sed(1) call to evaluate changes of each.
+esed() {
+   (( ${#} >= 2 )) || die "too few arguments for 
${_esed_cmd[0]:-${FUNCNAME[0]}}"
+
+   local endopts=false args=() contents=() exps=() files=()
+   local -i i
+   for ((i=1; i<=${#}; i++)); do
+   if [[ ${!i} =~ ^- ]] && ! ${endopts}; then
+   case ${!i} in
+   --) endopts=true ;;
+   -E|-n|-r) args+=( ${!i} ) ;;
+   -e)
+   i+=1
+   [[ ${!i} ]] || die "missing argument to 
-e"
+   exps+=( "${!i}" )
+   ;;
+   *) die "unrecognized option for ${FUNCNAME[0]}" 
;;
+   esac
+   elif (( ! ${#exps[@]} )); then
+   exps+=( "${!i}" ) # like sed, if no -e, first 
non-option is exp
+   else
+   [[ -f ${!i} ]] || die "not a file: ${!i}"
+   files+=( "${!i}" )
+   contents+=( "$(<"${!i}")" ) || die "failed reading: 
${!i}"
+   fi
+   done
+   (( ${#files[@]} )) || die "no files in ${FUNCNAME[0]} arguments"
+
+   if [[ ${_esed_output} ]]; then
+   (( ${#files[@]} == 1 )) || die "${_esed_cmd[0]} needs exactly 
one input file"
+
+   # swap file for output to simplify sequential sed'ing
+   cp -- "${files[0]}" "${_esed_output}" || die
+   files[0]=${_esed_output}
+   fi
+
+   local changed exp newcontents sed
+   for exp in "${exps[@]}"; do
+   sed=( sed -i "${args[@]}" -e "${exp}" -- "${files[@]}" )
+   [[ ${ESED_VERBOSE} ]] && einfo "${sed[*]}"
+
+   "${sed[@]}" ... 
+# @DESCRIPTION:
+# esed() wrapper to save the result to .  Intended to replace
+# ``sed ... input > output`` given esed() does not support stdin/out.
+enewsed() {
+   local _esed_cmd=( ${FUNCNAME[0]} "${@}" )
+   local _esed_output=${*: -1:1}
+   esed "${@:1:${#}-1}"
+}
+
+# @FUNCTION: erepl
+# @USAGE:   ...
+# @DESCRIPTION:
+# Do basic bash-only ``${//""/}`` per-line
+# replacement in files(s).  Dies if no changes were made.  Suggested over
+# sed(1) where possible for simplicity and avoiding issues with 

Re: [gentoo-dev] it's time for 22.0 profiles

2022-06-04 Thread Kenton Groombridge
On 22/05/28 10:28PM, Andreas K. Huettel wrote:
> Hi all,
>
> it's time for introducing 22.0 profiles [1] - so if you have any things that 
> need to
> be switched in an incompatible way tree-wide, or if you have any suggestions 
> on how
> to change our default settings, please reply to this mail with details!
>

The currently existing systemd/selinux profiles need to be replaced with
systemd/hardened and systemd/hardened/selinux profiles. So, instead of
(for example):

default/linux/amd64/20.0/no-multilib/systemd/selinux
default/linux/amd64/20.0/systemd/selinux

We would instead have:

default/linux/amd64/20.0/no-multilib/systemd/hardened/selinux
default/linux/amd64/20.0/no-multilib/systemd/hardened
default/linux/amd64/20.0/systemd/hardened
default/linux/amd64/20.0/systemd/hardened/selinux

The takeaway is that the systemd/selinux profiles should have hardened
as a parent for consistency with the other SELinux profiles.

/* Kenton Groombridge */


signature.asc
Description: PGP signature


Re: [gentoo-dev] [PATCH 0/2] Add esed.eclass for sed that dies if caused no changes

2022-06-04 Thread Ionen Wolkens
On Sat, Jun 04, 2022 at 06:19:30PM +0200, Alessandro Barbieri wrote:
> When I use sed is for dynamic content and mostly like to do this:
> s|lib|$(get_libdir)|g
> In this case esed would be deleterious because it would fail on 32 bit
> arches

This case is noted in the docs fwiw. How to handle will depend on
preference but best route to ensure the change is always right
would be either to patch to replace lib by e.g. @GENTOO_LIBDIR@,
/then/ sed, or insert a variable/option that could be passed and
perhaps even upstreamed.

Lazier approach that use esed (or upcoming erepl) could be:

   [[ $(get_libdir) != lib ]] && erepl /lib /$(get_libdir) file

This also avoids unnecessarily editing files when there's nothing,
albeit more invasive and runs get_libdir twice. EPREFIX is a bit
nicer given we can use `use prefix`:

   use prefix && erepl /usr "${EPREFIX}"/usr file

This is a bit like replacing
   rm -f exists-with-USE-gui-only
by
   use !gui || rm exists-with-USE-gui-only || die
(bash exit code logic always fun wrt that double negation...)

Both are going to do the job at first, but one may end up missing
that the file was moved in another directory on bump and is now
getting wrongly installed.

-- 
ionen


signature.asc
Description: PGP signature


Re: [gentoo-dev] [PATCH 0/2] Add esed.eclass for sed that dies if caused no changes

2022-06-04 Thread Alessandro Barbieri
Il giorno mar 31 mag 2022 alle ore 13:23 Ionen Wolkens 
ha scritto:

> Often preferable to use patches so this happens, but sed have its
> uses/convenience and this intend to help reduce the amount of old
> broken seds causing issues that go unnoticed on bumps.
>
> Inspired by app-portage/iwdevtools' qa-sed (warns on any seds), but
> this is for more deterministic use in ebuilds.
>
> Also slightly shortens sed use, -i is default, and no need to || die.
> (see @EXAMPLE in eclass for a quick usage overview).
>
> Implementation / available wrappers / usefulness still up for debate,
> but without further comments I consider this ready (albeit first time
> touching / making an eclass, so I could be overlooking simple things).
> Also partly uses >=bash-4.4, so EAPI-7 is not considered.
>
> See github PR[1] for old changelog background.
>
> Up to maintainers but personally would encourage to slowly replace
> (almost) all use of sed with either this or patches. Some cases
> where it can be inconvenient like eclasses "guessing" that a package
> may or may not have something to replace, and that nothing happened
> is not an issue.
>
> [1] https://github.com/gentoo/gentoo/pull/25662
>
> Ionen Wolkens (2):
>   esed.eclass: new eclass
>   eclass/tests/esed.sh: basic tests for esed.eclass
>
>  eclass/esed.eclass   | 199 +++
>  eclass/tests/esed.sh | 173 +
>  2 files changed, 372 insertions(+)
>  create mode 100644 eclass/esed.eclass
>  create mode 100755 eclass/tests/esed.sh
>
> --
> 2.35.1
>
>
>
I use patches for static content, not a big fan of wall of sed in ebuilds
When I use sed is for dynamic content and mostly like to do this:
s|lib|$(get_libdir)|g
In this case esed would be deleterious because it would fail on 32 bit
arches


[gentoo-dev] [PATCH] install-qa-check.d/60udev-eclass: check for udev_reload in pkg_postrm

2022-06-04 Thread Mike Gilbert
Bug: https://bugs.gentoo.org/847436
Signed-off-by: Mike Gilbert 
---
 metadata/install-qa-check.d/60udev-eclass | 5 +
 1 file changed, 5 insertions(+)

diff --git a/metadata/install-qa-check.d/60udev-eclass 
b/metadata/install-qa-check.d/60udev-eclass
index 4aadc9b1f18..24a4df38ec4 100644
--- a/metadata/install-qa-check.d/60udev-eclass
+++ b/metadata/install-qa-check.d/60udev-eclass
@@ -54,6 +54,11 @@ udev_rules_check() {
eqawarn "QA Notice: package is installing udev rules 
without calling"
eqawarn "udev_reload in pkg_postinst phase"
fi
+   local pkg_postrm_body="$(declare -fp pkg_postrm 2>&1)"
+   if [[ ! ${pkg_postrm_body} == *udev_reload* ]] ; then
+   eqawarn "QA Notice: package is installing udev rules 
without calling"
+   eqawarn "udev_reload in pkg_postrm phase"
+   fi
fi
 }
 
-- 
2.35.1




[gentoo-dev] [PATCH] udev.eclass: document when udev_reload should be called

2022-06-04 Thread Mike Gilbert
Closes: https://bugs.gentoo.org/847436
Signed-off-by: Mike Gilbert 
---
 eclass/udev.eclass | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/eclass/udev.eclass b/eclass/udev.eclass
index 073e5d8acbc..830e3eeb125 100644
--- a/eclass/udev.eclass
+++ b/eclass/udev.eclass
@@ -1,4 +1,4 @@
-# Copyright 1999-2021 Gentoo Authors
+# Copyright 1999-2022 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 # @ECLASS: udev.eclass
@@ -26,6 +26,14 @@
 #  # udev_dorules contrib/99-foomatic
 #  # udev_newrules contrib/98-foomatic 99-foomatic
 # }
+#
+# pkg_postinst() {
+#  udev_reload
+# }
+#
+# pkg_postrm() {
+#  udev_reload
+# }
 # @CODE
 
 case ${EAPI} in
@@ -110,7 +118,9 @@ udev_newrules() {
 
 # @FUNCTION: udev_reload
 # @DESCRIPTION:
-# Run udevadm control --reload to refresh rules and databases
+# Run "udevadm control --reload" to refresh rules and databases.
+# Should be called from pkg_postinst and pkg_postrm in packages which install
+# udev rules or hwdb data.
 udev_reload() {
if [[ -n ${ROOT%/} ]]; then
return 0
-- 
2.35.1




[gentoo-dev] [PATCH 18/18] distutils-r1.eclass: Add "_trial_temp" to forbidden package names

2022-06-04 Thread Michał Górny
Signed-off-by: Michał Górny 
---
 eclass/distutils-r1.eclass | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
index 9536e5c466be..db5cced50952 100644
--- a/eclass/distutils-r1.eclass
+++ b/eclass/distutils-r1.eclass
@@ -1884,7 +1884,7 @@ _distutils-r1_post_python_install() {
 
local forbidden_package_names=(
examples test tests
-   .pytest_cache .hypothesis
+   .pytest_cache .hypothesis _trial_temp
)
local p
for p in "${forbidden_package_names[@]}"; do
-- 
2.35.1




[gentoo-dev] [PATCH 17/18] distutils-r1.eclass: small docs format fixes

2022-06-04 Thread Michał Górny
From: Arthur Zamarin 

Signed-off-by: Arthur Zamarin 
---
 eclass/distutils-r1.eclass | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
index 30f7d941f0d4..9536e5c466be 100644
--- a/eclass/distutils-r1.eclass
+++ b/eclass/distutils-r1.eclass
@@ -119,7 +119,7 @@ esac
 # - sip - sipbuild backend
 #
 # - standalone - standalone build systems without external deps
-#(used for bootstrapping).
+#   (used for bootstrapping).
 #
 # The variable needs to be set before the inherit line.  The eclass
 # adds appropriate build-time dependencies and verifies the value.
@@ -149,10 +149,10 @@ esac
 # - rdepend -- add it to BDEPEND+RDEPEND (e.g. when using pkg_resources)
 #
 # - pyproject.toml -- use pyproject2setuptools to install a project
-# using pyproject.toml (flit, poetry...)
+#   using pyproject.toml (flit, poetry...)
 #
 # - manual -- do not add the dependency and suppress the checks
-# (assumes you will take care of doing it correctly)
+#   (assumes you will take care of doing it correctly)
 #
 # This variable is effective only if DISTUTILS_OPTIONAL is disabled.
 # It is available only in non-PEP517 mode.  It needs to be set before
@@ -628,8 +628,11 @@ distutils_enable_tests() {
 # (if ${EPYTHON} is set; fallback 'python' otherwise).
 #
 # setup.py will be passed the following, in order:
+#
 # 1. ${DISTUTILS_ARGS[@]}
+#
 # 2. ${mydistutilsargs[@]} (deprecated)
+#
 # 3. additional arguments passed to the esetup.py function.
 #
 # Please note that setup.py will respect defaults (unless overridden
-- 
2.35.1




[gentoo-dev] [PATCH 16/18] python-any-r1.eclass: use python_has_version in examples

2022-06-04 Thread Michał Górny
From: Arthur Zamarin 

python_has_version is preferred as it gives nicer output and safer
defaults, instead of has_version.
---
 eclass/python-any-r1.eclass | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/eclass/python-any-r1.eclass b/eclass/python-any-r1.eclass
index 2051b5e89b81..fc66434cc6bf 100644
--- a/eclass/python-any-r1.eclass
+++ b/eclass/python-any-r1.eclass
@@ -139,7 +139,7 @@ EXPORT_FUNCTIONS pkg_setup
 # Example use:
 # @CODE
 # python_check_deps() {
-#  has_version "dev-python/foo[${PYTHON_USEDEP}]"
+#  python_has_version "dev-python/foo[${PYTHON_USEDEP}]"
 # }
 # @CODE
 #
@@ -161,7 +161,7 @@ EXPORT_FUNCTIONS pkg_setup
 # Example use:
 # @CODE
 # python_check_deps() {
-#  has_version "dev-python/bar[${PYTHON_SINGLE_USEDEP}]"
+#  python_has_version "dev-python/bar[${PYTHON_SINGLE_USEDEP}]"
 # }
 # @CODE
 #
@@ -228,9 +228,9 @@ if [[ ! ${_PYTHON_ANY_R1} ]]; then
 #  dev-python/baz[${PYTHON_USEDEP}] )')"
 #
 # python_check_deps() {
-#  has_version "dev-python/foo[${PYTHON_SINGLE_USEDEP}]" \
-#  && { has_version "dev-python/bar[${PYTHON_USEDEP}]" \
-#  || has_version "dev-python/baz[${PYTHON_USEDEP}]"; }
+#  python_has_version "dev-python/foo[${PYTHON_SINGLE_USEDEP}]" \
+#  && { python_has_version "dev-python/bar[${PYTHON_USEDEP}]" \
+#  || python_has_version 
"dev-python/baz[${PYTHON_USEDEP}]"; }
 # }
 # @CODE
 #
-- 
2.35.1




[gentoo-dev] [PATCH 15/18] app-admin/gnome-abrt: Use DISTUTILS_USE_PEP517=no

2022-06-04 Thread Michał Górny
Signed-off-by: Michał Górny 
---
 .../gnome-abrt/gnome-abrt-1.4.1-r1.ebuild | 57 +++
 1 file changed, 57 insertions(+)
 create mode 100644 app-admin/gnome-abrt/gnome-abrt-1.4.1-r1.ebuild

diff --git a/app-admin/gnome-abrt/gnome-abrt-1.4.1-r1.ebuild 
b/app-admin/gnome-abrt/gnome-abrt-1.4.1-r1.ebuild
new file mode 100644
index ..2df18e86b873
--- /dev/null
+++ b/app-admin/gnome-abrt/gnome-abrt-1.4.1-r1.ebuild
@@ -0,0 +1,57 @@
+# Copyright 1999-2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+DISTUTILS_USE_PEP517=no
+PYTHON_COMPAT=( python3_{8..10} )
+
+inherit meson distutils-r1
+
+DESCRIPTION="A utility for viewing problems that have occurred with the system"
+HOMEPAGE="https://github.com/abrt/gnome-abrt;
+SRC_URI="https://github.com/abrt/${PN}/archive/${PV}.tar.gz -> ${P}.tar.gz"
+
+LICENSE="GPL-2+"
+SLOT="0"
+KEYWORDS="~amd64 ~x86"
+
+IUSE="doc"
+
+RDEPEND="
+   >=x11-libs/gtk+-3.10.0:3
+   >=dev-libs/libreport-2.14.0:0=[python,${PYTHON_USEDEP}]
+   >=app-admin/abrt-2.14.0
+   >=dev-python/pygobject-3.29.1:3[${PYTHON_USEDEP}]
+   >=dev-python/pyxdg-0.19[${PYTHON_USEDEP}]
+"
+DEPEND="${RDEPEND}"
+BDEPEND="
+   doc? (
+   app-text/asciidoc
+   app-text/xmlto
+   )
+   virtual/pkgconfig
+   >=sys-devel/gettext-0.17
+"
+
+python_configure() {
+   local emesonargs=(
+   $(meson_use doc docs)
+   -Dlint=false
+   )
+
+   meson_src_configure
+}
+
+python_compile() {
+   meson_src_compile
+}
+
+python_test() {
+   meson_src_test
+}
+
+python_install() {
+   meson_src_install
+}
-- 
2.35.1




[gentoo-dev] [PATCH 14/18] dev-python/gpep517: Use DISTUTILS_USE_PEP517=no

2022-06-04 Thread Michał Górny
Signed-off-by: Michał Górny 
---
 dev-python/gpep517/gpep517-6-r1.ebuild | 41 ++
 1 file changed, 41 insertions(+)
 create mode 100644 dev-python/gpep517/gpep517-6-r1.ebuild

diff --git a/dev-python/gpep517/gpep517-6-r1.ebuild 
b/dev-python/gpep517/gpep517-6-r1.ebuild
new file mode 100644
index ..ee64cb1d660f
--- /dev/null
+++ b/dev-python/gpep517/gpep517-6-r1.ebuild
@@ -0,0 +1,41 @@
+# Copyright 2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# please keep this ebuild at EAPI 7 -- sys-apps/portage dep
+EAPI=7
+
+DISTUTILS_USE_PEP517=no
+PYTHON_COMPAT=( pypy3 python3_{8..11} )
+
+inherit distutils-r1
+
+DESCRIPTION="A backend script to aid installing Python packages in Gentoo"
+HOMEPAGE="
+   https://pypi.org/project/gpep517/
+   https://github.com/mgorny/gpep517/
+"
+SRC_URI="
+   https://github.com/mgorny/gpep517/archive/v${PV}.tar.gz
+   -> ${P}.gh.tar.gz
+"
+
+LICENSE="MIT"
+SLOT="0"
+KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~loong ~m68k ~mips ~ppc ~ppc64 
~riscv ~s390 ~sparc ~x86 ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos 
~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris"
+
+RDEPEND="
+   >=dev-python/installer-0.5.0[${PYTHON_USEDEP}]
+   >=dev-python/tomli-1.2.3[${PYTHON_USEDEP}]
+"
+
+distutils_enable_tests pytest
+
+python_install() {
+   python_domodule gpep517
+   python_newscript - gpep517 <<-EOF
+   #!${EPREFIX}/usr/bin/python
+   import sys
+   from gpep517.__main__ import main
+   sys.exit(main())
+   EOF
+}
-- 
2.35.1




[gentoo-dev] [PATCH 13/18] dev-python/installer: Use DISTUTILS_USE_PEP517=no

2022-06-04 Thread Michał Górny
Signed-off-by: Michał Górny 
---
 .../installer/installer-0.5.1-r1.ebuild   | 37 +++
 1 file changed, 37 insertions(+)
 create mode 100644 dev-python/installer/installer-0.5.1-r1.ebuild

diff --git a/dev-python/installer/installer-0.5.1-r1.ebuild 
b/dev-python/installer/installer-0.5.1-r1.ebuild
new file mode 100644
index ..4f89e7433018
--- /dev/null
+++ b/dev-python/installer/installer-0.5.1-r1.ebuild
@@ -0,0 +1,37 @@
+# Copyright 2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# please keep this ebuild at EAPI 7 -- sys-apps/portage dep
+EAPI=7
+
+DISTUTILS_USE_PEP517=no
+PYTHON_COMPAT=( python3_{8..11} pypy3 )
+
+inherit distutils-r1
+
+DESCRIPTION="A library for installing Python wheels"
+HOMEPAGE="
+   https://pypi.org/project/installer/
+   https://github.com/pypa/installer/
+   https://installer.readthedocs.io/en/latest/
+"
+SRC_URI="
+   https://github.com/pypa/installer/archive/${PV}.tar.gz
+   -> ${P}.gh.tar.gz
+   
https://files.pythonhosted.org/packages/py3/${PN::1}/${PN}/${P%_p*}-py3-none-any.whl
+   -> ${P%_p*}-py3-none-any.whl.zip
+"
+
+LICENSE="MIT"
+SLOT="0"
+KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~loong ~m68k ~mips ~ppc ~ppc64 
~riscv ~s390 ~sparc ~x86 ~x64-cygwin ~amd64-linux ~x86-linux ~ppc-macos 
~x64-macos ~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris"
+
+BDEPEND="
+   app-arch/unzip
+"
+
+distutils_enable_tests pytest
+
+python_compile() {
+   python_domodule src/installer "${WORKDIR}"/*.dist-info
+}
-- 
2.35.1




[gentoo-dev] [PATCH 12/18] dev-python/tomli: Use DISTUTILS_USE_PEP517=no

2022-06-04 Thread Michał Górny
Signed-off-by: Michał Górny 
---
 dev-python/tomli/tomli-2.0.1-r1.ebuild | 36 ++
 1 file changed, 36 insertions(+)
 create mode 100644 dev-python/tomli/tomli-2.0.1-r1.ebuild

diff --git a/dev-python/tomli/tomli-2.0.1-r1.ebuild 
b/dev-python/tomli/tomli-2.0.1-r1.ebuild
new file mode 100644
index ..338d877a350d
--- /dev/null
+++ b/dev-python/tomli/tomli-2.0.1-r1.ebuild
@@ -0,0 +1,36 @@
+# Copyright 2021-2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# please keep this ebuild at EAPI 7 -- sys-apps/portage dep
+EAPI=7
+
+DISTUTILS_USE_PEP517=no
+PYTHON_COMPAT=( python3_{8..11} pypy3 )
+
+inherit distutils-r1
+
+DESCRIPTION="A lil' TOML parser"
+HOMEPAGE="
+   https://pypi.org/project/tomli/
+   https://github.com/hukkin/tomli/
+"
+SRC_URI="
+   https://github.com/hukkin/tomli/archive/${PV}.tar.gz
+   -> ${P}.gh.tar.gz
+   
https://files.pythonhosted.org/packages/py3/${PN::1}/${PN}/${P}-py3-none-any.whl
+   -> ${P}-py3-none-any.whl.zip
+"
+
+LICENSE="MIT"
+SLOT="0"
+KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~loong ~m68k ~mips ~ppc ~ppc64 
~riscv ~s390 ~sparc ~x86 ~ppc-macos ~x64-macos ~x64-solaris"
+
+BDEPEND="
+   app-arch/unzip
+"
+
+distutils_enable_tests unittest
+
+python_compile() {
+   python_domodule src/tomli "${WORKDIR}"/*.dist-info
+}
-- 
2.35.1




[gentoo-dev] [PATCH 11/18] python-utils-r1.eclass: Add explicit checks for incorrect phase

2022-06-04 Thread Michał Górny
Signed-off-by: Michał Górny 
---
 eclass/python-utils-r1.eclass | 13 +
 1 file changed, 13 insertions(+)

diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass
index fd04cf374ce4..b9cf9c03caeb 100644
--- a/eclass/python-utils-r1.eclass
+++ b/eclass/python-utils-r1.eclass
@@ -696,6 +696,9 @@ python_scriptinto() {
 python_doexe() {
debug-print-function ${FUNCNAME} "${@}"
 
+   [[ ${EBUILD_PHASE} != install ]] &&
+   die "${FUNCNAME} can only be used in src_install"
+
local f
for f; do
python_newexe "${f}" "${f##*/}"
@@ -714,6 +717,8 @@ python_doexe() {
 python_newexe() {
debug-print-function ${FUNCNAME} "${@}"
 
+   [[ ${EBUILD_PHASE} != install ]] &&
+   die "${FUNCNAME} can only be used in src_install"
[[ ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is 
null).'
[[ ${#} -eq 2 ]] || die "Usage: ${FUNCNAME}  "
 
@@ -762,6 +767,9 @@ python_newexe() {
 python_doscript() {
debug-print-function ${FUNCNAME} "${@}"
 
+   [[ ${EBUILD_PHASE} != install ]] &&
+   die "${FUNCNAME} can only be used in src_install"
+
local _PYTHON_REWRITE_SHEBANG=1
python_doexe "${@}"
 }
@@ -786,6 +794,9 @@ python_doscript() {
 python_newscript() {
debug-print-function ${FUNCNAME} "${@}"
 
+   [[ ${EBUILD_PHASE} != install ]] &&
+   die "${FUNCNAME} can only be used in src_install"
+
local _PYTHON_REWRITE_SHEBANG=1
python_newexe "${@}"
 }
@@ -894,6 +905,8 @@ python_domodule() {
 python_doheader() {
debug-print-function ${FUNCNAME} "${@}"
 
+   [[ ${EBUILD_PHASE} != install ]] &&
+   die "${FUNCNAME} can only be used in src_install"
[[ ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is 
null).'
 
local includedir=$(python_get_includedir)
-- 
2.35.1




[gentoo-dev] [PATCH 10/18] python-utils-r1.eclass: Support python_domodule outside src_install

2022-06-04 Thread Michał Górny
Make it possible to use python_domodule() outside src_install(),
in order to install files into the ${BUILD_DIR}/install tree used
by distutils-r1.

Signed-off-by: Michał Górny 
---
 eclass/python-utils-r1.eclass | 29 ++---
 1 file changed, 22 insertions(+), 7 deletions(-)

diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass
index b3c249dfa694..fd04cf374ce4 100644
--- a/eclass/python-utils-r1.eclass
+++ b/eclass/python-utils-r1.eclass
@@ -832,6 +832,10 @@ python_moduleinto() {
 # and packages (directories). All listed files will be installed
 # for all enabled implementations, and compiled afterwards.
 #
+# The files are installed into ${D} when run in src_install() phase.
+# Otherwise, they are installed into ${BUILD_DIR}/install location
+# that is suitable for picking up by distutils-r1 in PEP517 mode.
+#
 # Example:
 # @CODE
 # src_install() {
@@ -854,13 +858,24 @@ python_domodule() {
d=${sitedir#${EPREFIX}}/${_PYTHON_MODULEROOT//.//}
fi
 
-   (
-   insopts -m 0644
-   insinto "${d}"
-   doins -r "${@}" || return ${?}
-   )
-
-   python_optimize "${ED%/}/${d}"
+   if [[ ${EBUILD_PHASE} == install ]]; then
+   (
+   insopts -m 0644
+   insinto "${d}"
+   doins -r "${@}" || return ${?}
+   )
+   python_optimize "${ED%/}/${d}"
+   elif [[ -n ${BUILD_DIR} ]]; then
+   local dest=${BUILD_DIR}/install${EPREFIX}/${d}
+   mkdir -p "${dest}" || die
+   cp -pR "${@}" "${dest}/" || die
+   (
+   cd "${dest}" &&
+   chmod -R a+rX "${@##*/}"
+   ) || die
+   else
+   die "${FUNCNAME} can only be used in src_install or with 
BUILD_DIR set"
+   fi
 }
 
 # @FUNCTION: python_doheader
-- 
2.35.1




[gentoo-dev] [PATCH 09/18] python-utils-r1.eclass: Fix typo in python_moduleinto doc

2022-06-04 Thread Michał Górny
Fix python_moduleinto doc to mention python_domodule rather than
python_doscript (copy-paste error, probably).

Signed-off-by: Michał Górny 
---
 eclass/python-utils-r1.eclass | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass
index 9eb068d3b13f..b3c249dfa694 100644
--- a/eclass/python-utils-r1.eclass
+++ b/eclass/python-utils-r1.eclass
@@ -805,10 +805,10 @@ python_newscript() {
 # site-packages directory.
 #
 # In the relative case, the exact path is determined directly
-# by each python_doscript/python_newscript function. Therefore,
-# python_moduleinto can be safely called before establishing the Python
-# interpreter and/or a single call can be used to set the path correctly
-# for multiple implementations, as can be seen in the following example.
+# by each python_domodule invocation. Therefore, python_moduleinto
+# can be safely called before establishing the Python interpreter and/or
+# a single call can be used to set the path correctly for multiple
+# implementations, as can be seen in the following example.
 #
 # Example:
 # @CODE
-- 
2.35.1




[gentoo-dev] [PATCH 08/18] distutils-r1.eclass: Introduce DISTUTILS_USE_PEP517=no mode

2022-06-04 Thread Michał Górny
Introduce a new DISTUTILS_USE_PEP517 value "no" that stands for
"no build system".  This is primarily meant to replace the legacy
distutils-r1 logic used for bootstrapping baseline PEP 517 packages.
At the same time, it provides a convenient replacement for some
of the uses of python-r1.

In this mode, the eclass does not add PEP517-specific dependencies
and does not export default python_compile() and python_install()
implementations.  However, it does set dependencies, REQUIRED_USE
and enables sub-phase usage (with respect to DISTUTILS_OPTIONAL).
It also permits using distutils_enable_{sphinx,tests}.

Signed-off-by: Michał Górny 
---
 eclass/distutils-r1.eclass | 30 +-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
index 208bd2718cb8..30f7d941f0d4 100644
--- a/eclass/distutils-r1.eclass
+++ b/eclass/distutils-r1.eclass
@@ -106,6 +106,8 @@ esac
 #
 # - maturin - maturin backend
 #
+# - no - no PEP517 build system (see below)
+#
 # - pbr - pbr backend
 #
 # - pdm - pdm.pep517 backend
@@ -121,6 +123,17 @@ esac
 #
 # The variable needs to be set before the inherit line.  The eclass
 # adds appropriate build-time dependencies and verifies the value.
+#
+# The special value "no" indicates that the package has no build system.
+# This is not equivalent to unset DISTUTILS_USE_PEP517 (legacy mode).
+# It causes the eclass not to include any build system dependencies
+# and to disable default python_compile() and python_install()
+# implementations.  Baseline Python deps and phase functions will still
+# be set (depending on the value of DISTUTILS_OPTIONAL).  Most of
+# the other eclass functions will work.  Testing venv will be provided
+# in ${BUILD_DIR}/install after python_compile(), and if any (other)
+# files are found in ${BUILD_DIR}/install after python_install(), they
+# will be merged into ${D}.
 
 # @ECLASS_VARIABLE: DISTUTILS_USE_SETUPTOOLS
 # @DEFAULT_UNSET
@@ -212,6 +225,10 @@ _distutils_set_globals() {
bdep+='

>=dev-util/maturin-0.12.7[${PYTHON_USEDEP}]'
;;
+   no)
+   # undo the generic deps added above
+   bdep=
+   ;;
pbr)
bdep+='

>=dev-python/pbr-5.8.0-r1[${PYTHON_USEDEP}]'
@@ -789,7 +806,7 @@ distutils_install_for_testing() {
 distutils_write_namespace() {
debug-print-function ${FUNCNAME} "${@}"
 
-   if [[ ! ${DISTUTILS_USE_PEP517} ]]; then
+   if [[ ! ${DISTUTILS_USE_PEP517:-no} != no ]]; then
die "${FUNCNAME} is available only in PEP517 mode"
fi
if [[ ${EBUILD_PHASE} != test || ! ${BUILD_DIR} ]]; then
@@ -912,6 +929,9 @@ _distutils-r1_print_package_versions() {
dev-util/maturin
)
;;
+   no)
+   return
+   ;;
pbr)
packages+=(
dev-python/pbr
@@ -1207,6 +1227,10 @@ distutils_pep517_install() {
debug-print-function ${FUNCNAME} "${@}"
[[ ${#} -eq 1 ]] || die "${FUNCNAME} takes exactly one argument: root"
 
+   if [[ ! ${DISTUTILS_USE_PEP517:-no} != no ]]; then
+   die "${FUNCNAME} is available only in PEP517 mode"
+   fi
+
local root=${1}
local -x WHEEL_BUILD_DIR=${BUILD_DIR}/wheel
mkdir -p "${WHEEL_BUILD_DIR}" || die
@@ -1351,6 +1375,9 @@ distutils-r1_python_compile() {
in_iuse debug && use debug &&
MATURIN_PEP517_ARGS+=" 
--cargo-extra-args=--profile=dev"
;;
+   no)
+   return
+   ;;
esac
 
if [[ ${DISTUTILS_USE_PEP517} ]]; then
@@ -1472,6 +1499,7 @@ distutils-r1_python_test() {
 distutils-r1_python_install() {
debug-print-function ${FUNCNAME} "${@}"
 
+   [[ ${DISTUTILS_USE_PEP517} == no ]] && return
_python_check_EPYTHON
 
local scriptdir=${EPREFIX}/usr/bin
-- 
2.35.1




[gentoo-dev] [PATCH 07/18] distutils-r1.eclass: Move venv/merge-root logic to post-phases

2022-06-04 Thread Michał Górny
Move the PEP517 venv logic, install executable wrapping and root-merging
logic all into post-phases.  This will enable the ebuilds that do not
use the standard phase implementations to use them.

Signed-off-by: Michał Górny 
---
 eclass/distutils-r1.eclass | 124 ++---
 1 file changed, 73 insertions(+), 51 deletions(-)

diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
index 1d7bea6d8cab..208bd2718cb8 100644
--- a/eclass/distutils-r1.eclass
+++ b/eclass/distutils-r1.eclass
@@ -1361,33 +1361,7 @@ distutils-r1_python_compile() {
addpredict /usr/lib/portage/pym
addpredict /usr/local # bug 498232
 
-   local root=${BUILD_DIR}/install
-   distutils_pep517_install "${root}"
-
-   # copy executables to python-exec directory
-   # we do it early so that we can alter bindir recklessly
-   local bindir=${root}${EPREFIX}/usr/bin
-   local rscriptdir=${root}$(python_get_scriptdir)
-   [[ -d ${rscriptdir} ]] &&
-   die "${rscriptdir} should not exist!"
-   if [[ -d ${bindir} ]]; then
-   mkdir -p "${rscriptdir}" || die
-   cp -a --reflink=auto "${bindir}"/. "${rscriptdir}"/ || 
die
-   fi
-
-   # enable venv magic inside the install tree
-   mkdir -p "${bindir}" || die
-   ln -s "${PYTHON}" "${bindir}/${EPYTHON}" || die
-   ln -s "${EPYTHON}" "${bindir}/python3" || die
-   ln -s "${EPYTHON}" "${bindir}/python" || die
-   cat > "${bindir}"/pyvenv.cfg <<-EOF || die
-   include-system-site-packages = true
-   EOF
-
-   # we need to change shebangs to point to the venv-python
-   find "${bindir}" -type f -exec sed -i \
-   -e 
"1s@^#!\(${EPREFIX}/usr/bin/\(python\|pypy\)\)@#!${root}\1@" \
-   {} + || die
+   distutils_pep517_install "${BUILD_DIR}/install"
fi
 }
 
@@ -1501,18 +1475,7 @@ distutils-r1_python_install() {
_python_check_EPYTHON
 
local scriptdir=${EPREFIX}/usr/bin
-   if [[ ${DISTUTILS_USE_PEP517} ]]; then
-   local root=${BUILD_DIR}/install
-   # remove the altered bindir, executables from the package
-   # are already in scriptdir
-   rm -r "${root}${scriptdir}" || die
-   if [[ ${DISTUTILS_SINGLE_IMPL} ]]; then
-   local wrapped_scriptdir=${root}$(python_get_scriptdir)
-   if [[ -d ${wrapped_scriptdir} ]]; then
-   mv "${wrapped_scriptdir}" "${root}${scriptdir}" 
|| die
-   fi
-   fi
-   else
+   if [[ ! ${DISTUTILS_USE_PEP517} ]]; then
local root=${D%/}/_${EPYTHON}
[[ ${DISTUTILS_SINGLE_IMPL} ]] && root=${D%/}
 
@@ -1565,18 +1528,6 @@ distutils-r1_python_install() {
 
esetup.py "${args[@]}"
fi
-
-   if [[ ! ${DISTUTILS_SINGLE_IMPL} || ${DISTUTILS_USE_PEP517} ]]; then
-   multibuild_merge_root "${root}" "${D%/}"
-   if [[ ${DISTUTILS_USE_PEP517} ]]; then
-   # we need to recompile everything here in order to embed
-   # the correct paths
-   python_optimize "${D%/}$(python_get_sitedir)"
-   fi
-   fi
-   if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
-   _distutils-r1_wrap_scripts "${scriptdir}"
-   fi
 }
 
 # @FUNCTION: distutils-r1_python_install_all
@@ -1764,6 +1715,43 @@ distutils-r1_src_configure() {
return ${ret}
 }
 
+# @FUNCTION: _distutils-r1_post_python_compile
+# @INTERNAL
+# @DESCRIPTION:
+# Post-phase function called after python_compile.  In PEP517 mode,
+# it adjusts the install tree for venv-style usage.
+_distutils-r1_post_python_compile() {
+   debug-print-function ${FUNCNAME} "${@}"
+
+   local root=${BUILD_DIR}/install
+   if [[ ${DISTUTILS_USE_PEP517} && -d ${root} ]]; then
+   # copy executables to python-exec directory
+   # we do it early so that we can alter bindir recklessly
+   local bindir=${root}${EPREFIX}/usr/bin
+   local rscriptdir=${root}$(python_get_scriptdir)
+   [[ -d ${rscriptdir} ]] &&
+   die "${rscriptdir} should not exist!"
+   if [[ -d ${bindir} ]]; then
+   mkdir -p "${rscriptdir}" || die
+   cp -a --reflink=auto "${bindir}"/. "${rscriptdir}"/ || 
die
+   fi
+
+   # enable venv magic inside the install tree
+   mkdir -p "${bindir}" || die
+   ln -s "${PYTHON}" "${bindir}/${EPYTHON}" || die
+   ln -s "${EPYTHON}" "${bindir}/python3" || die
+   ln -s "${EPYTHON}" 

[gentoo-dev] [PATCH 06/18] distutils-r1.eclass: Make *-nspkg.pth warning fatal for EAPI 9+

2022-06-04 Thread Michał Górny
Now that we've essentially removed non-implicit namespace packages
from Gentoo and setuptools upstream has deprecated their old solution,
it's time to make this check fatal.  Unfortunately, I did not think
of it when adding PEP517 mode, so let's do that in EAPI 9.

Signed-off-by: Michał Górny 
---
 eclass/distutils-r1.eclass | 4 
 1 file changed, 4 insertions(+)

diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
index b0318410b100..1d7bea6d8cab 100644
--- a/eclass/distutils-r1.eclass
+++ b/eclass/distutils-r1.eclass
@@ -1865,6 +1865,10 @@ _distutils-r1_check_namespace_pth() {
ewarn "the ebuild accordingly:"
ewarn
ewarn "  
https://projects.gentoo.org/python/guide/concept.html#namespace-packages;
+
+   if ! has "${EAPI}" 6 7 8; then
+   die "*-nspkg.pth files are banned in EAPI ${EAPI}"
+   fi
fi
 }
 
-- 
2.35.1




[gentoo-dev] [PATCH 05/18] distutils-r1.eclass: Remove the obsolete pypy/share check

2022-06-04 Thread Michał Górny
The PyPy 'share' directory check was necessary because of the historical
prefix logic that we patched in Gentoo.  All modern versions of PyPy
use '/usr' as sys.prefix natively, so the check is no longer needed.

Signed-off-by: Michał Górny 
---
 eclass/distutils-r1.eclass | 12 
 1 file changed, 12 deletions(-)

diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
index 30391ad67f3a..b0318410b100 100644
--- a/eclass/distutils-r1.eclass
+++ b/eclass/distutils-r1.eclass
@@ -1839,18 +1839,6 @@ _distutils-r1_post_python_install() {
die "Package installs '${p}' package which is forbidden 
and likely a bug in the build system."
fi
done
-
-   local shopt_save=$(shopt -p nullglob)
-   shopt -s nullglob
-   local pypy_dirs=(
-   "${D}${EPREFIX}/usr/$(get_libdir)"/pypy*/share
-   "${D}${EPREFIX}/usr/lib"/pypy*/share
-   )
-   ${shopt_save}
-
-   if [[ -n ${pypy_dirs} ]]; then
-   die "Package installs 'share' in PyPy prefix, see bug #465546."
-   fi
 }
 
 # @FUNCTION: _distutils-r1_check_namespace_pth
-- 
2.35.1




[gentoo-dev] [PATCH 04/18] distutils-r1.eclass: Move install QA checks to post-phase function

2022-06-04 Thread Michał Górny
Perform the install QA check (the invalid package name check) in a post-
phase function.  This enables it to be performed even when
distutils-r1_python_install is not used.

Signed-off-by: Michał Górny 
---
 eclass/distutils-r1.eclass | 54 ++
 1 file changed, 31 insertions(+), 23 deletions(-)

diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
index b690f21f9159..30391ad67f3a 100644
--- a/eclass/distutils-r1.eclass
+++ b/eclass/distutils-r1.eclass
@@ -1566,29 +1566,6 @@ distutils-r1_python_install() {
esetup.py "${args[@]}"
fi
 
-   local forbidden_package_names=(
-   examples test tests
-   .pytest_cache .hypothesis
-   )
-   local p
-   for p in "${forbidden_package_names[@]}"; do
-   if [[ -d ${root}$(python_get_sitedir)/${p} ]]; then
-   die "Package installs '${p}' package which is forbidden 
and likely a bug in the build system."
-   fi
-   done
-
-   local shopt_save=$(shopt -p nullglob)
-   shopt -s nullglob
-   local pypy_dirs=(
-   "${root}${EPREFIX}/usr/$(get_libdir)"/pypy*/share
-   "${root}${EPREFIX}/usr/lib"/pypy*/share
-   )
-   ${shopt_save}
-
-   if [[ -n ${pypy_dirs} ]]; then
-   die "Package installs 'share' in PyPy prefix, see bug #465546."
-   fi
-
if [[ ! ${DISTUTILS_SINGLE_IMPL} || ${DISTUTILS_USE_PEP517} ]]; then
multibuild_merge_root "${root}" "${D%/}"
if [[ ${DISTUTILS_USE_PEP517} ]]; then
@@ -1845,6 +1822,37 @@ distutils-r1_src_test() {
return ${ret}
 }
 
+# @FUNCTION: _distutils-r1_post_python_install
+# @INTERNAL
+# @DESCRIPTION:
+# Post-phase function called after python_install.
+_distutils-r1_post_python_install() {
+   debug-print-function ${FUNCNAME} "${@}"
+
+   local forbidden_package_names=(
+   examples test tests
+   .pytest_cache .hypothesis
+   )
+   local p
+   for p in "${forbidden_package_names[@]}"; do
+   if [[ -d ${D}$(python_get_sitedir)/${p} ]]; then
+   die "Package installs '${p}' package which is forbidden 
and likely a bug in the build system."
+   fi
+   done
+
+   local shopt_save=$(shopt -p nullglob)
+   shopt -s nullglob
+   local pypy_dirs=(
+   "${D}${EPREFIX}/usr/$(get_libdir)"/pypy*/share
+   "${D}${EPREFIX}/usr/lib"/pypy*/share
+   )
+   ${shopt_save}
+
+   if [[ -n ${pypy_dirs} ]]; then
+   die "Package installs 'share' in PyPy prefix, see bug #465546."
+   fi
+}
+
 # @FUNCTION: _distutils-r1_check_namespace_pth
 # @INTERNAL
 # @DESCRIPTION:
-- 
2.35.1




[gentoo-dev] [PATCH 03/18] distutils-r1.eclass: Call egg-info cleanup via post-test phase

2022-06-04 Thread Michał Górny
Signed-off-by: Michał Górny 
---
 eclass/distutils-r1.eclass | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
index d6fd176192de..b690f21f9159 100644
--- a/eclass/distutils-r1.eclass
+++ b/eclass/distutils-r1.eclass
@@ -1818,15 +1818,24 @@ _distutils-r1_clean_egg_info() {
rm -rf "${BUILD_DIR}"/lib/*.egg-info || die
 }
 
+# @FUNCTION: _distutils-r1_post_python_test
+# @INTERNAL
+# @DESCRIPTION:
+# Post-phase function called after python_test.
+_distutils-r1_post_python_test() {
+   debug-print-function ${FUNCNAME} "${@}"
+
+   if [[ ! ${DISTUTILS_USE_PEP517} ]]; then
+   _distutils-r1_clean_egg_info
+   fi
+}
+
 distutils-r1_src_test() {
debug-print-function ${FUNCNAME} "${@}"
local ret=0
 
if declare -f python_test >/dev/null; then
_distutils-r1_run_foreach_impl python_test || ret=${?}
-   if [[ ! ${DISTUTILS_USE_PEP517} ]]; then
-   _distutils-r1_run_foreach_impl 
_distutils-r1_clean_egg_info
-   fi
fi
 
if declare -f python_test_all >/dev/null; then
-- 
2.35.1




[gentoo-dev] [PATCH 02/18] distutils-r1.eclass: Support internal post-python_* phase functions

2022-06-04 Thread Michał Górny
Support running additional post-python_* phase functions for internal
usage.  The goal is to replace some of the inline logic
in distutils-r1_python_* functions that relies on the user calling them
and additional calls to python_foreach_impl.

Signed-off-by: Michał Górny 
---
 eclass/distutils-r1.eclass | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
index ed368da79896..d6fd176192de 100644
--- a/eclass/distutils-r1.eclass
+++ b/eclass/distutils-r1.eclass
@@ -1687,6 +1687,11 @@ distutils-r1_run_phase() {
fi
 
cd "${_DISTUTILS_INITIAL_CWD}" || die
+   if [[ ! ${_DISTUTILS_IN_COMMON_IMPL} ]] &&
+   declare -f "_distutils-r1_post_python_${EBUILD_PHASE}" 
>/dev/null
+   then
+   "_distutils-r1_post_python_${EBUILD_PHASE}"
+   fi
return "${ret}"
 }
 
@@ -1701,6 +1706,7 @@ distutils-r1_run_phase() {
 # of sources made for the selected Python interpreter.
 _distutils-r1_run_common_phase() {
local DISTUTILS_ORIG_BUILD_DIR=${BUILD_DIR}
+   local _DISTUTILS_IN_COMMON_IMPL=1
 
if [[ ${DISTUTILS_SINGLE_IMPL} ]]; then
# reuse the dedicated code branch
-- 
2.35.1




[gentoo-dev] [PATCH 01/18] python-utils-r1.eclass: Strip stray *-pytest-*.pyc files in epytest

2022-06-04 Thread Michał Górny
The test suites of pytest plugins cause additional *-pytest-*.pyc files
to be created.  Remove them in order to prevent them from being
installed alongside the package.

Closes: https://bugs.gentoo.org/847235
Signed-off-by: Michał Górny 
---
 eclass/python-utils-r1.eclass | 5 +
 1 file changed, 5 insertions(+)

diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass
index 67dc5bf754d6..9eb068d3b13f 100644
--- a/eclass/python-utils-r1.eclass
+++ b/eclass/python-utils-r1.eclass
@@ -1318,6 +1318,11 @@ epytest() {
 
# remove common temporary directories left over by pytest plugins
rm -rf .hypothesis .pytest_cache || die
+   # pytest plugins create additional .pyc files while testing
+   # see e.g. https://bugs.gentoo.org/847235
+   if [[ -n ${BUILD_DIR} && -d ${BUILD_DIR} ]]; then
+   find "${BUILD_DIR}" -name '*-pytest-*.pyc' -delete || die
+   fi
 
return ${ret}
 }
-- 
2.35.1




[gentoo-dev] [PATCH 00/18] distutils-r1.eclass D_U_PEP517=no mode & other patches

2022-06-04 Thread Michał Górny
Hi,

Here's another large-ish patchset for the Python eclass.  The primary
highlight is DISTUTILS_USE_PEP517=no mode explained below.  In addition
to that, some refactoring, bug fixes and other changes collected
to avoid updating the metadata cache twice.


D_U_PEP517=no mode basically gives you the best of distutils-r1 features
without default python_* phases or build system-specific dependencies.
This means to cover 3 use cases:

1) packages that can't use PEP517 to avoid cyclic deps in bootstrap,

2) trivial packages without a build system,

3) Python-ish packages without a PEP517 build system (e.g. using plain
   meson).

Before, these either required legacy mode (that I'd like to eventually
remove, many years from now) or using python-r1 directly.  Thanks to
the new mode, they can benefit from convenient python_* phases, default
Python deps (unless you're using DISTUTILS_OPTIONAL), the test-scope
venv logic, distutils_enable_tests, etc.

There are two main methods of using it: either declare phases up to
python_install() and install files straight to ${D}, or install them
to ${BUILD_DIR}/install during python_compile() and the eclass will pick
it up.  The latter method gives you working venv for python_test() too.

I've included a few example ebuilds in the middle of patch set.  tomli
and installer ebuilds demonstrate using python_compile() to install
Python modules and use them in tests.  gpep517 uses python_install().
gnome-abrt demonstrates working with meson (yes, I know it's the old
version).


Other changes are:

- removing incidental install of temporary cache files (*-pytest-*.pyc)
  from epytest

- internal refactoring to make post-python_install() QA checks,
  ${BUILD_DIR}/install merging and post-python_compile() test venv setup
  (in PEP517 mode) work independently of python_compile()
  and python_install() overrides

- *-nspkg.pth warning will become an error in EAPI 9

- python_domodule() now works outside src_install(), by installing
  into ${BUILD_DIR}/install (and therefore fits part with distutils-r1)

- other python_do*() and python_new*() functions now fail if called
  outside src_install()

- add `_trial_temp` to disallowed top-level packages

- minor doc fixes


-- 
Best regards,
Michał Górny

Arthur Zamarin (2):
  python-any-r1.eclass: use python_has_version in examples
  distutils-r1.eclass: small docs format fixes

Michał Górny (16):
  python-utils-r1.eclass: Strip stray *-pytest-*.pyc files in epytest
  distutils-r1.eclass: Support internal post-python_* phase functions
  distutils-r1.eclass: Call egg-info cleanup via post-test phase
  distutils-r1.eclass: Move install QA checks to post-phase function
  distutils-r1.eclass: Remove the obsolete pypy/share check
  distutils-r1.eclass: Make *-nspkg.pth warning fatal for EAPI 9+
  distutils-r1.eclass: Move venv/merge-root logic to post-phases
  distutils-r1.eclass: Introduce DISTUTILS_USE_PEP517=no mode
  python-utils-r1.eclass: Fix typo in python_moduleinto doc
  python-utils-r1.eclass: Support python_domodule outside src_install
  python-utils-r1.eclass: Add explicit checks for incorrect phase
  dev-python/tomli: Use DISTUTILS_USE_PEP517=no
  dev-python/installer: Use DISTUTILS_USE_PEP517=no
  dev-python/gpep517: Use DISTUTILS_USE_PEP517=no
  app-admin/gnome-abrt: Use DISTUTILS_USE_PEP517=no
  distutils-r1.eclass: Add "_trial_temp" to forbidden package names

 .../gnome-abrt/gnome-abrt-1.4.1-r1.ebuild |  57 +
 dev-python/gpep517/gpep517-6-r1.ebuild|  41 
 .../installer/installer-0.5.1-r1.ebuild   |  37 +++
 dev-python/tomli/tomli-2.0.1-r1.ebuild|  36 +++
 eclass/distutils-r1.eclass| 230 --
 eclass/python-any-r1.eclass   |  10 +-
 eclass/python-utils-r1.eclass |  55 -
 7 files changed, 369 insertions(+), 97 deletions(-)
 create mode 100644 app-admin/gnome-abrt/gnome-abrt-1.4.1-r1.ebuild
 create mode 100644 dev-python/gpep517/gpep517-6-r1.ebuild
 create mode 100644 dev-python/installer/installer-0.5.1-r1.ebuild
 create mode 100644 dev-python/tomli/tomli-2.0.1-r1.ebuild

-- 
2.35.1




Re: [gentoo-dev] [PATCH v2 1/1] esed.eclass: new eclass

2022-06-04 Thread Ionen Wolkens
On Fri, Jun 03, 2022 at 07:15:17PM -0500, Oskari Pirhonen wrote:
[snip[
> Testing for (in)equality between pre- and post-sed contents is
> reasonable enough in most cases. This time, though, it would fail to
> detect anything has changed since the pre-sed contents have their NULL's
> unintentionally stripped, whereas the post-sed contents have them
> intentionally stripped.
>
> While I personally don't think that running sed on binary files is a
> good idea in the first place, it's still relevant since the end result
> would be an incorrect answer to the question of "Did sed actually do
> anything?".

Yeah one of the primary motivation to silence this was elsewhere, I
don't think silencing matters for esed and if binary files are being
modified may as well use sed(1) directly instead (this is something
that'd need to be more intensively verified on bumps than with esed
anyway).

Use is also very uncommon, although sed is still "handy" when changing
just 1 instruction and want to avoid an extra dependency on a proper
binary patching method.
 
> On the other hand, saving a set of pre- and post-sed hashes like Ulrich
> suggested would give the expected result.

If really wanted to solve this yes, although it may make sense to say
this eclass is not for binary files. The talk to add bash-only "erepl"
makes it rather difficult to preserve nulls (mapfile silently strip \0
without even a warning). mapfile -d '' could allow to restore them
but ideally want to iterate on lines to do per-line pattern matches.
Is it possible to hack away something to preserve? Probably.. but it's
going to make this messy and I'm not sure it's worth it.

erepl is also worse because they'll be lost in output and not just
during comparison.

-- 
ionen


signature.asc
Description: PGP signature