2013-04-06 14 views
12

पर कॉल करते समय कस्टम कार्य चलाएं मैं अपना पायथन पैकेज "पीपी इंस्टॉल करने योग्य" बनाना चाहता हूं। समस्या यह है कि पैकेज में शेल स्क्रिप्ट है जिसे उपयोगकर्ता की init shell script (उदा। .bashrc) में सोर्स किया जाना चाहिए।'पाइप इंस्टॉल'

लेकिन स्थापना के बाद, उपयोगकर्ता बिल्कुल नहीं जानता कि स्क्रिप्ट कहाँ गई (संभवतः /usr/bin, लेकिन हम गारंटी नहीं दे सकते)। बेशक उपयोगकर्ता which myscript.sh चला सकता है और मैन्युअल रूप से अपनी init स्क्रिप्ट संपादित करता है।

लेकिन मैं इस चरण को स्वचालित करना चाहता हूं। मैं एक नया distutils कमांड बना सकते हैं, लेकिन pip install इसे कॉल नहीं करता है। और मैं distutils.command.install.install विस्तार कर सकते हैं, लेकिन पिप के माध्यम से स्थापना टूट जाता है (हालांकि 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}) 

खोल

$ 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 

क्या सबसे अच्छा aproach है pip के माध्यम से एक पैकेज स्थापित करने के बाद एक कस्टम कार्य चलाने के लिए?

+1

क्या आप 'distutils' का उपयोग करने के बजाय setuptools.command.install आयात इंस्टॉल' से 'प्रयास कर सकते हैं? –

+1

@ आलोक, यह काम किया! कृपया उत्तर दें ताकि मैं इसे स्वीकार कर सकूं। :) – borges

+0

हो गया। खुशी है कि यह काम किया। –

उत्तर

11

क्या आप distutils का उपयोग करने के बजाय from setuptools.command.install import install के साथ प्रयास कर सकते हैं?

+0

धन्यवाद, यह वास्तव में मेरी मदद की। मैंने पीछा किया था (https://stackoverflow.com/questions/17806485/execute-a-python-script-post-install-using-distutils-setuptools) और उसी समस्या को प्राप्त किया, इसे दस्तावेज़ में (http: // ब्लॉग। diffbrent.com/correctly-adding-nltk-to-your-python-package-using-setup-py-post-install-commands/) और आपको –

+5

प्रोप 0 देता है मुझे वही समस्या मिल रही है [http] (http: //stackoverflow.com/questions/19569557/pip-not-picking-up-a-custom-install-cmdclass?lq=1) - मुझे 'python setup.py install' चलाते समय कस्टम व्यवहार मिलता है, लेकिन जब मैं नहीं रन 'पाइप इंस्टॉल '। कोई विचार? – scubbo

+5

मेरे पास एक ही समस्या है। '' pip install -e .'' 'कमांड क्लास चलाता है और फिर यह तब चलता है जब मैं bdist_wheel करता हूं लेकिन पाइप इंस्टॉल के दौरान कुछ भी नहीं होता है। – bjorns

संबंधित मुद्दे