पर कॉल करते समय कस्टम कार्य चलाएं मैं अपना पायथन पैकेज "पीपी इंस्टॉल करने योग्य" बनाना चाहता हूं। समस्या यह है कि पैकेज में शेल स्क्रिप्ट है जिसे उपयोगकर्ता की 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
के माध्यम से एक पैकेज स्थापित करने के बाद एक कस्टम कार्य चलाने के लिए?
क्या आप 'distutils' का उपयोग करने के बजाय setuptools.command.install आयात इंस्टॉल' से 'प्रयास कर सकते हैं? –
@ आलोक, यह काम किया! कृपया उत्तर दें ताकि मैं इसे स्वीकार कर सकूं। :) – borges
हो गया। खुशी है कि यह काम किया। –