Skip to content

Commit dc94007

Browse files
committed
Bug 1878964 - Remove mozbuild.exec_. r=firefox-build-system-reviewers,sergesanspaille
Its comment says: > Wrapper around the exec statement to avoid bogus errors like: > (snip) > which happen with older versions of python 2.7. IOW, it's been useless ever since we dropped support for python 2.7. Differential Revision: https://phabricator.services.mozilla.com/D200879
1 parent db1d04d commit dc94007

File tree

8 files changed

+31
-51
lines changed

8 files changed

+31
-51
lines changed

python/mozbuild/mozbuild/configure/__init__.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
from mozbuild.util import (
3131
ReadOnlyDict,
3232
ReadOnlyNamespace,
33-
exec_,
3433
memoize,
3534
memoized_property,
3635
system_encoding,
@@ -491,7 +490,7 @@ def include_file(self, path):
491490
source = fh.read()
492491

493492
code = self.get_compiled_source(source, path)
494-
exec_(code, self)
493+
exec(code, self)
495494

496495
self._paths.pop(-1)
497496

@@ -1017,21 +1016,21 @@ def _recursively_get_property(self, module, what, wrapped):
10171016
@memoized_property
10181017
def _wrapped_os(self):
10191018
wrapped_os = {}
1020-
exec_("from os import *", {}, wrapped_os)
1019+
exec("from os import *", {}, wrapped_os)
10211020
# Special case os and os.environ so that os.environ is our copy of
10221021
# the environment.
10231022
wrapped_os["environ"] = self._environ
10241023
# Also override some os.path functions with ours.
10251024
wrapped_path = {}
1026-
exec_("from os.path import *", {}, wrapped_path)
1025+
exec("from os.path import *", {}, wrapped_path)
10271026
wrapped_path.update(self.OS.path.__dict__)
10281027
wrapped_os["path"] = ReadOnlyNamespace(**wrapped_path)
10291028
return ReadOnlyNamespace(**wrapped_os)
10301029

10311030
@memoized_property
10321031
def _wrapped_subprocess(self):
10331032
wrapped_subprocess = {}
1034-
exec_("from subprocess import *", {}, wrapped_subprocess)
1033+
exec("from subprocess import *", {}, wrapped_subprocess)
10351034

10361035
def wrap(function):
10371036
def wrapper(*args, **kwargs):
@@ -1055,11 +1054,11 @@ def _wrapped_six(self):
10551054
if six.PY3:
10561055
return six
10571056
wrapped_six = {}
1058-
exec_("from six import *", {}, wrapped_six)
1057+
exec("from six import *", {}, wrapped_six)
10591058
wrapped_six_moves = {}
1060-
exec_("from six.moves import *", {}, wrapped_six_moves)
1059+
exec("from six.moves import *", {}, wrapped_six_moves)
10611060
wrapped_six_moves_builtins = {}
1062-
exec_("from six.moves.builtins import *", {}, wrapped_six_moves_builtins)
1061+
exec("from six.moves.builtins import *", {}, wrapped_six_moves_builtins)
10631062

10641063
# Special case for the open() builtin, because otherwise, using it
10651064
# fails with "IOError: file() constructor not accessible in
@@ -1104,7 +1103,7 @@ def _get_one_import(self, _from, _import, _as, glob):
11041103
_import,
11051104
(" as %s" % _as) if _as else "",
11061105
)
1107-
exec_(import_line, {}, glob)
1106+
exec(import_line, {}, glob)
11081107

11091108
def _resolve_and_set(self, data, name, value, when=None):
11101109
# Don't set anything when --help was on the command line

python/mozbuild/mozbuild/frontend/sandbox.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import six
2525
from mozpack.files import FileFinder
2626

27-
from mozbuild.util import ReadOnlyDict, exec_
27+
from mozbuild.util import ReadOnlyDict
2828

2929
from .context import Context
3030

@@ -181,7 +181,7 @@ def execute():
181181
old_source = self._current_source
182182
self._current_source = source
183183
try:
184-
exec_(code, self)
184+
exec(code, self)
185185
finally:
186186
self._current_source = old_source
187187

python/mozbuild/mozbuild/test/configure/test_checks_configure.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from common import ConfigureTestSandbox, ensure_exe_extension, fake_short_path
1616
from mozbuild.configure import ConfigureError, ConfigureSandbox
1717
from mozbuild.shellutil import quote as shell_quote
18-
from mozbuild.util import exec_
1918

2019

2120
class TestChecksConfigure(unittest.TestCase):
@@ -26,7 +25,7 @@ def test(val, msg):
2625
sandbox = ConfigureSandbox({}, stdout=out, stderr=out)
2726
base_dir = os.path.join(topsrcdir, "build", "moz.configure")
2827
sandbox.include_file(os.path.join(base_dir, "checks.configure"))
29-
exec_(to_exec, sandbox)
28+
exec(to_exec, sandbox)
3029
sandbox["foo"](val)
3130
self.assertEqual(out.getvalue(), msg)
3231

@@ -119,7 +118,7 @@ def get_result(
119118

120119
status = 0
121120
try:
122-
exec_(command, sandbox)
121+
exec(command, sandbox)
123122
sandbox.run()
124123
except SystemExit as e:
125124
status = e.code

python/mozbuild/mozbuild/test/configure/test_compile_checks.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from test_toolchain_helpers import FakeCompiler
1414

1515
from common import ConfigureTestSandbox
16-
from mozbuild.util import exec_
1716

1817

1918
class BaseCompileChecks(unittest.TestCase):
@@ -132,12 +131,12 @@ def host_cxx_compiler():
132131
sandbox = ConfigureTestSandbox(paths, config, {}, ["/bin/configure"], out, out)
133132
sandbox.include_file(os.path.join(base_dir, "util.configure"))
134133
sandbox.include_file(os.path.join(base_dir, "checks.configure"))
135-
exec_(mock_compiler_defs, sandbox)
134+
exec(mock_compiler_defs, sandbox)
136135
sandbox.include_file(os.path.join(base_dir, "compile-checks.configure"))
137136

138137
status = 0
139138
try:
140-
exec_(command, sandbox)
139+
exec(command, sandbox)
141140
sandbox.run()
142141
except SystemExit as e:
143142
status = e.code

python/mozbuild/mozbuild/test/configure/test_configure.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
NegativeOptionValue,
1919
PositiveOptionValue,
2020
)
21-
from mozbuild.util import ReadOnlyNamespace, exec_, memoized_property
21+
from mozbuild.util import ReadOnlyNamespace, memoized_property
2222

2323
test_data_path = mozpath.abspath(mozpath.dirname(__file__))
2424
test_data_path = mozpath.join(test_data_path, "data")
@@ -296,7 +296,7 @@ def test_imports(self):
296296
sandbox = ConfigureSandbox(config, {}, ["configure"], out, out)
297297

298298
with self.assertRaises(ImportError):
299-
exec_(
299+
exec(
300300
textwrap.dedent(
301301
"""
302302
@template
@@ -307,7 +307,7 @@ def foo():
307307
sandbox,
308308
)
309309

310-
exec_(
310+
exec(
311311
textwrap.dedent(
312312
"""
313313
@template
@@ -322,11 +322,11 @@ def foo():
322322

323323
# os.path after an import is a mix of vanilla os.path and sandbox os.path.
324324
os_path = {}
325-
exec_("from os.path import *", {}, os_path)
325+
exec("from os.path import *", {}, os_path)
326326
os_path.update(sandbox.OS.path.__dict__)
327327
os_path = ReadOnlyNamespace(**os_path)
328328

329-
exec_(
329+
exec(
330330
textwrap.dedent(
331331
"""
332332
@template
@@ -339,7 +339,7 @@ def foo():
339339

340340
self.assertEqual(sandbox["foo"](), os_path)
341341

342-
exec_(
342+
exec(
343343
textwrap.dedent(
344344
"""
345345
@template
@@ -352,7 +352,7 @@ def foo():
352352

353353
self.assertEqual(sandbox["foo"](), os_path)
354354

355-
exec_(
355+
exec(
356356
textwrap.dedent(
357357
"""
358358
@template
@@ -367,7 +367,7 @@ def foo():
367367
sandbox["foo"]()
368368
self.assertEqual(str(e.exception), "Importing __builtin__ is forbidden")
369369

370-
exec_(
370+
exec(
371371
textwrap.dedent(
372372
"""
373373
@template
@@ -384,7 +384,7 @@ def foo():
384384
f.close()
385385

386386
# This used to unlock the sandbox
387-
exec_(
387+
exec(
388388
textwrap.dedent(
389389
"""
390390
@template
@@ -400,7 +400,7 @@ def foo():
400400
sandbox["foo"]()
401401
self.assertEqual(str(e.exception), "Importing __builtin__ is forbidden")
402402

403-
exec_(
403+
exec(
404404
textwrap.dedent(
405405
"""
406406
@template
@@ -413,7 +413,7 @@ def foo():
413413

414414
self.assertIs(sandbox["foo"](), sandbox)
415415

416-
exec_(
416+
exec(
417417
textwrap.dedent(
418418
"""
419419
@template
@@ -430,7 +430,7 @@ def foo():
430430
self.assertEqual(list(sandbox), ["__builtins__", "foo"])
431431
self.assertEqual(sandbox["__builtins__"], ConfigureSandbox.BUILTINS)
432432

433-
exec_(
433+
exec(
434434
textwrap.dedent(
435435
"""
436436
@template
@@ -462,7 +462,7 @@ def _apply_imports(self, *args, **kwargs):
462462
out = StringIO()
463463
sandbox = CountApplyImportsSandbox(config, {}, ["configure"], out, out)
464464

465-
exec_(
465+
exec(
466466
textwrap.dedent(
467467
"""
468468
@template
@@ -490,7 +490,7 @@ def _wrapped_foo(self):
490490
out = StringIO()
491491
sandbox = BasicWrappingSandbox(config, {}, ["configure"], out, out)
492492

493-
exec_(
493+
exec(
494494
textwrap.dedent(
495495
"""
496496
@template

python/mozbuild/mozbuild/test/configure/test_moz_configure.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
from mozunit import main
66

77
from common import BaseConfigureTest, ConfigureTestSandbox
8-
from mozbuild.util import ReadOnlyNamespace, exec_, memoized_property
8+
from mozbuild.util import ReadOnlyNamespace, memoized_property
99

1010

1111
def sandbox_class(platform):
1212
class ConfigureTestSandboxOverridingPlatform(ConfigureTestSandbox):
1313
@memoized_property
1414
def _wrapped_sys(self):
1515
sys = {}
16-
exec_("from sys import *", sys)
16+
exec("from sys import *", sys)
1717
sys["platform"] = platform
1818
return ReadOnlyNamespace(**sys)
1919

python/mozbuild/mozbuild/test/configure/test_util.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
Version,
2424
getpreferredencoding,
2525
)
26-
from mozbuild.util import exec_
2726

2827

2928
class TestConfigureOutputHandler(unittest.TestCase):
@@ -457,7 +456,7 @@ def get_result(self, command="", paths=None):
457456
)
458457
status = 0
459458
try:
460-
exec_(command, sandbox)
459+
exec(command, sandbox)
461460
sandbox.run()
462461
except SystemExit as e:
463462
status = e.code

python/mozbuild/mozbuild/util.py

-16
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,6 @@
4040
system_encoding = "utf-8"
4141

4242

43-
def exec_(object, globals=None, locals=None):
44-
"""Wrapper around the exec statement to avoid bogus errors like:
45-
46-
SyntaxError: unqualified exec is not allowed in function ...
47-
it is a nested function.
48-
49-
or
50-
51-
SyntaxError: unqualified exec is not allowed in function ...
52-
it contains a nested function with free variable
53-
54-
which happen with older versions of python 2.7.
55-
"""
56-
exec(object, globals, locals)
57-
58-
5943
def _open(path, mode):
6044
if "b" in mode:
6145
return io.open(path, mode)

0 commit comments

Comments
 (0)