[Distutils] setuptools in 2.5?

Phillip J. Eby pje at telecommunity.com
Sun Jan 15 18:34:35 CET 2006

At 10:30 AM 1/15/2006 -0500, Jim Fulton wrote:
>Has a decision been made whether to include setuptools in 2.5?

It hasn't been proposed, and I don't think it's likely.  setuptools is 
still alpha (although I think it's starting to reach beta quality) and 
there are a lot of features left to implement before 1.0.

I do think it's quite possible that quite a lot of setuptools could 
reasonably be backported to the distutils, including some of its command 
conveniences (aliases, configuration-saving, distribution rotation, etc.), 
utility functions (e.g. find_packages), and so on.  The parts that are both 
stable and not specific to eggs, in other words, as these are less likely 
to be controversial.  :)

>If it is going to be included, then I'll update doctest to
>use pkg_resources to find doctest text files.  If it isn't going to
>be included then I'll have a quandry. :)  I guess that in that case,
>I'd have to use some conditional logic.

I'd suggest something like this, which will give you a compatible API and 
will work with any zipped packages, not just eggs:

      import sys, os

      def _get_path_and_loader(package_name, resource_name):
              module = sys.modules[moduleName]
          except KeyError:
              module = sys.modules[moduleName]
          loader = getattr(module, '__loader__', None)
          parts = resource_name.split('/')
          path = os.path.join(os.path.dirname(module.__file__),*parts)
          return path, loader

      def resource_string(package_name, resource_name):
          path,loader = _get_path_and_loader(package_name, resource_name)
          if loader is None:
              f = open(path,'rb')
                  return f.read()
              return loader.get_data(path)

          from pkg_resources import resource_string
      except ImportError:

(Note that if 'resource_name' includes a subdirectory path under the 
associated package, it should use '/' as a separator, not the local os.sep 
character, as pkg_resources uses distutils-style paths for "resources".)

More information about the Distutils-SIG mailing list