Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 41d1f16

Browse filesBrowse files
Hellzedtargos
authored andcommitted
tools: fix Python 3 deprecation warning in test.py
PR-URL: #30208 Reviewed-By: Christian Clauss <cclauss@me.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: David Carlier <devnexen@gmail.com>
1 parent 33bd128 commit 41d1f16
Copy full SHA for 41d1f16

File tree

Expand file treeCollapse file tree

1 file changed

+28
-13
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+28
-13
lines changed
Open diff view settings
Collapse file

‎tools/test.py‎

Copy file name to clipboardExpand all lines: tools/test.py
+28-13Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030

3131
from __future__ import print_function
32-
import imp
3332
import logging
3433
import optparse
3534
import os
@@ -45,6 +44,27 @@
4544
import errno
4645
import copy
4746

47+
48+
if sys.version_info >= (3, 5):
49+
from importlib import machinery, util
50+
def get_module(name, path):
51+
loader_details = (machinery.SourceFileLoader, machinery.SOURCE_SUFFIXES)
52+
spec = machinery.FileFinder(path, loader_details).find_spec(name)
53+
module = util.module_from_spec(spec)
54+
spec.loader.exec_module(module)
55+
return module
56+
else:
57+
import imp
58+
def get_module(name, path):
59+
file = None
60+
try:
61+
(file, pathname, description) = imp.find_module(name, [path])
62+
return imp.load_module(name, file, pathname, description)
63+
finally:
64+
if file:
65+
file.close()
66+
67+
4868
from io import open
4969
from os.path import join, dirname, abspath, basename, isdir, exists
5070
from datetime import datetime
@@ -786,18 +806,13 @@ def GetConfiguration(self, context):
786806
if self.is_loaded:
787807
return self.config
788808
self.is_loaded = True
789-
file = None
790-
try:
791-
(file, pathname, description) = imp.find_module('testcfg', [ self.path ])
792-
module = imp.load_module('testcfg', file, pathname, description)
793-
self.config = module.GetConfiguration(context, self.path)
794-
if hasattr(self.config, 'additional_flags'):
795-
self.config.additional_flags += context.node_args
796-
else:
797-
self.config.additional_flags = context.node_args
798-
finally:
799-
if file:
800-
file.close()
809+
810+
module = get_module('testcfg', self.path)
811+
self.config = module.GetConfiguration(context, self.path)
812+
if hasattr(self.config, 'additional_flags'):
813+
self.config.additional_flags += context.node_args
814+
else:
815+
self.config.additional_flags = context.node_args
801816
return self.config
802817

803818
def GetBuildRequirements(self, path, context):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.