如何依赖于系统命令与python / distutils? [英] How to depends of a system command with python/distutils?

查看:191
本文介绍了如何依赖于系统命令与python / distutils?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找最优雅的方式通知我的图书馆的用户,他们需要一个特定的unix命令,以确保它将工作...



是我的lib提出错误的赌注时间:




  • 安装?





< b

还应该如何检测命令是否丢失(如果不是commands.getoutput(which CommandIDependsOn):raise Exception(你需要CommandIDependsOn)

解决方案



<我不会有任何检查。记录你的库需要这个命令,如果用户试图使用库的任何部分需要它,运行命令将引发异常。



(PS: commands

code>是旧的和破碎的,不应该在新的代码中使用 subprocess 是热的新东西。)


I'm looking for the most elegant way to notify users of my library that they need a specific unix command to ensure that it will works...

When is the bet time for my lib to raise an error:

  • Installation ?
  • When my app call the command ?
  • At the import of my lib ?
  • both?

And also how should you detect that the command is missing (if not commands.getoutput("which CommandIDependsOn"): raise Exception("you need CommandIDependsOn")).

I need advices.

解决方案

I wouldn't have any check at all. Document that your library requires this command, and if the user tries to use whatever part of your library needs it, an exception will be raised by whatever runs the command. It should still be possible to import your library and use it, even if only a subset of functionality is offered.

(PS: commands is old and broken and shouldn't be used in new code. subprocess is the hot new stuff.)

这篇关于如何依赖于系统命令与python / distutils?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆