()
| 36 | module_path, module_filename = os.path.split(os.path.realpath(__file__)) |
| 37 | |
| 38 | def read_config(): |
| 39 | # pylint: disable=W0703 |
| 40 | def json_to_object(data, output_base, config_base): |
| 41 | def json_object_hook(object_dict): |
| 42 | items = [(k, os.path.join(config_base, v) if k == "path" else v) |
| 43 | for (k, v) in object_dict.items()] |
| 44 | items = [(k, os.path.join(output_base, v) if k == "output" else v) |
| 45 | for (k, v) in items] |
| 46 | keys, values = list(zip(*items)) |
| 47 | # 'async' is a keyword since Python 3.7. |
| 48 | # Avoid namedtuple(rename=True) for compatibility with Python 2.X. |
| 49 | keys = tuple('async_' if k == 'async' else k for k in keys) |
| 50 | return collections.namedtuple('X', keys)(*values) |
| 51 | return json.loads(data, object_hook=json_object_hook) |
| 52 | |
| 53 | def init_defaults(config_tuple, path, defaults): |
| 54 | keys = list(config_tuple._fields) # pylint: disable=E1101 |
| 55 | values = [getattr(config_tuple, k) for k in keys] |
| 56 | for i in range(len(keys)): |
| 57 | if hasattr(values[i], "_fields"): |
| 58 | values[i] = init_defaults(values[i], path + "." + keys[i], defaults) |
| 59 | for optional in defaults: |
| 60 | if optional.find(path + ".") != 0: |
| 61 | continue |
| 62 | optional_key = optional[len(path) + 1:] |
| 63 | if optional_key.find(".") == -1 and optional_key not in keys: |
| 64 | keys.append(optional_key) |
| 65 | values.append(defaults[optional]) |
| 66 | return collections.namedtuple('X', keys)(*values) |
| 67 | |
| 68 | try: |
| 69 | cmdline_parser = argparse.ArgumentParser() |
| 70 | cmdline_parser.add_argument("--output_base", type=unicode, required=True) |
| 71 | cmdline_parser.add_argument("--jinja_dir", type=unicode, required=True) |
| 72 | cmdline_parser.add_argument("--config", type=unicode, required=True) |
| 73 | cmdline_parser.add_argument("--config_value", default=[], action="append") |
| 74 | cmdline_parser.add_argument( |
| 75 | "--inspector_protocol_dir", type=unicode, required=True, |
| 76 | help=("directory with code_generator.py and C++ encoding / binding " |
| 77 | "libraries, relative to the root of the source tree.")) |
| 78 | cmdline_parser.add_argument("--depfile", type=unicode, required=False) |
| 79 | cmdline_parser.add_argument("--stamp", type=unicode, required=False) |
| 80 | arg_options = cmdline_parser.parse_args() |
| 81 | jinja_dir = arg_options.jinja_dir |
| 82 | output_base = arg_options.output_base |
| 83 | config_file = arg_options.config |
| 84 | config_base = os.path.dirname(config_file) |
| 85 | config_values = arg_options.config_value |
| 86 | if bool(arg_options.depfile) != bool(arg_options.stamp): |
| 87 | raise Exception("--depfile requires --stamp and vice versa") |
| 88 | depfile = arg_options.depfile |
| 89 | stamp = arg_options.stamp |
| 90 | inspector_protocol_dir = arg_options.inspector_protocol_dir.lstrip('/') |
| 91 | except Exception: |
| 92 | # Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.html |
| 93 | exc = sys.exc_info()[1] |
| 94 | sys.stderr.write("Failed to parse command-line arguments: %s\n\n" % exc) |
| 95 | exit(1) |
no test coverage detected
searching dependent graphs…