Run custom task when call `pip install`

两盒软妹~` 提交于 2019-11-26 11:27:05

问题


I want to make my python package \"pip installable\". The problem is that the package has shell script that must be sourced in the user\'s init shell script (e.g. .bashrc).

But after the installation, the user don\'t exactly know where the script went (presumably /usr/bin, but we can\'t garantee). Of course the user can runs which myscript.sh and manually edits his init script.

But I want to automate this step. I can create a new distutils command, but pip install doesn\'t call it. And I can extend distutils.command.install.install, but the installation breaks via pip (although works via python setup.py install):

setup.py

from distutils.command.install import install

class CustomInstall(install):
def run(self):
    install.run(self)
    # custom stuff here
    do_my_stuff()

setup(..., cmdclass={\'install\': CustomInstall})

shell

$ pip install dist/mypackage.tar.gz
Unpacking ./dist/mypackage.tar.gz
  Running setup.py egg_info for package from file:///path/to/mypackage/dist/mypackage.tar.gz

Installing collected packages: mypackage
  Running setup.py install for mypackage
    usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
       or: -c --help [cmd1 cmd2 ...]
       or: -c --help-commands
       or: -c cmd --help

    error: option --single-version-externally-managed not recognized
    Complete output from command /path/to/.virtualenvs/myvirtualenv/bin/python -c \"import setuptools;__file__=\'/tmp/pip-OFjrqU-build/setup.py\';exec(compile(open(__file__).read().replace(\'\\r\\n\', \'\\n\'), __file__, \'exec\'))\" install --record /tmp/pip-s4Yo4d-record/install-record.txt --single-version-externally-managed --install-headers /path/to/.virtualenvs/myvirtualenv/include/site/python2.7:
    usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
       or: -c --help [cmd1 cmd2 ...]
       or: -c --help-commands
       or: -c cmd --help

error: option --single-version-externally-managed not recognized

----------------------------------------
Command /path/to/.virtualenvs/myvirtualenv/bin/python -c \"import setuptools;__file__=\'/tmp/pip-OFjrqU-build/setup.py\';exec(compile(open(__file__).read().replace(\'\\r\\n\', \'\\n\'), __file__, \'exec\'))\" install --record /tmp/pip-s4Yo4d-record/install-record.txt --single-version-externally-managed --install-headers /path/to/.virtualenvs/myvirtualenv/include/site/python2.7 failed with error code 1 in /tmp/pip-OFjrqU-build
Storing complete log in /path/to/myhome/.pip/pip.log

What is the best aproach to run a custom task after install a package via pip?


回答1:


Could you try with from setuptools.command.install import install instead of using distutils?



来源:https://stackoverflow.com/questions/15853058/run-custom-task-when-call-pip-install

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!