Python paketimi "pip installable" yapmak istiyorum. Sorun, paketin kullanıcının init kabuk komut dosyasında (ör. .bashrc
) bulunması gereken kabuk betiğine sahip olmasıdır.“pip install” i çağırırken özel görevi çalıştırın
Ancak kurulumdan sonra, kullanıcı komut dosyasının nereye gittiğini tam olarak bilmemektedir (muhtemelen /usr/bin
, ancak garanti edemeyiz). Tabii ki kullanıcı which myscript.sh
'u çalıştırabilir ve kendi init betiğini elle düzenleyebilir.
Ancak bu adımı otomatikleştirmek istiyorum. Yeni bir distutils komutu oluşturabilirim, ancak pip install
onu çağırmıyor. Ve distutils.command.install.install
uzatmak, ama pip üzerinden tesisat sonları (her ne kadar python setup.py install
aracılığıyla işleri):
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})
kabuk
$ 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
Ne iyi yaklaşımı olan pip
aracılığıyla bir paket kurduktan sonra özel bir görev çalıştırmak için?
'distutils' yerine 'setuptools.command.install' 'import install'' ile denemeler yapabilir misiniz? –
@Alok, işe yaradı! lütfen cevap verebilmem için cevap ver. :) – borges
Bitti. Memnun kaldım. –