[英]Running `chmod` after installing a package using `setup.py`
Let's assume I have a package which calls an executable file somewhere in the code (for example a third-party c/java-program). 假设我有一个程序包,该程序包在代码中的某个地方调用可执行文件(例如,第三方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
). 例如,一个可执行文件( 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: 并如下准备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
)
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. 在setup.py
脚本的末尾添加chmod
调用并不容易,因为需要首先弄清楚正确的安装路径。 I tried with resource_filename
but that returned the local file (as in "pre-installation"). 我尝试使用resource_filename
但是返回了本地文件(如“预安装”中所示)。
How can this problem be solved? 如何解决这个问题? Also with virtualenv
in mind... 还要考虑virtualenv
...
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). 如果使用scripts
关键字安装它,它将获得正确的模式(并安装在适当的bin /目录中)。
How would you execute something on files contained inside a package after install? 安装后如何对软件包中包含的文件执行某些操作?
This question would appear to address the same situation, and it looks like it has a reasonable answer. 这个问题似乎可以解决相同的情况,并且看起来有一个合理的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.