Re: [Distutils] Using `pkg_resources` without importing the module

2011-07-12 Thread cool-RR
On Mon, Jul 11, 2011 at 4:36 AM, P.J. Eby p...@telecommunity.com wrote:

 At 12:38 AM 7/11/2011 +0200, cool-RR wrote:

  On Mon, Jul 11, 2011 at 12:33 AM, P.J. Eby mailto:p...@telecommunity.com
 **p...@telecommunity.com wrote:
 At 09:25 PM 7/10/2011 +0200, cool-RR wrote:
 Hello,

 I want to use `pkg_resources` to retrieve an image file from a Python
 package. But I want to do this without importing the actual package. Is this
 possible using `pkg_resources`, or does it import the package?


 It imports the package, as it needs to know what loader object was used,
 to know whether it will be reading from a zipfile or whatever else.


 Hm. Are you familiar with any other method that can be used to get
 resources without importing?

 If you don't, then my next direction is to combine `pkg_resources` with my
 module-tasting technique; using an `__import__` hook to do a very
 minimialistic import of a module/package, without importing any other
 modules that it tries to import. Do you think that this minimalistic import
 will give `pkg_resources` enough data (about the loader or otherwise) to get
 the resources?


 Dunno.  It looks for a __loader__ attribute, so that's got to be there.
  (Unless it's a normal filesystem package or module; that's the case where
 __loader__ is not normally set.)


Yes, I got it to work! So now I can use `pkg_resources` on a package without
having to fully import you.

After my code is finalized I'll describe the solution and show the code.


Ram.
___
Distutils-SIG maillist  -  Distutils-SIG@python.org
http://mail.python.org/mailman/listinfo/distutils-sig


[Distutils] Using `pkg_resources` without importing the module

2011-07-10 Thread cool-RR
Hello,

I want to use `pkg_resources` to retrieve an image file from a Python
package. But I want to do this without importing the actual package. Is this
possible using `pkg_resources`, or does it import the package?


Thanks,
Ram.
___
Distutils-SIG maillist  -  Distutils-SIG@python.org
http://mail.python.org/mailman/listinfo/distutils-sig


Re: [Distutils] Using `pkg_resources` without importing the module

2011-07-10 Thread P.J. Eby

At 09:25 PM 7/10/2011 +0200, cool-RR wrote:

Hello,

I want to use `pkg_resources` to retrieve an image file from a 
Python package. But I want to do this without importing the actual 
package. Is this possible using `pkg_resources`, or does it import the package?


It imports the package, as it needs to know what loader object was 
used, to know whether it will be reading from a zipfile or whatever else.


___
Distutils-SIG maillist  -  Distutils-SIG@python.org
http://mail.python.org/mailman/listinfo/distutils-sig


Re: [Distutils] Using `pkg_resources` without importing the module

2011-07-10 Thread cool-RR
On Mon, Jul 11, 2011 at 12:33 AM, P.J. Eby p...@telecommunity.com wrote:

 At 09:25 PM 7/10/2011 +0200, cool-RR wrote:

 Hello,

 I want to use `pkg_resources` to retrieve an image file from a Python
 package. But I want to do this without importing the actual package. Is this
 possible using `pkg_resources`, or does it import the package?


 It imports the package, as it needs to know what loader object was used, to
 know whether it will be reading from a zipfile or whatever else.


Hm. Are you familiar with any other method that can be used to get resources
without importing?

If you don't, then my next direction is to combine `pkg_resources` with my
module-tasting technique; using an `__import__` hook to do a very
minimialistic import of a module/package, without importing any other
modules that it tries to import. Do you think that this minimalistic import
will give `pkg_resources` enough data (about the loader or otherwise) to get
the resources?


Ram.
___
Distutils-SIG maillist  -  Distutils-SIG@python.org
http://mail.python.org/mailman/listinfo/distutils-sig


Re: [Distutils] Using `pkg_resources` without importing the module

2011-07-10 Thread P.J. Eby

At 12:38 AM 7/11/2011 +0200, cool-RR wrote:
On Mon, Jul 11, 2011 at 12:33 AM, P.J. Eby 
mailto:p...@telecommunity.comp...@telecommunity.com wrote:

At 09:25 PM 7/10/2011 +0200, cool-RR wrote:
Hello,

I want to use `pkg_resources` to retrieve an image file from a 
Python package. But I want to do this without importing the actual 
package. Is this possible using `pkg_resources`, or does it import the package?



It imports the package, as it needs to know what loader object was 
used, to know whether it will be reading from a zipfile or whatever else.



Hm. Are you familiar with any other method that can be used to get 
resources without importing?


If you don't, then my next direction is to combine `pkg_resources` 
with my module-tasting technique; using an `__import__` hook to do 
a very minimialistic import of a module/package, without importing 
any other modules that it tries to import. Do you think that this 
minimalistic import will give `pkg_resources` enough data (about the 
loader or otherwise) to get the resources?


Dunno.  It looks for a __loader__ attribute, so that's got to be 
there.  (Unless it's a normal filesystem package or module; that's 
the case where __loader__ is not normally set.)


___
Distutils-SIG maillist  -  Distutils-SIG@python.org
http://mail.python.org/mailman/listinfo/distutils-sig