简体   繁体   English

具有可执行权限的package_data文件

[英]package_data files with executable permissions

I am using distutils to create a Python (2) package installer. 我正在使用distutils来创建一个Python(2)包安装程序。 In my package are a couple of binary executable that get called from my Python code. 在我的包中有一些二进制可执行文件,可以从我的Python代码中调用。 I am listing these as package_data in my setup.py file so they get installed along with the package. 我在setup.py文件中将这些列为package_data ,因此它们随包一起安装。 However, distutils does not copy the executable permission bit on these files when they are installed. 但是,distutils在安装这些文件时不会复制这些文件的可执行权限位。 Is there a way to force distutils to install package_data files with executable permissions? 有没有办法强制distutils安装具有可执行权限的package_data文件?

Figured it out based on some other SO answers - the following works: 根据其他一些SO答案计算出来 - 以下工作:

class my_install_lib(distutils.command.install_lib.install_lib):
  def run(self):
    distutils.command.install_lib.install_lib.run(self)
    for fn in self.get_outputs():
      if <this is one of the binaries I want to be executable>:
        # copied from distutils source - make the binaries executable
        mode = ((os.stat(fn).st_mode) | 0555) & 07777
        distutils.log.info("changing mode of %s to %o", fn, mode)
        os.chmod(fn, mode)

and then pass cmdclass={'install_lib':my_install_lib} to setup . 然后将cmdclass={'install_lib':my_install_lib}传递给setup

You could also use setuptools instead of distutils. 您也可以使用setuptools而不是distutils。 The setuptools preserves the file modes of the package_data files, whereas distutils doesn't. setuptools保留package_data文件的文件模式,而distutils则不保存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM