<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px"><div id="yui_3_16_0_1_1426491999706_6484">Hi All</div><div id="yui_3_16_0_1_1426491999706_7245" dir="ltr">    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 ?<br></div><div id="yui_3_16_0_1_1426491999706_10124" dir="ltr"><br></div><div id="yui_3_16_0_1_1426491999706_10125" dir="ltr">I'm monkey patching around these for now<br></div><div id="yui_3_16_0_1_1426491999706_11091" dir="ltr"><a id="yui_3_16_0_1_1426491999706_11094" href="https://github.com/stuaxo/vext/blob/master/setup.py#L16">https://github.com/stuaxo/vext/blob/master/setup.py#L16</a><br></div><div id="yui_3_16_0_1_1426491999706_6483"><span></span></div><div id="yui_3_16_0_1_1426491999706_14000"><br><span></span></div><div id="yui_3_16_0_1_1426491999706_14002"><div id="yui_3_16_0_1_1426491999706_14001">S++</div></div>  <br><div class="qtdSeparateBR"><br><br></div><div style="display: block;" class="yahoo_quoted"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;"> <div dir="ltr"> <font face="Arial" size="2"> On Thursday, March 12, 2015 2:54 PM, Stuart Axon <stuaxo2@yahoo.com> wrote:<br> </font> </div> <blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; margin-top: 5px; padding-left: 5px;">  <br><br> <div class="y_msg_container"><div id="yiv9542919583"><div>For closure:  The solution was to make a Command class + implement finalize_options to fixup the paths in distribution.data_files.<div><br clear="none"></div><div><br clear="none"></div><div>Source:</div><div><br clear="none"></div><div># <a rel="nofollow" shape="rect" target="_blank" href="https://gist.github.com/stuaxo/c76a042cb7aa6e77285b">https://gist.github.com/stuaxo/c76a042cb7aa6e77285b</a></div><div>"""</div><div>Install a file into the root of sitepackages on windows as well as linux.</div><div><br clear="none"></div><div>Under normal operation on win32 path_to_site_packages</div><div>gets changed to '' which installs inside the .egg instead.</div><div>"""</div><div><br clear="none"></div><div>import os</div><div><br clear="none"></div><div>from distutils import sysconfig</div><div>from distutils.command.install_data import install_data</div><div>from setuptools import setup</div><div><br clear="none"></div><div>here = os.path.normpath(os.path.abspath(os.path.dirname(__file__)))</div><div><br clear="none"></div><div>site_packages_path = sysconfig.get_python_lib()</div><div>site_packages_files = ['TEST_FILE.TXT']</div><div><br clear="none"></div><div>class _install_data(install_data):</div><div>    def finalize_options(self):</div><div>        """</div><div>        On win32 the files here are changed to '' which</div><div>        ends up inside the .egg, change this back to the</div><div>        absolute path.</div><div>        """</div><div>        install_data.finalize_options(self)</div><div>        global site_packages_files</div><div>        for i, f in enumerate(list(self.distribution.data_files)):</div><div>            if not isinstance(f, basestring):</div><div>                folder, files = f</div><div>                if files == site_packages_files:</div><div>                    # Replace with absolute path version</div><div>                    self.distribution.data_files[i] = (site_packages_path, files)</div><div><br clear="none"></div><div>setup(</div><div>    cmdclass={'install_data': _install_data},</div><div>    name='test_install',</div><div>    version='0.0.1',</div><div><br clear="none"></div><div>    description='',</div><div>    long_description='',</div><div>    url='<a rel="nofollow" shape="rect" target="_blank" href="https://example.com/">https://example.com</a>',</div><div>    author='Stuart Axon',</div><div>    author_email='stuaxo2@yahoo.com',</div><div>    license='PD',</div><div>    classifiers=[],</div><div>    keywords='',</div><div>    packages=[],</div><div><br clear="none"></div><div>    install_requires=[],</div><div><br clear="none"></div><div>    data_files=[</div><div>        (site_packages_path, site_packages_files),</div><div>    ],</div><div><br clear="none"></div><div>)</div><div><br clear="none"></div><div><br clear="none"><div class="yiv9542919583yqt2417488586" id="yiv9542919583yqtfd49264"><br clear="none">On Tue, 10 Mar, 2015 at 11:29 PM, Stuart Axon <stuaxo2@yahoo.com> wrote:<br clear="none">
<blockquote type="cite"><div class="yiv9542919583plaintext" style="white-space:pre-wrap;">I had more of a dig into this, with a minimal setup.py:


<a rel="nofollow" shape="rect" target="_blank" href="https://gist.github.com/stuaxo/c76a042cb7aa6e77285b">https://gist.github.com/stuaxo/c76a042cb7aa6e77285b</a>

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++




<blockquote> On Monday, March 9, 2015 12:17 AM, Stuart Axon <stuaxo2@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
 
 <a rel="nofollow" shape="rect" target="_blank" href="http://stackoverflow.com/questions/4579908/cross-platform-splitting-of-path-in-python">http://stackoverflow.com/questions/4579908/cross-platform-splitting-of-path-in-python</a>
 
 which seems an easy way to get an off-by-one error in a path ?
 
</blockquote></div></blockquote></div></div></div></div><br><br></div> </blockquote>  </div> </div>   </div></div></body></html>