Skip to content

Commit 8ad3455

Browse files
Trottdanielleadams
authored andcommitted
tools: revise install.py for minor improvements
* Use an with block for reading the config file. Refs: https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files * Use explicit blank return to make it clear that the return value is not actually used and that it is being used for flow control only.. PR-URL: #36626 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Christian Clauss <[email protected]>
1 parent 34d1d79 commit 8ad3455

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

tools/install.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ def abspath(*args):
1919
return os.path.abspath(path)
2020

2121
def load_config():
22-
s = open('config.gypi').read()
23-
return ast.literal_eval(s)
22+
with open('config.gypi') as f:
23+
return ast.literal_eval(f.read())
2424

2525
def try_unlink(path):
2626
try:
@@ -223,11 +223,19 @@ def run(args):
223223
cmd = args[1] if len(args) > 1 else 'install'
224224

225225
if os.environ.get('HEADERS_ONLY'):
226-
if cmd == 'install': return headers(install)
227-
if cmd == 'uninstall': return headers(uninstall)
226+
if cmd == 'install':
227+
headers(install)
228+
return
229+
if cmd == 'uninstall':
230+
headers(uninstall)
231+
return
228232
else:
229-
if cmd == 'install': return files(install)
230-
if cmd == 'uninstall': return files(uninstall)
233+
if cmd == 'install':
234+
files(install)
235+
return
236+
if cmd == 'uninstall':
237+
files(uninstall)
238+
return
231239

232240
raise RuntimeError('Bad command: %s\n' % cmd)
233241

0 commit comments

Comments
 (0)