commit:     a0ed53f9996f4e44c8a04c98a6356be67ccf3cef
Author:     Florian Schmaus <flow <AT> gentoo <DOT> org>
AuthorDate: Thu Feb 19 18:25:30 2026 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Feb 20 13:38:16 2026 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=a0ed53f9

emerge: allow for "--jobs n" to disable parallel emerge jobs

If the user has

EMERGE_DEFAULT_OPTS="${EMERGE_DEFAULT_OPTS} --jobs 0"

in /etc/portage/make.conf, then there was previously no way to disable
parallel emerge jobs again. This allows to disable parallel emerge
jobs by specifying "--jobs n" with the emerge command line.

This also slightly cleans up the logic if myoptions.jobs is not True,
y or n: Since jobs can then only ever be None if a ValueError is
thrown, move the parser.error() statement in the except block

Signed-off-by: Florian Schmaus <flow <AT> gentoo.org>
Part-of: https://github.com/gentoo/portage/pull/1555
Closes: https://github.com/gentoo/portage/pull/1555
Signed-off-by: Sam James <sam <AT> gentoo.org>

 lib/_emerge/main.py | 21 +++++++++++++++------
 man/emerge.1        |  3 ++-
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/lib/_emerge/main.py b/lib/_emerge/main.py
index f176e40e44..b5ff354b45 100644
--- a/lib/_emerge/main.py
+++ b/lib/_emerge/main.py
@@ -128,6 +128,14 @@ def insert_optional_args(args):
         "n",
     )
 
+    class valid_integers_or_y_or_n:
+        def __contains__(self, s):
+            if s in valid_integers:
+                return True
+            return s in y_or_n
+
+    valid_integers_or_y_or_n = valid_integers_or_y_or_n()
+
     new_args = []
 
     default_arg_opts = {
@@ -155,7 +163,7 @@ def insert_optional_args(args):
         "--getbinpkg": y_or_n,
         "--getbinpkgonly": y_or_n,
         "--ignore-world": y_or_n,
-        "--jobs": valid_integers,
+        "--jobs": valid_integers_or_y_or_n,
         "--jobs-tmpdir-require-free-gb": valid_integers,
         "--keep-going": y_or_n,
         "--load-average": valid_floats,
@@ -1005,17 +1013,18 @@ def parse_opts(tmpcmdline, silent=False):
 
     if myoptions.jobs is not None:
         jobs = None
-        if myoptions.jobs == "True":
+        if myoptions.jobs in ("True", "y"):
             jobs = True
+        elif myoptions.jobs == "n":
+            jobs = None
         else:
             try:
                 jobs = int(myoptions.jobs)
             except ValueError:
-                jobs = None
+                if not silent:
+                    parser.error(f"Invalid --jobs parameter: 
'{myoptions.jobs}'\n")
 
-        if jobs is None and not silent:
-            parser.error(f"Invalid --jobs parameter: '{myoptions.jobs}'\n")
-        elif jobs == 0:
+        if jobs == 0:
             from portage.util.cpuinfo import get_cpu_count
 
             jobs = get_cpu_count()

diff --git a/man/emerge.1 b/man/emerge.1
index ff242eacb6..6cadec2fdf 100644
--- a/man/emerge.1
+++ b/man/emerge.1
@@ -701,7 +701,8 @@ in the \fBmake.conf\fR(5) man page.
 Specifies the number of packages to build simultaneously. If this option is
 given without an argument, emerge will not limit the number of jobs that can
 run simultaneously.  If 0 is given as argument, emerge will limit the jobs to
-the number of processors.  Also see the related \fB\-\-load\-average\fR option.
+the number of processors.  Using 'n' as argument can be used to disable this
+setting.  Also see the related \fB\-\-load\-average\fR option.
 Similarly to the \-\-quiet\-build option, the \-\-jobs option causes all
 build output to be redirected to logs.
 Note that interactive packages currently force a setting

Reply via email to