Changeset 787

Show
Ignore:
Timestamp:
08/04/07 14:30:36 (1 year ago)
Author:
robin
Message:

add warnings for non existant discovery path argv arguments

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • pyrun/trunk/ChangeLog

    r783 r787  
    11ChangeLog 
    22~~~~~~~~~ 
     3 
     40.1.1 
     5  * By default, print a warning if any of the argv discovery path items dont 
     6    exist on the file system. -q suppreses the warnings 
    37 
    480.1d 
  • pyrun/trunk/pyrun.py

    r783 r787  
    55import os, sys, types, re, traceback, inspect, imp, compiler 
    66 
    7 from os.path import join, dirname, basename, isfile, isdir 
     7from os.path import join, dirname, basename, isfile, isdir, exists 
    88 
    99have_runpy=False 
     
    244244 
    245245    Note that by default, egg directories and egg archive files are found as 
    246     top level package paths but the find process will not decends below the level 
    247     of an egg directory. This behaviour can be modified by judicious use of 
    248     `evaluate_packagelocation` and `allow_descent`. 
     246    top level package paths but the find process will not decends below the 
     247    level of an egg directory. This behaviour can be modified by judicious use 
     248    of `evaluate_packagelocation` and `allow_descent`. 
    249249 
    250250    """ 
     
    313313    discover package paths OR legitemate python module files. 
    314314 
    315     The results are returned as a 3 element tuple. The first element is the 
    316     discovered path and the second is a list containing the result of 
    317     `path_moduleinfo` for any explict references to python module files and 
    318     the last is the index of the first non option argument with your supplied 
    319     offset added to it.: 
    320  
    321         ``(pathextension, moduleinfos, inonoption)`` 
     315    The results are returned as a 4 element tuple: The first element is the 
     316    discovered path; The second is a list containing the result of 
     317    `path_pkg_moduleinfo` for any explicit references to python module files; 
     318    The third is the index of the first non option argument with your 
     319    supplied offset added to it; and the last is a list of each item in args 
     320    which does not exist on the file system: 
     321 
     322        ``(pathextension, moduleinfos, inonoption, doesnotexist)`` 
    322323 
    323324    See the implementation of `discover_and_run` for a typical usage example. 
     
    340341    """ 
    341342 
     343    doesnotexist = [] 
    342344    minfos = [] 
    343345    pthextend = [] 
    344     searchpaths = [] 
     346    findpaths = [] 
    345347    pthset = set([]) 
    346348 
     
    349351    for ia, a in enumerate_argv_args(args, offset): 
    350352 
    351         #minfo = path_moduleinfo(a) 
     353        if not exists(a): 
     354            doesnotexist.append(a) 
     355 
    352356        minfo = path_pkg_moduleinfo(a) 
    353357        if minfo: 
     
    355359            a = minfo[0] 
    356360 
    357             # Currently ~/xxx/foo.py will put ~/xxx in the path irespective 
     361            # Currently ~/xxx/foo.py will put ~/xxx in the path irrespective 
    358362            # of whether there is a ~/xxx/__init__.py. I am very tempted 
    359363            # to reject directories which are not discovered from genuine 
     
    363367            # , with the current implementation, python files collected 
    364368            # together in a 'scripts' directory will be able to do sibling 
    365             # imports ( and hence shadow things for each other) becuase their 
     369            # imports ( and hence shadow things for each other) because their 
    366370            # common parent directory gets put on the path here. 
    367371            if a not in pthset: 
     
    369373                pthset.add(a) 
    370374        else: 
    371             searchpaths.append(a) 
     375            findpaths.append(a) 
    372376 
    373377    newpaths = find_package_paths(pth=pthset, 
    374         *searchpaths 
     378        *findpaths 
    375379        ) 
    376380    pthextend.extend(newpaths) 
    377381 
    378     return pthextend, minfos, ia + 1 
     382    return pthextend, minfos, ia + 1, doesnotexist 
    379383 
    380384 
     
    415419    argv = argv or sys.argv[:] 
    416420 
    417     pthextend, minfos, ia = discover_path(1, *argv) 
     421    pthextend, minfos, ia, doesnotexist = discover_path(1, *argv) 
    418422 
    419423    # We are running the module, eat the artificial `--` delimiter 
     
    443447    init_globals=None, mod_fname=None, mod_loader=None, alter_sys=True): 
    444448    """compile `filename` and run the code using runpy._run_module_code.""" 
     449 
    445450    global runpy 
    446451    if not have_runpy: 
     
    477482 
    478483    try: 
    479         pthextend, minfos, ia = discover_path(1, *argv) 
     484        pthextend, minfos, ia, doesnotexist = discover_path( 
     485                1, *argv) 
     486 
     487        if not opts.q and doesnotexist: 
     488            print (''' 
     489Warning: your discovery path arguments referenced the following files or 
     490directories which do not exist on the file system:''') 
     491            print '\t' + '\n\t'.join(doesnotexist) 
     492 
    480493 
    481494        # If there are no unconsumed arguments: We have already determined 
     
    522535                    # takes a single argument. 
    523536                    if len(argv) < ia+1: 
    524                         print ('The `-%s` pyrun option requires a module name
     537                        print ('The `-%s` pyrun option requires an argument
    525538                                ) % nextopt 
    526539                        return -1 
     
    660673 
    661674OPTIONS_runex=[ 
     675('-q', dict(default=False, action='store_true', metavar='QUIET', help= 
     676"""Suppress all warnings about missing paths etc. Useful when you are 
     677using speculative paths and are using -p or -P to print the discoverd 
     678path.""")), 
    662679 
    663680('-p', dict(default=False, action='store_true', metavar='PRINTPATH', help=