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