Changeset 806

Show
Ignore:
Timestamp:
05/09/08 11:30:28 (8 months ago)
Author:
robin
Message:

miscelaneous fixes, paths in .pth files relative to the directory containing the .pth file

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • pyrun/trunk/pyrun.py

    r804 r806  
    66 
    77from os.path import join, dirname, basename, isfile, isdir, exists 
    8 from os.path import splitext 
     8from os.path import splitext, abspath, normpath, expandvars, expanduser 
    99 
    1010import logging 
     
    212212 
    213213def evaluate_packagepath(path, name='', allow_egglinks=False): 
    214     if isegg_path(path, allow_links=allow_egglinks): 
    215         return name or path 
     214 
     215    if isegg_path(path, allow_links=True): 
     216        if not isegg_path(path, allow_links=False): 
     217            if not allow_egglinks: 
     218                return False 
     219            egg_pth = file(path, 'r').read().strip() 
     220            egg_pth = egg_pth.split('\n')[0].strip() 
     221            return name or normpath(abspath(join(dirname(path), egg_pth))) 
     222        else: 
     223            return name or path 
     224 
    216225    if (isdir(path) and '.' not in name and ( 
    217226        isfile(join(path, '__init__.py')) or 
     
    324333        short_opts = {} 
    325334 
    326     assert ia <= len(argv), ( 
     335    assert ia <= len(argv) + 1, ( 
    327336            'ia=%s, argv="%s"' 
    328337            ) % (ia, str(argv) 
    329338                    ) 
    330     if ia == len(argv): 
     339    if ia >= len(argv): 
    331340        return [] 
    332341 
     
    343352    # 
    344353 
    345     if argv[ia] == '--'
     354    if argv[ia] == '--' or argv[ia] == '-'
    346355        del argv[ia] 
    347356    else: 
    348  
    349357        # Short or long ? 
    350358        if argv[ia].startswith('--'): 
     
    460468                pthextend.extend(newpaths) 
    461469                findpaths[:] = [] 
    462             pthextend.extend(ln.strip() for ln in file(a) 
    463                     if exists(ln.strip()) 
    464                     ) 
     470            pthdir = normpath(abspath(dirname(a))) 
     471            for ln in file(a): 
     472                ln = ln.strip() 
     473                pth = join(abspath(expandvars(expanduser(ln)))) 
     474                if exists(pth): 
     475                    pthextend.append(pth) 
     476                else: 
     477                    doesnotexist.append(ln) 
     478 
    465479            continue 
    466480 
     
    823837                        ) 
    824838            if opts.P: 
    825                 banner += '\n\nPYTONPATH=%s' % os.pathsep.join( 
     839                banner += '\n\nPYTHONPATH=%s' % os.pathsep.join( 
    826840                        pthextend 
    827841                        ) 
     
    892906 
    893907USAGE_runex="""\ 
    894 %prog  [-nidDpP] [BASEPATH(s)][-m mod.name | '--'] [TARGET-OPTIONS] 
    895  
    896 In most cases the solo '--' is not required. It tends to be useful when you 
    897 implicitly select the module to run AND you want to pass a non option argument 
    898 as the first value in the command line for that module. It can also be 
     908%prog  [-nidDpP] [BASEPATH(s)][-m mod.name | '--' | '-' ] [TARGET-OPTIONS] 
     909 
     910Discover python packages and modules under BASEPATH(s). Run the first module 
     911file named in `BASEPATH(s)` *OR* explicitly nominated using the `-m` option. 
     912BASEPATH can reference python .pth files, in which case the paths in that file 
     913are inserted. 
     914 
     915Note that the 'import ' lines are not supported in .pth files, that the paths 
     916are interpreted as relative to the directory containing the .pth file and that 
     917environment variables and '~' are fully expanded. 
     918 
     919In most cases the solo '--' or '-' is not required. It tends to be useful when 
     920you implicitly select the module to run AND you want to pass a non option 
     921argument as the first value in the command line for that module. It can also be 
    899922necessary when the target module has short options, without long-name 
    900923alternatives, which collide with those defined for pyrun. 
    901  
    902 Discover python packages and modules under PATH. Run the first module file 
    903 named in `PATH` *OR* explicitly nominated using the `-m` option. 
    904924 
    905925NOTE: Any option that is marked [NYI] is Not Yet Implemented.""" 
  • pyrun/trunk/pyrunscripts.py

    r804 r806  
    170170            # No explicit script selection, take them all 
    171171            reqs = [env[project][0].as_requirement() for project in env] 
     172            print reqs 
    172173 
    173174