]> git.eshelyaron.com Git - emacs.git/commitdiff
Support Python 3 in 'package-test-update-archives-async'
authorkobarity <kobarity@gmail.com>
Thu, 9 May 2024 15:39:10 +0000 (00:39 +0900)
committerEshel Yaron <me@eshelyaron.com>
Sun, 12 May 2024 15:49:08 +0000 (17:49 +0200)
* test/lisp/emacs-lisp/package-resources/package-test-server.py:
Support Python 3.
* test/lisp/emacs-lisp/package-tests.el
(package-test-update-archives-async): Search for an executable
named "python", "python3", or "python2".  (Bug#70722)

Co-authored-by: Lin Sun <sunlin7@hotmail.com>
(cherry picked from commit 6380806196f3806b6c2bff60ff6cddae3eee2a19)

test/lisp/emacs-lisp/package-resources/package-test-server.py
test/lisp/emacs-lisp/package-tests.el

index 128b4249ec366854db028e186262d89aabbf3dda..16f3e391aa11be98ce19847dc066b59fd722b713 100644 (file)
@@ -1,23 +1,19 @@
 import sys
-import BaseHTTPServer
-from SimpleHTTPServer import SimpleHTTPRequestHandler
 
+try:
+    from http.server import HTTPServer, SimpleHTTPRequestHandler
+except ImportError:
+    from BaseHTTPServer import HTTPServer
+    from SimpleHTTPServer import SimpleHTTPRequestHandler
 
-HandlerClass = SimpleHTTPRequestHandler
-ServerClass  = BaseHTTPServer.HTTPServer
-Protocol     = "HTTP/1.0"
-
-if sys.argv[1:]:
-    port = int(sys.argv[1])
-else:
-    port = 0
-server_address = ('127.0.0.1', port)
 
-HandlerClass.protocol_version = Protocol
-httpd = ServerClass(server_address, HandlerClass)
+HandlerClass = SimpleHTTPRequestHandler
+HandlerClass.protocol_version = "HTTP/1.0"
+server_address = ("127.0.0.1", int(sys.argv[1]) if sys.argv[1:] else 0)
+httpd = HTTPServer(server_address, HandlerClass)
 
 ip, port = httpd.socket.getsockname()[0:2]
-print ("Server started, http://%s:%s/" % (ip, port))
+print("Server started, http://%s:%s/" % (ip, port))
 # Flush in case we're in full buffering mode (instead of line
 # buffering), this might happen if python is a cygwin program and we
 # run it from a native w32 program.
index d95b94f214535e40096bbb4a48a1f818481c0614..692d655025042d6b69cd28154976d52d9678fa2c 100644 (file)
@@ -634,14 +634,15 @@ but with a different end of line convention (bug#48137)."
 (ert-deftest package-test-update-archives-async ()
   "Test updating package archives asynchronously."
   :tags '(:expensive-test)
-  (skip-unless (executable-find "python2"))
   (let* ((package-menu-async t)
          (default-directory package-test-data-dir)
-         (process (start-process
+         (python-interpreter (seq-some #'executable-find '("python" "python3" "python2")))
+         process addr)
+    (skip-unless python-interpreter)
+    (setq process (start-process
                    "package-server" "package-server-buffer"
-                   (executable-find "python2")
+                   python-interpreter
                    "package-test-server.py"))
-         (addr nil))
     (unwind-protect
         (progn
           (with-current-buffer "package-server-buffer"