我可以获取pip来删除我安装但不再需要的脚本吗?

时间:2015-06-03 20:57:36

标签: python setuptools

说我有以下项目:

confectionary/
    __init__.py
    confections.py
scripts/
    crunchy_frog.py
    anthrax_ripple.py
    spring_surprise.py

它已由我的用户安装,因此他们只需输入

即可
$ spring_surprise.py

并从计算机中弹出不锈钢螺栓,刺穿两颊。

然而,Constable Parrot已经说服我进入更多传统区域的糖果,所以我将不再提供这样的甜食。我已将脚本更改为如下所示:

scripts/
   praline.py
   lime_coconut.py

然而,当我安装这个较新的版本时,旧的脚本仍然存在。

是否有可能在我的setup.py中以某种方式指定我的应用程序升级时不再需要这些旧脚本?

1 个答案:

答案 0 :(得分:0)

正确的方法是通过setuptools。令人愉快的Click library has a great example

而不是拥有scripts目录,只需在应用程序本身的某个地方组合这些信息,因此confections.py应包含以下内容:

def crunchy_frog():
    '''Only the freshest killed frogs... '''
    # TODO: implement

def anthrax_ripple():
    '''A delightful blend of Anthrax spores... '''
    # TODO: implement

def spring_surprise():
    '''Deploy stainless steel bolts, piercing both cheeks'''
    # TODO: implement

然后在setup.py

from setuptools import setup

setup(
    name='confectionary',
    version='1.0.0',
    py_modules=['confectionary'],
    entry_points='''
        [console_scripts]
        crunchy_frog=confectionary.confections:crunchy_frog
        anthrax_ripple=confectionary.confections:anthrax_ripple
        spring_surprise=confectionary.confections:spring_surprise
    ''',
)

当你更改它时,显然你会适当地改变confections.py,但是你可以改变你的setup.py

from setuptools import setup

setup(
    name='confectionary',
    version='2.0.0',
    py_modules=['confectionary'],
    entry_points='''
        [console_scripts]
        praline=confectionary.confections:praline
        lime_coconut=confectionary.confections:lime_coconut
    ''',
)

现在一切都会快乐!作为额外的奖励,您会发现setuptools也会在Windows上创建appropriate files

美味!

相关问题