[Distutils] Installing a file into sitepackages

Ionel Cristian Mărieș contact at ionelmc.ro
Tue Mar 24 10:58:40 CET 2015


Hmmmm, good catch. It appears that when `setup.py install` is used the .pth
file is there, but it's inside the egg (wrong place).


Thanks,
-- Ionel Cristian Mărieș, http://blog.ionelmc.ro

On Tue, Mar 24, 2015 at 11:36 AM, Stuart Axon <stuaxo2 at yahoo.com> wrote:

> Hi,
>  This works from pypi - but not when installing from source with  python
> setup.py install  which stops this nifty thing from working:
>
> PYTHON_HUNTER="module='os.path'" python yourapp.py
>
>
> Sandbox monkeypatches os.file, so I think it catches you using copy.
> Maybe we need a common API for code that runs at startup?
>
> S++
>
>
>
>   On Tuesday, March 24, 2015 3:56 PM, Ionel Cristian Mărieș <
> contact at ionelmc.ro> wrote:
>
>
>
> Hey,
>
> If you just want to copy a out-of-package file into site-package you could
> just override the build command and copy it there (in the build dir).
> Here's an example:
> https://github.com/ionelmc/python-hunter/blob/master/setup.py#L27-L31 -
> it seems to work fine with wheels.
>
>
>
> Thanks,
> -- Ionel Cristian Mărieș, http://blog.ionelmc.ro
>
> On Mon, Mar 16, 2015 at 11:02 AM, Stuart Axon <stuaxo2 at yahoo.com> wrote:
>
> Hi All
>     This, and another memory-leak bug were triggered by the sandbox.
> Would it be possible to either add an API to exempt files, or just allow
> writing within site packages, even if just for .pth files ?
>
> I'm monkey patching around these for now
> https://github.com/stuaxo/vext/blob/master/setup.py#L16
>
> S++
>
>
>
>   On Thursday, March 12, 2015 2:54 PM, Stuart Axon <stuaxo2 at yahoo.com>
> wrote:
>
>
>
> For closure:  The solution was to make a Command class + implement
> finalize_options to fixup the paths in distribution.data_files.
>
>
> Source:
>
> # https://gist.github.com/stuaxo/c76a042cb7aa6e77285b
> """
> Install a file into the root of sitepackages on windows as well as linux.
>
> Under normal operation on win32 path_to_site_packages
> gets changed to '' which installs inside the .egg instead.
> """
>
> import os
>
> from distutils import sysconfig
> from distutils.command.install_data import install_data
> from setuptools import setup
>
> here = os.path.normpath(os.path.abspath(os.path.dirname(__file__)))
>
> site_packages_path = sysconfig.get_python_lib()
> site_packages_files = ['TEST_FILE.TXT']
>
> class _install_data(install_data):
>     def finalize_options(self):
>         """
>         On win32 the files here are changed to '' which
>         ends up inside the .egg, change this back to the
>         absolute path.
>         """
>         install_data.finalize_options(self)
>         global site_packages_files
>         for i, f in enumerate(list(self.distribution.data_files)):
>             if not isinstance(f, basestring):
>                 folder, files = f
>                 if files == site_packages_files:
>                     # Replace with absolute path version
>                     self.distribution.data_files[i] = (site_packages_path,
> files)
>
> setup(
>     cmdclass={'install_data': _install_data},
>     name='test_install',
>     version='0.0.1',
>
>     description='',
>     long_description='',
>     url='https://example.com',
>     author='Stuart Axon',
>     author_email='stuaxo2 at yahoo.com',
>     license='PD',
>     classifiers=[],
>     keywords='',
>     packages=[],
>
>     install_requires=[],
>
>     data_files=[
>         (site_packages_path, site_packages_files),
>     ],
>
> )
>
>
>
> On Tue, 10 Mar, 2015 at 11:29 PM, Stuart Axon <stuaxo2 at yahoo.com> wrote:
>
> I had more of a dig into this, with a minimal setup.py:
> https://gist.github.com/stuaxo/c76a042cb7aa6e77285b setup calls
> install_data On win32 setup.py calls install_data which copies the file
> into the egg - even though I have given the absolute path to sitepackages
> C:\> python setup.py install .... running install_data creating
> build\bdist.win32\egg copying TEST_FILE.TXT -> build\bdist.win32\egg\ ....
> On Linux the file is copied to the right path: $ python setup.py install
> ..... installing package data to build/bdist.linux-x86_64/egg running
> install_data copying TEST_FILE.TXT ->
> /mnt/data/home/stu/.virtualenvs/tmpv/lib/python2.7/site-packages ....
> *something* is normalising my absolute path to site packages into just '' -
> it's possible to see by looking at self.data_files in the 'run' function
> in: distutils/command/install_data.py - on windows it the first part has
> been changed to '' unlike on linux where it's the absolute path I set...
> still not sure where it's happening though. *This all took a while, as
> rebuilt VM and verified on 2.7.8 and 2.7.9.. S++
>
> On Monday, March 9, 2015 12:17 AM, Stuart Axon <stuaxo2 at yahoo.com> wrote:
> > I had a further look - and on windows the file ends up inside the .egg
> file, on linux it ends up inside the site packages as intended. At a guess
> it seems like there might be a bug in the path handling on windows. .. I
> wonder if it's something like this
> http://stackoverflow.com/questions/4579908/cross-platform-splitting-of-path-in-python
> which seems an easy way to get an off-by-one error in a path ?
>
>
>
>
> _______________________________________________
> Distutils-SIG maillist  -  Distutils-SIG at python.org
> https://mail.python.org/mailman/listinfo/distutils-sig
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/distutils-sig/attachments/20150324/b9bbaab4/attachment.html>


More information about the Distutils-SIG mailing list