How do you configure your setup.py so that it does not attempt to overwrite a script if it already exists? Or at least finish the rest of the package installation if writing a script fails. I am using setuptools for my setup.py. The relevant part of setup.py is this:
如何配置setup.py,以便它不会覆盖已经存在的脚本?或者至少在编写脚本失败时完成软件包安装的其余部分。我在setup.py上使用setuptools。 setup.py的相关部分是这样的:
entry_points = {
'console_scripts' : [
'green = green:main', # <-- The one I have problems with
'green%d = green:main' % sys.version_info[:1], # green2 or green3
'green-%d.%d = green:main' % sys.version_info[:2], # green-3.4 etc.
],
},
my setup.py has both versioned scripts (the version of python is included in the name of the script) and unversioned scripts. On OS X I use system python for 2.7, which requires superuser permissions to run pip (sudo pip ...), which causes the script to get installed under /usr/local/bin
with root ownership. Then when I try installing under python 3.4 installed via homebrew with user permissions, it attempts (and fails) to overwrite the unversioned script in /usr/local/bin
. I don't mind that it can't overwrite the script file, I do mind that pip fails the install and leaves the half-installed package in a weird, funky state.
我的setup.py有两个版本化的脚本(python的版本包含在脚本的名称中)和无版本的脚本。在OS X上,我使用系统python for 2.7,这需要超级用户权限来运行pip(sudo pip ...),这会导致脚本安装在具有root所有权的/ usr / local / bin下。然后当我尝试通过带有用户权限的homebrew安装的python 3.4下安装时,它会尝试(并且失败)覆盖/ usr / local / bin中的无版本脚本。我不介意它不能覆盖脚本文件,我记得pip无法安装并使半安装的软件包处于一个奇怪,时髦的状态。
I would like to be able to instruct setup.py to either not attempt to install a script if it was already installed by something else, or at least to ignore the error and continue with the rest of the installation if it doesn't have permissions to overwrite the script.
我希望能够指示setup.py如果已经安装了其他内容,则不尝试安装脚本,或者至少忽略错误并继续安装其余部分(如果它没有权限)覆盖脚本。
1 个解决方案
#1
0
I am not aware, if standard setup
function behaviour support your requirement.
我不知道,标准设置功能行为是否支持您的要求。
But I am sure, following can be done:
但我相信,可以做以下事情:
Ask setup
only for what is really possible
-
before you call your
setup
, check, if the script is already present and you are willing to reinstall it or skip. You are in Python script, so you have full Python power at hand, use it to investigate the situation and make the decision.在调用您的设置之前,请检查脚本是否已存在并且您是否愿意重新安装或跳过。您使用的是Python脚本,因此您拥有完整的Python功能,可以使用它来调查情况并做出决定。
-
When calling
setup
, construct the value ofentry_points
in such a way, it does what you need (either install or not install the script).调用setup时,以这种方式构造entry_points的值,它可以满足您的需要(安装或不安装脚本)。
Anyway, this has the dificulty, you need to do your own analysis, if the script to install is already there, where it is, check, if you shall update it or not etc.
无论如何,这有困难,你需要做自己的分析,如果要安装的脚本已经存在,它在哪里,检查,你是否应该更新它等。
Try asking setup
for what you want, if it fails, ask for less
As setup
is a funcion, you can put it into try
and except
, if you know, that you can resolve the problem asking to install without first script, second try may go this way.
由于设置是一个功能,你可以把它用于尝试,除非,如果你知道,你可以解决问题要求安装没有第一个脚本,第二次尝试可能会这样。
#1
0
I am not aware, if standard setup
function behaviour support your requirement.
我不知道,标准设置功能行为是否支持您的要求。
But I am sure, following can be done:
但我相信,可以做以下事情:
Ask setup
only for what is really possible
-
before you call your
setup
, check, if the script is already present and you are willing to reinstall it or skip. You are in Python script, so you have full Python power at hand, use it to investigate the situation and make the decision.在调用您的设置之前,请检查脚本是否已存在并且您是否愿意重新安装或跳过。您使用的是Python脚本,因此您拥有完整的Python功能,可以使用它来调查情况并做出决定。
-
When calling
setup
, construct the value ofentry_points
in such a way, it does what you need (either install or not install the script).调用setup时,以这种方式构造entry_points的值,它可以满足您的需要(安装或不安装脚本)。
Anyway, this has the dificulty, you need to do your own analysis, if the script to install is already there, where it is, check, if you shall update it or not etc.
无论如何,这有困难,你需要做自己的分析,如果要安装的脚本已经存在,它在哪里,检查,你是否应该更新它等。
Try asking setup
for what you want, if it fails, ask for less
As setup
is a funcion, you can put it into try
and except
, if you know, that you can resolve the problem asking to install without first script, second try may go this way.
由于设置是一个功能,你可以把它用于尝试,除非,如果你知道,你可以解决问题要求安装没有第一个脚本,第二次尝试可能会这样。