[prev in list] [next in list] [prev in thread] [next in thread] 

List:       opensolaris-tools-discuss
Subject:    Re: [tools-discuss] Re: [Bug 155] New: scripts need a better way of
From:       David Marker <David.Marker () Sun ! COM>
Date:       2007-02-14 20:30:00
Message-ID: 45D37148.7050003 () Sun ! COM
[Download RAW message or body]

What I did for the filemerge utility was to use a relative path like this:

    import sys
    import os

    sys.path.insert(1, '%s/../lib/python' % (os.path.dirname(sys.argv[0])))

This way if you use a tool in /opt/onbld/bin, it will look in 
/opt/onbld/bin/../lib/python for packages.
If you use a tool in /ws/onnv-tools/onbld/bin it will look in 
/ws/onnv-tools/onbld/bin/../lib/python for packages.

I inserted it after the default '.' search order, but it could be 
appended to the end too.
This works if you invoke the utility and it is found in your path, if 
you use a relative path to the utility, or an absolute path (so pretty 
much everything).
It means you get the python modules that are nearest the utility. Those 
should be what you want.
There is nothing nevada specific to this solution either.

Since pkgadd has mtimes of my *.pyc files <= mtimes of my *.py files I 
can even see exactly how it found the module as python complains.

-dvd

Stephen Lau wrote:
> bugzilla-daemon@np.grommit.com wrote:
>> http://bugs.grommit.com/show_bug.cgi?id=155
>>
>>            Summary: scripts need a better way of adjusting sys.path
>>            Product: SCM Migration
>>            Version: unspecified
>>           Platform: All
>>         OS/Version: Solaris 11/Nevada
>>             Status: NEW
>>           Severity: minor
>>           Priority: P4
>>          Component: onnv-scm
>>         AssignedTo: stevel@sun.com
>>         ReportedBy: richlowe@richlowe.net
>>
>>
>> Currently, everything that needs to adjust the python loadpath does 
>> it in a
>> form such as:
>>
>>  if os.getenv('ONBLD_TOOLS'):
>>          modpath = os.path.join(os.getenv('ONBLD_TOOLS'), 'lib/python')
>>          sys.path.append(modpath)
>>  elif os.path.isdir('/ws/onnv-tools/onbld'):
>>          sys.path.append('/ws/onnv-tools/onbld/lib/python')
>>  else:
>>          sys.path.append('/opt/onbld/lib/python')
>>
>> (we prefer ONBLD_TOOLS, which if in a workspace will be set 
>> appropriately, fall
>> back to onnv-tools, fall back further to onbld).
>>
>> I obviously don't have access to onnv-tools, and don't know if that v.
>> /opt/onbld are actually the preferred ordering of things, or if it 
>> should be
>> reversed.
>>
>> Also, obviously, I'd prefer to avoid enshrining the name 'onnv', and 
>> forcing a
>> change for each new Marketing Release.  (though there are other 
>> places where
>> these would exist, I suspect they're few).
>>
>>
>
> I'm thinking it makes more sense to prefer /opt/onbld/lib/python vs. 
> /ws/onnv-tools/onbld if it exists (prefer the local installed copy to 
> the NFS mounted copy).
>
> But I don't know what the convention is - but the above makes sense to 
> me from a build-machine point of view.
>
> -steve
>
_______________________________________________
tools-discuss mailing list
tools-discuss@opensolaris.org
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic