From dd10afc45afb58a325fa98f536a154a541184feb Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Fri, 25 Dec 2020 05:05:28 -0800 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/36626 Reviewed-By: Antoine du Hamel Reviewed-By: Christian Clauss --- tools/install.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/tools/install.py b/tools/install.py index 729b416fc47d3f..693faff4c37ac4 100755 --- a/tools/install.py +++ b/tools/install.py @@ -19,8 +19,8 @@ def abspath(*args): return os.path.abspath(path) def load_config(): - s = open('config.gypi').read() - return ast.literal_eval(s) + with open('config.gypi') as f: + return ast.literal_eval(f.read()) def try_unlink(path): try: @@ -223,11 +223,19 @@ def run(args): cmd = args[1] if len(args) > 1 else 'install' if os.environ.get('HEADERS_ONLY'): - if cmd == 'install': return headers(install) - if cmd == 'uninstall': return headers(uninstall) + if cmd == 'install': + headers(install) + return + if cmd == 'uninstall': + headers(uninstall) + return else: - if cmd == 'install': return files(install) - if cmd == 'uninstall': return files(uninstall) + if cmd == 'install': + files(install) + return + if cmd == 'uninstall': + files(uninstall) + return raise RuntimeError('Bad command: %s\n' % cmd)