Changeset 788
- Timestamp:
- 08/04/07 15:10:40 (1 year ago)
- Files:
-
- pyrun/trunk/ChangeLog (modified) (1 diff)
- pyrun/trunk/pkg-info.rst (modified) (1 diff)
- pyrun/trunk/pyrun.py (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
pyrun/trunk/ChangeLog
r787 r788 3 3 4 4 0.1.1 5 * Added -c, its much like python -c 6 * The `run script` option changed from -S to -C 5 7 * By default, print a warning if any of the argv discovery path items dont 6 8 exist on the file system. -q suppreses the warnings pyrun/trunk/pkg-info.rst
r785 r788 1 1 :License: MIT 2 2 :Name: pyrun 3 :Version: 0.1 3 :Version: 0.1.1dev 4 4 :Author: Robin Bryce 5 5 :Author-email: robinbryce@gmail.com pyrun/trunk/pyrun.py
r787 r788 444 444 445 445 446 def compile_and_run( filename, mod_name='__main__',446 def compile_and_run(source, mod_name='__main__', 447 447 init_globals=None, mod_fname=None, mod_loader=None, alter_sys=True): 448 448 """compile `filename` and run the code using runpy._run_module_code.""" … … 454 454 if mod_fname is None: 455 455 mod_fname = filename 456 code = compiler.compile( file(filename).read(), filename, 'exec')456 code = compiler.compile(source, mod_fname or '<unknown-source>', 'exec') 457 457 return runpy._run_module_code(code, 458 458 mod_name=mod_name, … … 482 482 483 483 try: 484 source = False 485 sourcefile = None 486 if opts.c and opts.C and not opts.q: 487 print ( 488 'Warning: -c and -C can not be used together. Ignoring "-C %s"' 489 ) % opts.C 490 491 if opts.C: 492 source = file(opts.C).read() 493 sourcefile = opts.C 494 if opts.c: 495 sourcefile = "<command-line>" 496 source = opts.c 497 498 484 499 pthextend, minfos, ia, doesnotexist = discover_path( 485 500 1, *argv) … … 544 559 # else: its definitely *not* a pyrun option 545 560 546 modname = not opts.S and (opts.m or (minfos and minfos[0][1]) or '') 561 if opts.c and opts.C and not opts.q: 562 print ( 563 'Warning: -c and -C can not be used together. Ignoring "-C %s"' 564 ) % opts.C 565 566 if opts.C: 567 source = file(opts.C).read() 568 sourcefile = opts.C 569 if opts.c: 570 sourcefile = "<command-line>" 571 source = opts.c 572 573 modname = not source and (opts.m or (minfos and minfos[0][1]) or '') 547 574 548 575 # Allways update the sys path. pthextend is the record of what we have … … 555 582 556 583 target_argv = [] 557 if modname or opts.S:558 target_argv.append(modname or opts.S)584 if modname or source: 585 target_argv.append(modname or source) 559 586 target_argv.extend(argv[ia:]) 560 587 561 def run _module():588 def run(): 562 589 if opts.n: 563 590 print 'execution of module disabled by user options' … … 568 595 sys.argv[:] = target_argv[:] 569 596 if runpy is not False: 570 if not opts.S:597 if not source: 571 598 return runpy.run_module( 572 599 modname, run_name='__main__', alter_sys=True 573 600 ) 574 601 else: 575 return compile_and_run( opts.S)602 return compile_and_run(source, mod_fname=sourcefile) 576 603 577 604 if opts.d: … … 592 619 banner += """\ 593 620 handy locals() are: 594 The function run _module (runs the discovered module if there was one)621 The function run() (runs the discovered module or -c/-C/-S options) 595 622 The variables target_argv, pthextend 596 623 597 Update target_argv *in place* before calling run _moduleif you want to tweak624 Update target_argv *in place* before calling run() if you want to tweak 598 625 the sys.argv the module sees.""" 599 626 … … 612 639 print os.pathsep.join(pthextend) 613 640 614 if not (opts.n or opts.d or opts.i) and (modname or opts.S):615 exitval = run _module()641 if not (opts.n or opts.d or opts.i) and (modname or source): 642 exitval = run() 616 643 if not isinstance(exitval, int): 617 644 return 0 … … 689 716 the discovery path.""")), 690 717 691 ('- S', dict(default=None, type='string', metavar='SCRIPT', help=718 ('-C', dict(default=None, type='string', metavar='SCRIPT', help= 692 719 """Identify a *python* SCRIPT to execute. The script need not have file 693 720 extension but it must contain leagal python code. This option trumps -m. This … … 713 740 714 741 ('-c', dict(default=False, metavar='STATEMENT', help= 715 """Update sys.argv and sys.path then execute statement in a new 716 python module. [NYI]""")), 717 718 ('-C', dict(default=False, metavar='STATEMENT', help= 719 """Update sys.argv and sys.path then execute statement in the context of the 720 selected module. [NYI]""")) 742 """Update sys.argv and sys.path then execute the statement in a new, clean, 743 module context.""")) 721 744 722 745 ]