使用“setup.py”安装软件包后运行“chmod”
假设我有一个包,它在代码中的某个位置调用可执行文件(例如第三方 c/java 程序)。让我们进一步假设,应用程序足够小/简单,可以与包捆绑在一起。例如单个可执行文件 (cfoo
)。
我可以继续,将文件放入以下结构中:
.
|-- foo
| |-- __init__.py
| |-- __init__.pyc
| |-- core.py
| |-- corebin
| | `-- cfoo
| `-- foomain.py
`-- setup.py
并准备一个 setup.py
如下:
from setuptools import setup
setup(
name='foo',
version='1.0',
packages=['foo'],
scripts=['foo/foomain.py'],
package_data={'foo': ['corebin/*']},
zip_safe=False
)
这将使我能够正确安装该软件包。稍后,在包代码中我可以这样做:
from subprocess import call
import pkg_resources as res
def main():
fn = res.resource_filename('foo', 'corebin/cfoo')
print "Resource located at:", fn
call([fn])
不幸的是,可执行文件将在没有设置可执行标志的情况下安装。即使原始文件已设置。在 setup.py
脚本末尾添加 chmod
调用并不容易,因为需要首先找出正确的安装路径。我尝试使用 resource_filename
但返回了本地文件(如“预安装”中所示)。
如何解决这个问题呢?还要考虑到virtualenv
...
Let's assume I have a package which calls an executable file somewhere in the code (for example a third-party c/java-program). Let's further assume, the application is small/trivial enough to bundle with the package. For example a single executable file (cfoo
).
I could go ahead, and put the files into the following structure:
.
|-- foo
| |-- __init__.py
| |-- __init__.pyc
| |-- core.py
| |-- corebin
| | `-- cfoo
| `-- foomain.py
`-- setup.py
And prepare a setup.py
as follows:
from setuptools import setup
setup(
name='foo',
version='1.0',
packages=['foo'],
scripts=['foo/foomain.py'],
package_data={'foo': ['corebin/*']},
zip_safe=False
)
This will allow me to properly install the package. Later, in the package-code I could do this:
from subprocess import call
import pkg_resources as res
def main():
fn = res.resource_filename('foo', 'corebin/cfoo')
print "Resource located at:", fn
call([fn])
Unfortunately, the executable file will be installed without executable flag set. Even if the original file had it set. Adding a chmod
call at the end of the setup.py
script is not as easy, as one would need to figure out the proper installation path first. I tried with resource_filename
but that returned the local file (as in "pre-installation").
How can this problem be solved? Also with virtualenv
in mind...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将我的评论推广为答案:
如果您使用
scripts
关键字安装它,它将获得正确的模式(并安装在适当的 bin/ 目录中)。此问题会出现针对同样的情况,看起来它有一个合理的答案。
I'm promoting my comment to an answer:
If you install it using the
scripts
keyword, it will get the correct mode (and get installed in an appropriate bin/ directory).This question would appear to address the same situation, and it looks like it has a reasonable answer.