Use distribute/setuptools to create symlink (or run script)?
Asked Answered
K

3

10

As part of my project's setup process, I need to symlink one of the packages to a specified directory so an init.d script can find it. Is there any way to add this as a post-processing command to setup()? I would even settle for creating another file that creates the link and pass it to setup() as part of some kwarg list of "run these" (if such an option exists).

setup(
    ...
    packages = find_packages('src'),
    package_dir = {'': 'src'},
    install_requires = ...,
    data_files = [('/etc/init.d', ['scripts/foo'])],
    ...
)

that foo script expects one of the packages from src/ to be symlinked to directory elsewhere (e.g. not simply be on PYTHONPATH). Is there a way to achieve that?

Kurgan answered 29/1, 2010 at 0:57 Comment(0)
D
4

Currently, only platform-specific package management tools (e.g. RPM, deb, win32 installers) have the ability to run post-install steps: the distutils, setuptools, etc. do not support this directly. (Except to the extent of allowing you to build the RPM, windows installer, etc.)

So, the simplest way to do this without a platform-specific installer, is to create a postinstall script of your own, or add a postinstall option to an existing script of yours, and tell users to run it. Otherwise, you'll have to use bdist_rpm or one of the other bdist commands to build an installer for the appropriate platform(s).

Demos answered 29/1, 2010 at 17:36 Comment(0)
I
9

I know this post is several years old but I wanted to provide an update that post-processing code is possible in setup.py. Long story short, you have to override the install function of setuptools but from then on you can add whatever code you want, such as copying symlinks that MANIFEST.in refuses to copy. Taken from Peter Lamut's solution.

from setuptools.command.install import install

class CustomInstallCommand(install):
    """Customized setuptools install command - prints a friendly greeting."""
    def run(self):
        print "Hello, developer, how are you? :)"
        install.run(self)
        #post-processing code
setup(
    ...
    cmdclass={
        'install': CustomInstallCommand,
    },
    ...
)
Iolenta answered 21/10, 2014 at 15:45 Comment(1)
Hélio Guilherme notified me that the link to my blog post was dead. I edited your post to make the link alive again. I'm glad that you found it useful, BTW.Radioman
D
4

Currently, only platform-specific package management tools (e.g. RPM, deb, win32 installers) have the ability to run post-install steps: the distutils, setuptools, etc. do not support this directly. (Except to the extent of allowing you to build the RPM, windows installer, etc.)

So, the simplest way to do this without a platform-specific installer, is to create a postinstall script of your own, or add a postinstall option to an existing script of yours, and tell users to run it. Otherwise, you'll have to use bdist_rpm or one of the other bdist commands to build an installer for the appropriate platform(s).

Demos answered 29/1, 2010 at 17:36 Comment(0)
K
0

Expanding on @pjeby's answer, you can also extend the install command to add your own custom postinstall steps. However that will only work when installing from source (i.e. running setup.py) and other installers like RPM and MSI will silently ignore your changes.

EDIT: Found this after some googling, it seems you should not try to create the symlinks by yourself: http://docs.python.org/2/install/index.html#alternate-installation

Kipkipling answered 20/3, 2013 at 12:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.