From: Ralf Jung Date: Tue, 11 Nov 2014 10:18:51 +0000 (+0100) Subject: make load_module compatible with python 3.2 X-Git-Url: https://git.ralfj.de/mass-build.git/commitdiff_plain/d4ae57d985ba8adbd010afce3ac8a9eef9bc1e40 make load_module compatible with python 3.2 --- diff --git a/mass_build.py b/mass_build.py index c5f4ddd..79bc17a 100755 --- a/mass_build.py +++ b/mass_build.py @@ -20,14 +20,20 @@ import vcs, build_system import argparse, os, sys, subprocess from collections import OrderedDict -# helper funcrions +# helper functions def load_module(name, path, write_bytecode = False): - import importlib.machinery - old_val = sys.dont_write_bytecode - sys.dont_write_bytecode = not write_bytecode - module = importlib.machinery.SourceFileLoader(name, path).load_module() - sys.dont_write_bytecode = old_val - return module + old_val = sys.dont_write_bytecode + sys.dont_write_bytecode = not write_bytecode + module = None + try: + from importlib.machinery import SourceFileLoader + module = SourceFileLoader(name, path).load_module() + except ImportError: + import imp + module = imp.load_source(name, path) + finally: + sys.dont_write_bytecode = old_val + return module # an entire Project class Project: