()
| 156 | |
| 157 | |
| 158 | def main(): |
| 159 | global DEBUG_ADAPT_STEP |
| 160 | |
| 161 | parser = argparse.ArgumentParser() |
| 162 | parser.add_argument( |
| 163 | class="st">"-d", class="st">"--debug", type=int, help=class="st">"breakpoint at this adaptation step" |
| 164 | ) |
| 165 | parser.add_argument( |
| 166 | class="st">"-m", |
| 167 | class="st">"--module", |
| 168 | type=str, |
| 169 | help=class="st">"import module name instead of running a script", |
| 170 | ) |
| 171 | parser.add_argument( |
| 172 | class="st">"args", metavar=class="st">"N", type=str, nargs=class="st">"*", help=class="st">"additional arguments" |
| 173 | ) |
| 174 | |
| 175 | argparse_args = [] |
| 176 | sys_argv = list(sys.argv) |
| 177 | |
| 178 | progname = sys_argv.pop(0) |
| 179 | |
| 180 | class="cm"># this is a little crazy, works at the moment for: |
| 181 | class="cm"># module w args: |
| 182 | class="cm"># python tools/trace_orm_adapter.py -m pytest test/orm/test_query.py -s |
| 183 | class="cm"># script: |
| 184 | class="cm"># python tools/trace_orm_adapter.py test3.py |
| 185 | has_module = False |
| 186 | while sys_argv: |
| 187 | arg = sys_argv.pop(0) |
| 188 | if arg in (class="st">"-m", class="st">"--module", class="st">"-d", class="st">"--debug"): |
| 189 | argparse_args.append(arg) |
| 190 | argparse_args.append(sys_argv.pop(0)) |
| 191 | has_module = arg in (class="st">"-m", class="st">"--module") |
| 192 | else: |
| 193 | if not has_module: |
| 194 | argparse_args.append(arg) |
| 195 | else: |
| 196 | sys_argv.insert(0, arg) |
| 197 | break |
| 198 | |
| 199 | options = parser.parse_args(argparse_args) |
| 200 | sys.argv = [class="st">"program.py"] + sys_argv |
| 201 | |
| 202 | if options.module == class="st">"pytest": |
| 203 | sys.argv.extend([class="st">"--capture", class="st">"sys"]) |
| 204 | |
| 205 | import runpy |
| 206 | |
| 207 | if options.debug: |
| 208 | DEBUG_ADAPT_STEP = options.debug |
| 209 | |
| 210 | if options.module: |
| 211 | runpy.run_module(options.module, run_name=class="st">"__main__") |
| 212 | else: |
| 213 | progname = options.args[0] |
| 214 | |
| 215 | runpy.run_path(progname) |
no test coverage detected