开发者

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

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 a开发者_如何学JAVAnother 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?


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,
    },
    ...
)


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).


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜