2

Is there a way to install files to arbitrary locations with setuptools? I've used Data Files with setuptools before, but those are typically installed inside the package directory. I need to install a plugin file that will be located in the install directory of another application.

pjs
  • 18,696
  • 4
  • 27
  • 56
Brendan Abel
  • 35,343
  • 14
  • 88
  • 118

3 Answers3

2

It seems that setuptools has purposely made it difficult to install files outside of the package directory.

I instead included the plugin files as package data and used the Entry Points feature of setuptools to expose the install/uninstall functions for the plugin files I wanted to distribute.

setup(
    ...
    entry_points={
        'console_scripts': [
            'mypackage_install_plugins = mypackage:install_plugins',
            'mypackage_uninstall_plugins = mypackage:uninstall_plugins',
        ],                
    }
)

I just added an additional step to the installation instructions to run the following command after installing the python package:

$> mypackage_install_plugins
Brendan Abel
  • 35,343
  • 14
  • 88
  • 118
1

The data_files attribute will allow you to specify full paths.
You could also do some shutil.copy magic in your setup.py, except don't.

ErlVolton
  • 6,714
  • 2
  • 15
  • 26
  • Thanks, this does seem to work for most locations; though, it doesn't seem to allow paths within another package inside the site-packages directory, which is the case for the Qt Designer plugins. – Brendan Abel Oct 29 '14 at 18:06
1

Check out this answer:

Execute a Python script post install using distutils / setuptools

which shows how to add an arbitrary install script (python, shell, whatever) that runs at the end of the install. It'll run whther you use "setup.py install" directly, or a package manager like "pip install". With this, you can add any files you want, anywhere you want.

Unfortunately, I feel Brendan's pain - setuptools, not being a full package manager itself, does not handle the uninstall. Therefore, there's no way to have an uninstall hook to reverse what you did in the post-install script.

Community
  • 1
  • 1
thebriguy
  • 183
  • 2
  • 7