[Distutils] Installing (data-)files in package directories

M.-A. Lemburg mal at lemburg.com
Wed Nov 19 15:37:13 EST 2003

Thomas Heller wrote:
> It seems installing data-files in package directories is a common
> requirement - at least for me.
> Readme files, data files needed by the packages - the bdist_wininst.exe
> file is such an example.  It needs to be in the same directory as the
> distutils.command.bdist_wininst module.
> So here is a build_py subclass (contained in a setup script) which does
> this. Any comments?

Does this only copy the files into the build directory or
also install them ?

It's a bit too unflexible for my taste (I wouldn't want *all*
files to get copied into the package tree). Here's what
I use for install_data to achieve more or less the same
with more control:

class mx_install_data(install_data):

     """ Rework the install_data command to something more useful.
     def finalize_options(self):

         if self.install_dir is None:
             installobj = self.distribution.get_command_obj('install')
             self.install_dir = installobj.install_data
         if _debug: print 'Installing data files to %s' % self.install_dir

     def run (self):

         if not self.dry_run:
         data_files = self.get_inputs()
         for entry in data_files:
             if type(entry) == types.StringType:
                 if 1 or os.name != 'posix':
                     # Unix- to platform-convention conversion
                     entry = string.join(string.split(entry, '/'), os.sep)
                 filenames = glob.glob(entry)
                 for filename in filenames:
                     dst = os.path.join(self.install_dir, filename)
                     dstdir = os.path.split(dst)[0]
                     if not self.dry_run:
                         outfile = self.copy_file(filename, dst)[0]
                         outfile = dst
                 raise ValueError, 'tuples in data_files not supported'

Marc-Andre Lemburg

Professional Python Software directly from the Source  (#1, Nov 19 2003)
 >>> Python/Zope Products & Consulting ...         http://www.egenix.com/
 >>> mxODBC.Zope Database Adapter ...             http://zope.egenix.com/
 >>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/

::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::

More information about the Distutils-SIG mailing list