Last active
August 29, 2015 14:16
-
-
Save stuaxo/c76a042cb7aa6e77285b to your computer and use it in GitHub Desktop.
Install file to site_packages root on windows as well as linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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 vext_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': vext_install_data}, | |
name='test_install', | |
version='0.0.1', | |
description='', | |
long_description='', | |
url='https://example.com', | |
author='Stuart Axon', | |
author_email='stuaxo2@yahoo.com', | |
license='PD', | |
classifiers=[], | |
keywords='', | |
packages=[], | |
install_requires=[], | |
# Install the import hook | |
data_files=[ | |
(site_packages_path, site_packages_files), | |
], | |
) | |
#print site_packages_path[2:] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment