Confusion about scan_code in modulefinder.py (in python 2.6)

2010-01-12 Thread Brock Pytlik
I've been working with the modulefinder.py code recently and I've come 
across a bit of code I'm not grasping. In the scan_code function, there 
are the following lines:

   if sys.version_info >= (2, 5):
   scanner = self.scan_opcodes_25
   else:
   scanner = self.scan_opcodes
I don't understand their purpose. Why would I be running a version of 
python less than 2.6 and using the 2.6 module? Should this be looking at 
the version of python that was used to compile 'co'?


In my use, I'm subclassing the modulefinder class and adapting the 
scan_code function to do what I need, but I've found I need separate 
classes for (2.4, 2.5) and 2.6 because when running 2.4 or 2.5, the 
above code traces back. (In 2.4 because self.scan_opcodes isn't defined, 
in 2.5 because self.scan_opcodes_25 isn't.)


In the end, I've gotten everything working to my satisfaction, but I'm 
curious about how this module (and those lines in particular) were 
designed to be used. Any insight would be appreciated.


Thanks,
Brock
--
http://mail.python.org/mailman/listinfo/python-list


Re: System default sys.path

2009-07-02 Thread Brock Pytlik

David Lyon wrote:

On Wed, 01 Jul 2009 19:48:04 -0700, Brock Pytlik  wrote:
  
Hi, I'm trying to find a way to get the value sys.path would have on a 
particular system if python was started with an empty python path. I do 
want it to include the site specific additional paths. I know I can hack 
this information myself, 



Copy the code out from site.py...

  
Well, as far as I can tell, site does several things. It calls 
abs__file__ which, afaict, doesn't effect sys.path. Then it calls 
removeduppaths, which walks over sys.path. That means that sys.path has 
already been set by something at that point. So, how/where did sys.path 
get set then? Or is sys.path always empty there at startup and this code 
is just to handle other situations?


[snip]

Brock
--
http://mail.python.org/mailman/listinfo/python-list


System default sys.path

2009-07-01 Thread Brock Pytlik
Hi, I'm trying to find a way to get the value sys.path would have on a 
particular system if python was started with an empty python path. I do 
want it to include the site specific additional paths. I know I can hack 
this information myself, but I'd rather be able to get this on demand so 
that if things change in the future, I don't have grovel around looking 
for which directory string to change.


If nothing else, I think the following would satisfy my needs:
1) a variable containing the directories to use as a prefix (I think 
sys.exec_prefix and sys.prefix are what I want here)
2) a variable containing the list of suffixes that are applies to the 
prefixes, like lib/python/site-packages

3) a way of handing the *.pth files

Thanks in advance for the help,
Brock
--
http://mail.python.org/mailman/listinfo/python-list