From eff065ece572c155d6717d3dc4a8e37fb91aadcc Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Tue, 2 Jun 2015 16:00:48 -0400 Subject: [PATCH] Bug 1170691 - part 1 - add the generating script's directory to sys.path in file_generate.py; r=glandium The old way of writing scripts for generated files would invoke the script thusly: python script.py arg1... Invoking the script this way means that the script's directory is automatically added to sys.path, and importing modules from that directory is easy. Let's make it equally easy in the new world for GENERATED_FILES, too. --- python/mozbuild/mozbuild/action/file_generate.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/python/mozbuild/mozbuild/action/file_generate.py b/python/mozbuild/mozbuild/action/file_generate.py index 6708bf1f365..97d12a76165 100644 --- a/python/mozbuild/mozbuild/action/file_generate.py +++ b/python/mozbuild/mozbuild/action/file_generate.py @@ -30,6 +30,16 @@ def main(argv): args = parser.parse_args(argv) script = args.python_script + # Permit the script to import modules from the same directory in which it + # resides. The justification for doing this is that if we were invoking + # the script as: + # + # python script arg1... + # + # then importing modules from the script's directory would come for free. + # Since we're invoking the script in a roundabout way, we provide this + # bit of convenience. + sys.path.append(os.path.dirname(script)) with open(script, 'r') as fh: module = imp.load_module('script', fh, script, ('.py', 'r', imp.PY_SOURCE))