Re: [Distutils] Installing a file into sitepackages
Finally got round to trying this in python3, it works well so switching over to it, cheers :) S++ On Friday, March 27, 2015 4:57 PM, Ionel Cristian Mărieș wrote: Also, a similar command subclass can be written for `develop`. So far i got 3 subclasses, for: build, easy_install and develop. Did I miss something important? Thanks, -- Ionel Cristian Mărieș, http://blog.ionelmc.ro On Wed, Mar 25, 2015 at 2:51 PM, Stuart Axon wrote: That looks much cleaner than my one, I'll give it a try.. does it work on python3, just found out my one does not. S++ On Wednesday, March 25, 2015 9:03 AM, Ionel Cristian Mărieș wrote: This seems to do the trick: class EasyInstallWithPTH(easy_install): def run(self): easy_install.run(self) for path in glob(join(dirname(__file__), 'src', '*.pth')): dest = join(self.install_dir, basename(path)) self.copy_file(path, dest) Thanks, -- Ionel Cristian Mărieș, http://blog.ionelmc.ro On Tue, Mar 24, 2015 at 11:36 AM, Stuart Axon 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ș 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 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 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_packagesgets changed to '' which installs inside the .egg instead.""" import os from distutils import sysconfigfrom distutils.command.install_data import install_datafrom 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='stua...@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 wrote: I had more of a dig into this, with a minimal setup.py:https://gist.github.com/stuaxo/c76a042cb7aa6e77285bsetup calls install_dataOn win32 setup.py calls install_data which copies the file into the egg - even though I have given the absolute path to sitepackagesC:\> python setup.py installrunning install_datacreating build\bdist.win32\eggcopying 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/eggrunning install_datacopying 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 happe
Re: [Distutils] Installing a file into sitepackages
Also, a similar command subclass can be written for `develop`. So far i got 3 subclasses, for: build, easy_install and develop. Did I miss something important? Thanks, -- Ionel Cristian Mărieș, http://blog.ionelmc.ro On Wed, Mar 25, 2015 at 2:51 PM, Stuart Axon wrote: > That looks much cleaner than my one, I'll give it a try.. does it work on > python3, just found out my one does not. > > S++ > > > > On Wednesday, March 25, 2015 9:03 AM, Ionel Cristian Mărieș < > cont...@ionelmc.ro> wrote: > > > > This seems to do the trick: > > class EasyInstallWithPTH(easy_install): > def run(self): > easy_install.run(self) > for path in glob(join(dirname(__file__), 'src', '*.pth')): > dest = join(self.install_dir, basename(path)) > self.copy_file(path, dest) > > > Thanks, > -- Ionel Cristian Mărieș, http://blog.ionelmc.ro > > On Tue, Mar 24, 2015 at 11:36 AM, Stuart Axon 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ș < > cont...@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 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 > 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='stua...@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 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 i
Re: [Distutils] Installing a file into sitepackages
That looks much cleaner than my one, I'll give it a try.. does it work on python3, just found out my one does not. S++ On Wednesday, March 25, 2015 9:03 AM, Ionel Cristian Mărieș wrote: This seems to do the trick: class EasyInstallWithPTH(easy_install): def run(self): easy_install.run(self) for path in glob(join(dirname(__file__), 'src', '*.pth')): dest = join(self.install_dir, basename(path)) self.copy_file(path, dest) Thanks, -- Ionel Cristian Mărieș, http://blog.ionelmc.ro On Tue, Mar 24, 2015 at 11:36 AM, Stuart Axon 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ș 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 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 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_packagesgets changed to '' which installs inside the .egg instead.""" import os from distutils import sysconfigfrom distutils.command.install_data import install_datafrom 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='stua...@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 wrote: I had more of a dig into this, with a minimal setup.py:https://gist.github.com/stuaxo/c76a042cb7aa6e77285bsetup calls install_dataOn win32 setup.py calls install_data which copies the file into the egg - even though I have given the absolute path to sitepackagesC:\> python setup.py installrunning install_datacreating build\bdist.win32\eggcopying 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/eggrunning install_datacopying 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 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-pla
Re: [Distutils] Installing a file into sitepackages
This seems to do the trick: class EasyInstallWithPTH(easy_install): def run(self): easy_install.run(self) for path in glob(join(dirname(__file__), 'src', '*.pth')): dest = join(self.install_dir, basename(path)) self.copy_file(path, dest) Thanks, -- Ionel Cristian Mărieș, http://blog.ionelmc.ro On Tue, Mar 24, 2015 at 11:36 AM, Stuart Axon 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ș < > cont...@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 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 > 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='stua...@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 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 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 l
Re: [Distutils] Installing a file into sitepackages
Yeah, I think it's a bit weird that it ends up there, makes sense for most files, but .pth files are only evaluated in site-packages - the sandbox should probably treat them differently... S++ On Tuesday, March 24, 2015 4:59 PM, Ionel Cristian Mărieș wrote: H, 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 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ș 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 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 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_packagesgets changed to '' which installs inside the .egg instead.""" import os from distutils import sysconfigfrom distutils.command.install_data import install_datafrom 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='stua...@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 wrote: I had more of a dig into this, with a minimal setup.py:https://gist.github.com/stuaxo/c76a042cb7aa6e77285bsetup calls install_dataOn win32 setup.py calls install_data which copies the file into the egg - even though I have given the absolute path to sitepackagesC:\> python setup.py installrunning install_datacreating build\bdist.win32\eggcopying 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/eggrunning install_datacopying 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 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
Re: [Distutils] Installing a file into sitepackages
H, 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 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ș < > cont...@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 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 > 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='stua...@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 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 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
Re: [Distutils] Installing a file into sitepackages
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ș 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 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 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_packagesgets changed to '' which installs inside the .egg instead.""" import os from distutils import sysconfigfrom distutils.command.install_data import install_datafrom 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='stua...@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 wrote: I had more of a dig into this, with a minimal setup.py:https://gist.github.com/stuaxo/c76a042cb7aa6e77285bsetup calls install_dataOn win32 setup.py calls install_data which copies the file into the egg - even though I have given the absolute path to sitepackagesC:\> python setup.py installrunning install_datacreating build\bdist.win32\eggcopying 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/eggrunning install_datacopying 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 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@python.org https://mail.python.org/mailman/listinfo/distutils-sig ___ Distutils-SIG maillist - Distutils-SIG@python.org https://mail.python.org/mailman/listinfo/distutils-sig
Re: [Distutils] Installing a file into sitepackages
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 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 > 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='stua...@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 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 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@python.org > https://mail.python.org/mailman/listinfo/distutils-sig > > ___ Distutils-SIG maillist - Distutils-SIG@python.org https://mail.python.org/mailman/listinfo/distutils-sig
Re: [Distutils] Installing a file into sitepackages
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 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_packagesgets changed to '' which installs inside the .egg instead.""" import os from distutils import sysconfigfrom distutils.command.install_data import install_datafrom 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='stua...@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 wrote: I had more of a dig into this, with a minimal setup.py:https://gist.github.com/stuaxo/c76a042cb7aa6e77285bsetup calls install_dataOn win32 setup.py calls install_data which copies the file into the egg - even though I have given the absolute path to sitepackagesC:\> python setup.py installrunning install_datacreating build\bdist.win32\eggcopying 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/eggrunning install_datacopying 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 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@python.org https://mail.python.org/mailman/listinfo/distutils-sig
Re: [Distutils] Installing a file into sitepackages
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='stua...@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 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 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@python.org https://mail.python.org/mailman/listinfo/distutils-sig
Re: [Distutils] Installing a file into sitepackages
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 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@python.org https://mail.python.org/mailman/listinfo/distutils-sig
Re: [Distutils] Installing a file into sitepackages
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@python.org https://mail.python.org/mailman/listinfo/distutils-sig
Re: [Distutils] Installing a file into sitepackages
Hm - I was able to reproduce it just now, I tried it with and without a recent site packages. Since my project is an import hook I want it to be imported on startup, maybe I should do this in a different way ... S++ > On Saturday, March 7, 2015 1:51 AM, Erik Bray wrote: > > On Fri, Feb 20, 2015 at 1:49 PM, Stuart Axon > > wrote: >> Hi, >> In my project, I install a .pth file into site-packages, I use the > data_files... in Ubuntu this seems to work OK, but in a Windows VM the file > doesn't seem to be being installed: >> >> setup( >> >> # Install the import hook >> data_files=[ >> (site_packages_path, ["vext_importer.pth"] if > environ.get('VIRTUAL_ENV') else []), >> ], >> ) >> >> >> - Is there a better way to do this ? >> >> >> >> I realise it's a bit odd installing a .pth - my project is to allow > certain packages to use the system site packages from a virtualenv - >> https://github.com/stuaxo/vext > > Hi Stuart, > > I know this is old so sorry to anyone else. But since no one > replied--I haven't looked too closely at what it is you're trying to > accomplish. But whatever the reason, that seems like a > reasonable-enough way to me if you need to get a .pth file installed > into site-packages. I'm not sure why it isn't working for you in > WIndows but it wasn't clear what the problem was. I just tried this > in a Windows VM and it worked fine? > > Best, > Erik > ___ Distutils-SIG maillist - Distutils-SIG@python.org https://mail.python.org/mailman/listinfo/distutils-sig
Re: [Distutils] Installing a file into sitepackages
On Fri, Feb 20, 2015 at 1:49 PM, Stuart Axon wrote: > Hi, >In my project, I install a .pth file into site-packages, I use the > data_files... in Ubuntu this seems to work OK, but in a Windows VM the file > doesn't seem to be being installed: > > setup( > ># Install the import hook > data_files=[ > (site_packages_path, ["vext_importer.pth"] if > environ.get('VIRTUAL_ENV') else []), > ], > ) > > > - Is there a better way to do this ? > > > > I realise it's a bit odd installing a .pth - my project is to allow certain > packages to use the system site packages from a virtualenv - > https://github.com/stuaxo/vext Hi Stuart, I know this is old so sorry to anyone else. But since no one replied--I haven't looked too closely at what it is you're trying to accomplish. But whatever the reason, that seems like a reasonable-enough way to me if you need to get a .pth file installed into site-packages. I'm not sure why it isn't working for you in WIndows but it wasn't clear what the problem was. I just tried this in a Windows VM and it worked fine? Best, Erik ___ Distutils-SIG maillist - Distutils-SIG@python.org https://mail.python.org/mailman/listinfo/distutils-sig
[Distutils] Installing a file into sitepackages
Hi, In my project, I install a .pth file into site-packages, I use the data_files... in Ubuntu this seems to work OK, but in a Windows VM the file doesn't seem to be being installed: setup( # Install the import hook data_files=[ (site_packages_path, ["vext_importer.pth"] if environ.get('VIRTUAL_ENV') else []), ], ) - Is there a better way to do this ? I realise it's a bit odd installing a .pth - my project is to allow certain packages to use the system site packages from a virtualenv - https://github.com/stuaxo/vext S++ ___ Distutils-SIG maillist - Distutils-SIG@python.org https://mail.python.org/mailman/listinfo/distutils-sig