Fix python3 deprecation warning

Gabriel Ganne <[email protected]>
Newsgroups gmane.comp.sysutils.automake.patches
Message-ID <CAMX-4-8Mx=O17NJ+ZgG+oECHH8bUwNcdUh_701ukqu_ribynWg@mail.gmail.com>
 Hi,

When byte-compilig python code, automake uses a small python script wrapped
around the py_compile module. This code makes use of the imp module which
has been deprecated since 3.4.
I'm working on the Debian stable release which provides python3.7, and in
practice, this means that each time I install python code and it is
byte-compiled I see the following warning: "DeprecationWarning: the imp
module is deprecated in favour of importlib; see the module's documentation
for alternative uses"

The attached patch proposes to replace the imp functions with the new ones
from importlib.

Best regards,

-- 
Gabriel Ganne

-- 





**Attention: Confidential**

This email message is for the sole use of 
the intended recipient(s) and may contain confidential and/or privileged 
information.
Any unauthorized review, use, disclosure or distribution is 
prohibited.
If you are not the intended recipient, please contact me by 
reply email and destroy all copies of the original message.
0001-python3-fix-deprecation-warning.patch (application/octet-stream, 2.1 KB)
From 62fc5dfade867746a401713fb487440ac1551f1e Mon Sep 17 00:00:00 2001
From: Gabriel Ganne <[email protected]>
Date: Sat, 13 Jul 2019 08:14:06 +0200
Subject: [PATCH] python3: fix deprecation warning

Python3 "imp" module is deprecated since version 3.4 in favor of the
importlib module. On debian stable (python3.7) this raises a deprecation
warning each time you byte-compile python code.

This commit replaces the functions:
 imp.get_tag() -> sys.implementation.cache_tag()
 imp.cache_from_source() -> importlib.util.cache_from_source()
---
 lib/py-compile | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/lib/py-compile b/lib/py-compile
index 9f8baf7ab..f7edd4c4e 100755
--- a/lib/py-compile
+++ b/lib/py-compile
@@ -116,7 +116,7 @@ else
 fi
 
 $PYTHON -c "
-import sys, os, py_compile, imp
+import sys, os, py_compile, importlib
 
 files = '''$files'''
 
@@ -129,15 +129,15 @@ for file in files.split():
 	    continue
     sys.stdout.write(file)
     sys.stdout.flush()
-    if hasattr(imp, 'get_tag'):
-        py_compile.compile(filepath, imp.cache_from_source(filepath), path)
+    if hasattr(sys.implementation, 'cache_tag'):
+        py_compile.compile(filepath, importlib.util.cache_from_source(filepath), path)
     else:
         py_compile.compile(filepath, filepath + 'c', path)
 sys.stdout.write('\n')" || exit $?
 
 # this will fail for python < 1.5, but that doesn't matter ...
 $PYTHON -O -c "
-import sys, os, py_compile, imp
+import sys, os, py_compile, importlib
 
 # pypy does not use .pyo optimization
 if hasattr(sys, 'pypy_translation_info'):
@@ -153,8 +153,8 @@ for file in files.split():
 	    continue
     sys.stdout.write(file)
     sys.stdout.flush()
-    if hasattr(imp, 'get_tag'):
-        py_compile.compile(filepath, imp.cache_from_source(filepath, False), path)
+    if hasattr(sys.implementation, 'cache_tag'):
+        py_compile.compile(filepath, importlib.util.cache_from_source(filepath), path)
     else:
         py_compile.compile(filepath, filepath + 'o', path)
 sys.stdout.write('\n')" 2>/dev/null || :
-- 
2.20.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.