commit:     e5b7b8a3ac0a710272e174851673e5eb74250a69
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Tue Jun  3 01:56:06 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Tue Jun  3 01:57:07 2025 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=e5b7b8a3

bin: env-update, dispatch-conf: add missing __name__ main guards for Python 3.14

The remaining test failures I see with Python 3.14 look like:
```
RuntimeError:
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.

        This probably means that you are not using fork to start your
        child processes and you have forgotten to use the proper idiom
        in the main module:

            if __name__ == '__main__':
                freeze_support()
                ...

        The "freeze_support()" line can be omitted if the program
        is not going to be frozen to produce an executable.

        To fix this issue, refer to the "Safe importing of main module"
        section in https://docs.python.org/3/library/multiprocessing.html
```

We're indeed missing some of those guards, so let's add them in.

Bug: https://bugs.gentoo.org/941956
Signed-off-by: Sam James <sam <AT> gentoo.org>

 bin/dispatch-conf | 29 +++++++++++++++--------------
 bin/env-update    | 44 +++++++++++++++++++++++---------------------
 2 files changed, 38 insertions(+), 35 deletions(-)

diff --git a/bin/dispatch-conf b/bin/dispatch-conf
index 2e72562439..92f1490048 100755
--- a/bin/dispatch-conf
+++ b/bin/dispatch-conf
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-# Copyright 1999-2021 Gentoo Authors
+# Copyright 1999-2025 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 #
@@ -595,18 +595,19 @@ def usage(argv):
     sys.exit(os.EX_OK)
 
 
-for x in sys.argv:
-    if x in ("-h", "--help"):
-        usage(sys.argv)
-    elif x in ("--version",):
-        print("Portage", portage.VERSION)
-        sys.exit(os.EX_OK)
+if __name__ == "__main__":
+    for x in sys.argv:
+        if x in ("-h", "--help"):
+            usage(sys.argv)
+        elif x in ("--version",):
+            print("Portage", portage.VERSION)
+            sys.exit(os.EX_OK)
 
-# run
-d = dispatch()
+    # run
+    d = dispatch()
 
-if len(sys.argv) > 1:
-    # for testing
-    d.grind(sys.argv[1:])
-else:
-    d.grind(portage.settings.get("CONFIG_PROTECT", "").split())
+    if len(sys.argv) > 1:
+        # for testing
+        d.grind(sys.argv[1:])
+    else:
+        d.grind(portage.settings.get("CONFIG_PROTECT", "").split())

diff --git a/bin/env-update b/bin/env-update
index 487bd80e48..f1730b8001 100755
--- a/bin/env-update
+++ b/bin/env-update
@@ -1,10 +1,21 @@
 #!/usr/bin/env python
-# Copyright 1999-2023 Gentoo Authors
+# Copyright 1999-2025 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 import errno
 import sys
 
+from os import path as osp
+
+makelinks = 1
+
+if osp.isfile(
+    osp.join(osp.dirname(osp.dirname(osp.realpath(__file__))), 
".portage_not_installed")
+):
+    sys.path.insert(
+        0, osp.join(osp.dirname(osp.dirname(osp.realpath(__file__))), "lib")
+    )
+
 
 def usage(status):
     print("Usage: env-update [--no-ldconfig]")
@@ -13,31 +24,22 @@ def usage(status):
     sys.exit(status)
 
 
-if "-h" in sys.argv or "--help" in sys.argv:
-    usage(0)
+if __name__ == "__main__":
+    if "-h" in sys.argv or "--help" in sys.argv:
+        usage(0)
 
-makelinks = 1
-if "--no-ldconfig" in sys.argv:
-    makelinks = 0
-    sys.argv.pop(sys.argv.index("--no-ldconfig"))
+    if "--no-ldconfig" in sys.argv:
+        makelinks = 0
+        sys.argv.pop(sys.argv.index("--no-ldconfig"))
 
-if len(sys.argv) > 1:
-    print("!!! Invalid command line options!\n")
-    usage(1)
+    if len(sys.argv) > 1:
+        print("!!! Invalid command line options!\n")
+        usage(1)
 
-from os import path as osp
+    import portage
 
-if osp.isfile(
-    osp.join(osp.dirname(osp.dirname(osp.realpath(__file__))), 
".portage_not_installed")
-):
-    sys.path.insert(
-        0, osp.join(osp.dirname(osp.dirname(osp.realpath(__file__))), "lib")
-    )
-import portage
+    portage._internal_caller = True
 
-portage._internal_caller = True
-
-if __name__ == "__main__":
     try:
         portage.env_update(makelinks)
     except OSError as e:

Reply via email to