unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#70722: [PATCH] ; Migrate to python3 for (package-test-update-archives-async)
@ 2024-05-02 18:11 Lin Sun
  2024-05-02 18:54 ` Eli Zaretskii
  0 siblings, 1 reply; 7+ messages in thread
From: Lin Sun @ 2024-05-02 18:11 UTC (permalink / raw)
  To: 70722

[-- Attachment #1: Type: text/plain, Size: 236 bytes --]

Hi,
The test case "package-test-update-archives-async" still tries to
search "python2" for testing, while python2 was at the end of its life
years ago.
So move the test case from python2 to python3.
Please help review the patch. Thanks

[-- Attachment #2: 0001-Migrate-to-python3-for-package-test-update-archives-.patch --]
[-- Type: text/x-patch, Size: 2820 bytes --]

From fc41f0c78601f9ca92ce5be4572a2d9b38822d28 Mon Sep 17 00:00:00 2001
From: Lin Sun <sunlin7@hotmail.com>
Date: Thu, 2 May 2024 06:52:09 +0000
Subject: [PATCH] ; Migrate to python3 for (package-test-update-archives-async)

* package-test-update-archives-async (package-test-update-archives-async):
  Try search python3 or python instead of pyhton2.
* test/lisp/emacs-lisp/package-resources/package-test-server.py:
  Rewrite script with python3.
---
 .../package-resources/package-test-server.py   | 18 +++++-------------
 test/lisp/emacs-lisp/package-tests.el          | 10 ++++++----
 2 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/test/lisp/emacs-lisp/package-resources/package-test-server.py b/test/lisp/emacs-lisp/package-resources/package-test-server.py
index 128b4249ec3..2b915823aa2 100644
--- a/test/lisp/emacs-lisp/package-resources/package-test-server.py
+++ b/test/lisp/emacs-lisp/package-resources/package-test-server.py
@@ -1,20 +1,12 @@
 import sys
-import BaseHTTPServer
-from SimpleHTTPServer import SimpleHTTPRequestHandler
+from http.server import HTTPServer, 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))
diff --git a/test/lisp/emacs-lisp/package-tests.el b/test/lisp/emacs-lisp/package-tests.el
index d95b94f2145..f2cce5ae8dc 100644
--- a/test/lisp/emacs-lisp/package-tests.el
+++ b/test/lisp/emacs-lisp/package-tests.el
@@ -634,14 +634,16 @@ package-test-update-archives
 (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 (cl-some #'executable-find '("python3" "python")))
+         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"
-- 
2.20.5


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* bug#70722: [PATCH] ; Migrate to python3 for (package-test-update-archives-async)
  2024-05-02 18:11 bug#70722: [PATCH] ; Migrate to python3 for (package-test-update-archives-async) Lin Sun
@ 2024-05-02 18:54 ` Eli Zaretskii
  2024-05-06  0:28   ` Lin Sun
  0 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2024-05-02 18:54 UTC (permalink / raw)
  To: Lin Sun; +Cc: 70722

> From: Lin Sun <sunlin7.mail@gmail.com>
> Date: Thu, 2 May 2024 18:11:04 +0000
> 
> The test case "package-test-update-archives-async" still tries to
> search "python2" for testing, while python2 was at the end of its life
> years ago.
> So move the test case from python2 to python3.

I'd prefer to make the test support both Python 2.x and Python 3.x.
The fact that python.org end-of-life'd Python 2 doesn't mean we have
to jump to attention and follow suit.  Old systems might still have
Python 2 installed, and there's no need to drop them.

I do agree that we should try looking for Python 3 first, and only
afterwards for Python 2.

Also, I think the test should start by looking for just "python",
before the versioned variants.

E.g., on my system (executable-find "python3") returns nil, although I
have Python 3.x installed -- but it's installed under the name
"python".

Thanks.





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#70722: [PATCH] ; Migrate to python3 for (package-test-update-archives-async)
  2024-05-02 18:54 ` Eli Zaretskii
@ 2024-05-06  0:28   ` Lin Sun
  2024-05-09  8:33     ` Eli Zaretskii
  0 siblings, 1 reply; 7+ messages in thread
From: Lin Sun @ 2024-05-06  0:28 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 70722

[-- Attachment #1: Type: text/plain, Size: 1225 bytes --]

On Thu, May 2, 2024 at 6:55 PM Eli Zaretskii <eliz@gnu.org> wrote:
>
> > From: Lin Sun <sunlin7.mail@gmail.com>
> > Date: Thu, 2 May 2024 18:11:04 +0000
> >
> > The test case "package-test-update-archives-async" still tries to
> > search "python2" for testing, while python2 was at the end of its life
> > years ago.
> > So move the test case from python2 to python3.
>
> I'd prefer to make the test support both Python 2.x and Python 3.x.
> The fact that python.org end-of-life'd Python 2 doesn't mean we have
> to jump to attention and follow suit.  Old systems might still have
> Python 2 installed, and there's no need to drop them.
>
> I do agree that we should try looking for Python 3 first, and only
> afterwards for Python 2.
>
> Also, I think the test should start by looking for just "python",
> before the versioned variants.
>
> E.g., on my system (executable-find "python3") returns nil, although I
> have Python 3.x installed -- but it's installed under the name
> "python".
Thanks for the comment, and it's true that python2 will still exist
for many years.
And I had changed the test case to adapt python/python3/python2 automatically.
Please help review the new patch. Thanks.

[-- Attachment #2: 0001-Support-python3-for-package-test-update-archives-asy.patch --]
[-- Type: text/x-patch, Size: 3611 bytes --]

From 814d21df047460be1eae004ad2031a97059f4665 Mon Sep 17 00:00:00 2001
From: Lin Sun <sunlin7@hotmail.com>
Date: Thu, 2 May 2024 06:52:09 +0000
Subject: [PATCH] ; Support python3 for (package-test-update-archives-async)
 (bug#70722)

* lisp/emacs-lisp/package-tests.el (package-test-update-archives-async):
  Searching python/python3/pyhton2 and decides coresponding python
  script file.
* test/lisp/emacs-lisp/package-resources/package-test-server.py3:
  Python3 script for package test server.
---
 .../package-resources/package-test-server.py3 | 17 ++++++++++++
 test/lisp/emacs-lisp/package-tests.el         | 26 +++++++++++++++----
 2 files changed, 38 insertions(+), 5 deletions(-)
 create mode 100644 test/lisp/emacs-lisp/package-resources/package-test-server.py3

diff --git a/test/lisp/emacs-lisp/package-resources/package-test-server.py3 b/test/lisp/emacs-lisp/package-resources/package-test-server.py3
new file mode 100644
index 00000000000..8f2d2db5f96
--- /dev/null
+++ b/test/lisp/emacs-lisp/package-resources/package-test-server.py3
@@ -0,0 +1,17 @@
+## package-test-server.py3 -*- mode: python; coding: utf-8 -*-
+import sys
+from http.server import HTTPServer, SimpleHTTPRequestHandler
+
+
+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))
+# 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.
+sys.stdout.flush()
+httpd.serve_forever()
diff --git a/test/lisp/emacs-lisp/package-tests.el b/test/lisp/emacs-lisp/package-tests.el
index d95b94f2145..3309ba32e0d 100644
--- a/test/lisp/emacs-lisp/package-tests.el
+++ b/test/lisp/emacs-lisp/package-tests.el
@@ -634,14 +634,30 @@ 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 python-test-script
+         process addr)
+    (when-let* ((py-interpreter (executable-find "python"))
+                (py-ver (shell-command-to-string "python --version")))
+      (setq python-interpreter py-interpreter
+            python-test-script (if (string-match-p "Python 2" py-ver)
+                                 "package-test-server.py"
+                               "package-test-server.py3")))
+    (when-let* (((not python-interpreter))
+                (py-interpreter (executable-find "python3")))
+      (setq python-interpreter py-interpreter
+            python-test-script "package-test-server.py3"))
+    (when-let* (((not python-interpreter))
+                (py-interpreter (executable-find "python2")))
+      (setq python-interpreter py-interpreter
+            python-test-script "package-test-server.py"))
+
+    (skip-unless python-interpreter)
+
+    (setq process (start-process
                    "package-server" "package-server-buffer"
-                   (executable-find "python2")
-                   "package-test-server.py"))
-         (addr nil))
+                   python-interpreter python-test-script))
     (unwind-protect
         (progn
           (with-current-buffer "package-server-buffer"
-- 
2.20.5


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* bug#70722: [PATCH] ; Migrate to python3 for (package-test-update-archives-async)
  2024-05-06  0:28   ` Lin Sun
@ 2024-05-09  8:33     ` Eli Zaretskii
  2024-05-09 16:00       ` kobarity
  0 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2024-05-09  8:33 UTC (permalink / raw)
  To: Lin Sun, kobarity; +Cc: 70722

> From: Lin Sun <sunlin7.mail@gmail.com>
> Date: Mon, 6 May 2024 00:28:07 +0000
> Cc: 70722@debbugs.gnu.org
> 
> On Thu, May 2, 2024 at 6:55 PM Eli Zaretskii <eliz@gnu.org> wrote:
> >
> > > From: Lin Sun <sunlin7.mail@gmail.com>
> > > Date: Thu, 2 May 2024 18:11:04 +0000
> > >
> > > The test case "package-test-update-archives-async" still tries to
> > > search "python2" for testing, while python2 was at the end of its life
> > > years ago.
> > > So move the test case from python2 to python3.
> >
> > I'd prefer to make the test support both Python 2.x and Python 3.x.
> > The fact that python.org end-of-life'd Python 2 doesn't mean we have
> > to jump to attention and follow suit.  Old systems might still have
> > Python 2 installed, and there's no need to drop them.
> >
> > I do agree that we should try looking for Python 3 first, and only
> > afterwards for Python 2.
> >
> > Also, I think the test should start by looking for just "python",
> > before the versioned variants.
> >
> > E.g., on my system (executable-find "python3") returns nil, although I
> > have Python 3.x installed -- but it's installed under the name
> > "python".
> Thanks for the comment, and it's true that python2 will still exist
> for many years.
> And I had changed the test case to adapt python/python3/python2 automatically.
> Please help review the new patch. Thanks.

Thanks.

kobarity, any comments, or should I install this?





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#70722: [PATCH] ; Migrate to python3 for (package-test-update-archives-async)
  2024-05-09  8:33     ` Eli Zaretskii
@ 2024-05-09 16:00       ` kobarity
  2024-05-09 16:19         ` Lin Sun
  2024-05-11 10:07         ` Eli Zaretskii
  0 siblings, 2 replies; 7+ messages in thread
From: kobarity @ 2024-05-09 16:00 UTC (permalink / raw)
  To: Eli Zaretskii, Lin Sun; +Cc: 70722

[-- Attachment #1: Type: text/plain, Size: 1657 bytes --]


Eli Zaretskii wrote:
> 
> > From: Lin Sun <sunlin7.mail@gmail.com>
> > Date: Mon, 6 May 2024 00:28:07 +0000
> > Cc: 70722@debbugs.gnu.org
> > 
> > On Thu, May 2, 2024 at 6:55 PM Eli Zaretskii <eliz@gnu.org> wrote:
> > >
> > > > From: Lin Sun <sunlin7.mail@gmail.com>
> > > > Date: Thu, 2 May 2024 18:11:04 +0000
> > > >
> > > > The test case "package-test-update-archives-async" still tries to
> > > > search "python2" for testing, while python2 was at the end of its life
> > > > years ago.
> > > > So move the test case from python2 to python3.
> > >
> > > I'd prefer to make the test support both Python 2.x and Python 3.x.
> > > The fact that python.org end-of-life'd Python 2 doesn't mean we have
> > > to jump to attention and follow suit.  Old systems might still have
> > > Python 2 installed, and there's no need to drop them.
> > >
> > > I do agree that we should try looking for Python 3 first, and only
> > > afterwards for Python 2.
> > >
> > > Also, I think the test should start by looking for just "python",
> > > before the versioned variants.
> > >
> > > E.g., on my system (executable-find "python3") returns nil, although I
> > > have Python 3.x installed -- but it's installed under the name
> > > "python".
> > Thanks for the comment, and it's true that python2 will still exist
> > for many years.
> > And I had changed the test case to adapt python/python3/python2 automatically.
> > Please help review the new patch. Thanks.
> 
> Thanks.
> 
> kobarity, any comments, or should I install this?

I agree with the policy to support both Python 2/3.
How about a patch like the one attached?

[-- Attachment #2: 0001-Support-Python-3-in-package-test-update-archives-asy.patch --]
[-- Type: application/octet-stream, Size: 3225 bytes --]

From 7d5fff9814517da14a45a45bd14e8152ae4bf6fc Mon Sep 17 00:00:00 2001
From: kobarity <kobarity@gmail.com>
Date: Fri, 10 May 2024 00:39:10 +0900
Subject: [PATCH] Support Python 3 in package-test-update-archives-async

* 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>
---
 .../package-resources/package-test-server.py  | 24 ++++++++-----------
 test/lisp/emacs-lisp/package-tests.el         |  9 +++----
 2 files changed, 15 insertions(+), 18 deletions(-)

diff --git a/test/lisp/emacs-lisp/package-resources/package-test-server.py b/test/lisp/emacs-lisp/package-resources/package-test-server.py
index 128b4249ec3..16f3e391aa1 100644
--- a/test/lisp/emacs-lisp/package-resources/package-test-server.py
+++ b/test/lisp/emacs-lisp/package-resources/package-test-server.py
@@ -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.
diff --git a/test/lisp/emacs-lisp/package-tests.el b/test/lisp/emacs-lisp/package-tests.el
index d95b94f2145..692d6550250 100644
--- a/test/lisp/emacs-lisp/package-tests.el
+++ b/test/lisp/emacs-lisp/package-tests.el
@@ -634,14 +634,15 @@ package-test-update-archives
 (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"
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* bug#70722: [PATCH] ; Migrate to python3 for (package-test-update-archives-async)
  2024-05-09 16:00       ` kobarity
@ 2024-05-09 16:19         ` Lin Sun
  2024-05-11 10:07         ` Eli Zaretskii
  1 sibling, 0 replies; 7+ messages in thread
From: Lin Sun @ 2024-05-09 16:19 UTC (permalink / raw)
  To: kobarity; +Cc: Eli Zaretskii, 70722

On Thu, May 9, 2024 at 4:00 PM kobarity <kobarity@gmail.com> wrote:
>
>
> Eli Zaretskii wrote:
> >
> > > From: Lin Sun <sunlin7.mail@gmail.com>
> > > Date: Mon, 6 May 2024 00:28:07 +0000
> > > Cc: 70722@debbugs.gnu.org
> > >
> > > On Thu, May 2, 2024 at 6:55 PM Eli Zaretskii <eliz@gnu.org> wrote:
> > > >
> > > > > From: Lin Sun <sunlin7.mail@gmail.com>
> > > > > Date: Thu, 2 May 2024 18:11:04 +0000
> > > > >
> > > > > The test case "package-test-update-archives-async" still tries to
> > > > > search "python2" for testing, while python2 was at the end of its life
> > > > > years ago.
> > > > > So move the test case from python2 to python3.
> > > >
> > > > I'd prefer to make the test support both Python 2.x and Python 3.x.
> > > > The fact that python.org end-of-life'd Python 2 doesn't mean we have
> > > > to jump to attention and follow suit.  Old systems might still have
> > > > Python 2 installed, and there's no need to drop them.
> > > >
> > > > I do agree that we should try looking for Python 3 first, and only
> > > > afterwards for Python 2.
> > > >
> > > > Also, I think the test should start by looking for just "python",
> > > > before the versioned variants.
> > > >
> > > > E.g., on my system (executable-find "python3") returns nil, although I
> > > > have Python 3.x installed -- but it's installed under the name
> > > > "python".
> > > Thanks for the comment, and it's true that python2 will still exist
> > > for many years.
> > > And I had changed the test case to adapt python/python3/python2 automatically.
> > > Please help review the new patch. Thanks.
> >
> > Thanks.
> >
> > kobarity, any comments, or should I install this?
>
> I agree with the policy to support both Python 2/3.
> How about a patch like the one attached?

Hi Kobarity,  your patch is a better one!  :thumbsup:





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#70722: [PATCH] ; Migrate to python3 for (package-test-update-archives-async)
  2024-05-09 16:00       ` kobarity
  2024-05-09 16:19         ` Lin Sun
@ 2024-05-11 10:07         ` Eli Zaretskii
  1 sibling, 0 replies; 7+ messages in thread
From: Eli Zaretskii @ 2024-05-11 10:07 UTC (permalink / raw)
  To: kobarity; +Cc: sunlin7.mail, 70722-done

> Date: Fri, 10 May 2024 01:00:13 +0900
> From: kobarity <kobarity@gmail.com>
> Cc: 70722@debbugs.gnu.org
> 
> > kobarity, any comments, or should I install this?
> 
> I agree with the policy to support both Python 2/3.
> How about a patch like the one attached?

Thanks, installed on the master branch, and closing the bug.





^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-05-11 10:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-02 18:11 bug#70722: [PATCH] ; Migrate to python3 for (package-test-update-archives-async) Lin Sun
2024-05-02 18:54 ` Eli Zaretskii
2024-05-06  0:28   ` Lin Sun
2024-05-09  8:33     ` Eli Zaretskii
2024-05-09 16:00       ` kobarity
2024-05-09 16:19         ` Lin Sun
2024-05-11 10:07         ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).