Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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?

like image 898
tdavis Avatar asked Jan 29 '10 00:01

tdavis


People also ask

What is the use of setuptools in Python?

Setuptools is a collection of enhancements to the Python distutils that allow developers to more easily build and distribute Python packages, especially ones that have dependencies on other packages. Packages built and distributed using setuptools look to the user like ordinary Python packages based on the distutils .

What is setuptools module in Python?

setuptools is a package development process library designed to facilitate packaging Python projects by enhancing the Python standard library distutils (distribution utilities). It includes: Python package and module definitions. Distribution package metadata. Test hooks.

What are PYPA setuptools?

Setuptools is a fully-featured, actively-maintained, and stable library designed to facilitate packaging Python projects. It helps developers to easily share reusable code (in the form of a library) and programs (e.g., CLI/GUI tools implemented in Python), that can be installed with pip and uploaded to PyPI.

Does pip require setuptools?

A Python file that relies only on the standard library can be redistributed and reused without the need to use setuptools. But for projects that consist of multiple files, need additional libraries, or need a specific version of Python, setuptools will be required.


2 Answers

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,
    },
    ...
)
like image 71
boses Avatar answered Nov 15 '22 14:11

boses


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

like image 44
PJ Eby Avatar answered Nov 15 '22 13:11

PJ Eby