1 #!/usr/bin/env python 2 3 """ 4 Command option processing and other utilities for compiling and testing 5 programs. 6 7 Copyright (C) 2009, 2013 Paul Boddie <paul@boddie.org.uk> 8 9 This program is free software; you can redistribute it and/or modify it under 10 the terms of the GNU General Public License as published by the Free Software 11 Foundation; either version 3 of the License, or (at your option) any later 12 version. 13 14 This program is distributed in the hope that it will be useful, but WITHOUT 15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 16 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 17 details. 18 19 You should have received a copy of the GNU General Public License along with 20 this program. If not, see <http://www.gnu.org/licenses/>. 21 """ 22 23 from os.path import exists, join 24 import micropython 25 26 def program(path, verbose=0): 27 28 """ 29 Return a program object for the given module search 'path'. 30 """ 31 32 i = micropython.Importer(path, verbose) 33 p = micropython.Program(i) 34 35 for d in path: 36 builtins = join(d, "builtins.py") 37 if exists(builtins): 38 i.load_from_file(builtins, "__builtins__") 39 break 40 return p 41 42 # Convenience functions. 43 44 def get_program(path, args): 45 46 """ 47 Return the program object for the given module search 'path' and command 48 'args'. 49 """ 50 51 return program(path, "-v" in args) 52 53 # vim: tabstop=4 expandtab shiftwidth=4