我可以让pip删除我已经安装但不再需要的脚本吗?

2024-06-01 06:38:07 发布

您现在位置:Python中文网/ 问答频道 /正文

假设我有以下项目:

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

我的用户已经安装了它,所以他们可以简单地键入

$ spring_surprise.py

从他们的电脑里弹出来的不锈钢螺栓,刺穿了他们的双颊

不过,警员鹦鹉说服了我,让我搬到更传统的糖果店,所以我不会再提供这样的甜食了。我已将脚本更改为这样:

scripts/
   praline.py
   lime_coconut.py

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

是否可以在my setup.py中指定在升级应用程序时不再需要这些旧脚本


Tags: 项目用户py脚本键入initscriptssurprise
1条回答
网友
1楼 · 发布于 2024-06-01 06:38:07

正确的方法是通过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

好吃

相关问题 更多 >