【问题标题】:Copying a built framework into Python package with package_data使用 package_data 将构建的框架复制到 Python 包中
【发布时间】:2017-11-15 04:49:42
【问题描述】:

我正在尝试改进PyBluez 在 macOS 上的安装方式。 Here 是 setup.py 代码在我更改之前的样子。

简而言之,在 macOS 上安装了一个名为 lightblue 的额外包,这取决于一个名为 LightAquaBlue.framework 的框架。今天它调用xcodebuild构建框架并安装到/Library/Frameworks,但我想改变它以将框架嵌入到Python包中。

这是我所做的:

packages.append('lightblue')
package_dir['lightblue'] = 'osx'
install_requires += ['pyobjc-core>=3.1', 'pyobjc-framework-Cocoa>=3.1']

# Add the LightAquaBlue framework to the package data as an 'eager resource'
# so that we can extract the whole framework at runtime
package_data['lightblue'] = [ 'LightAquaBlue.framework' ]
eager_resources.append('LightAquaBlue.framework')

# FIXME: This is inelegant, how can we cover the cases?
if 'install' in sys.argv or 'bdist' in sys.argv or 'bdist_egg' in sys.argv:
    # Build the framework into osx/
    import subprocess
    subprocess.check_call([
        'xcodebuild', 'install',
        '-project', 'osx/LightAquaBlue/LightAquaBlue.xcodeproj',
        '-scheme', 'LightAquaBlue',
        'DSTROOT=' + os.path.join(os.getcwd(), 'osx'),
        'INSTALL_PATH=/',
        'DEPLOYMENT_LOCATION=YES',
    ])

这会在 osx/(这是 lightblue 包的目录)内构建 LightAquaBlue.framework,然后将其作为 package_data 传递给 setuptools。但是,当我运行 pip install --upgrade -v ./pybluez/ 时,LightAquaBlue.framework 没有被复制

creating build/lib/lightblue
copying osx/_bluetoothsockets.py -> build/lib/lightblue
copying osx/_LightAquaBlue.py -> build/lib/lightblue
copying osx/_obexcommon.py -> build/lib/lightblue
copying osx/_IOBluetoothUI.py -> build/lib/lightblue
copying osx/__init__.py -> build/lib/lightblue
copying osx/_IOBluetooth.py -> build/lib/lightblue
copying osx/_obex.py -> build/lib/lightblue
copying osx/_lightblue.py -> build/lib/lightblue
copying osx/obex.py -> build/lib/lightblue
copying osx/_macutil.py -> build/lib/lightblue
copying osx/_lightbluecommon.py -> build/lib/lightblue

如果我有 setup.py 在 osx/ 中创建一个虚拟文件,并将其添加到 package_data,它确实会被复制。这表明对我来说路径没有混淆。

如果我添加 os.system('ls osx/'),它还会显示 LightAquaBlue.framework 与我的虚拟文件位于同一位置。

    LightAquaBlue
--> LightAquaBlue.framework
    DUMMY_FILE_THAT_WORKS
    _IOBluetooth.py
    _IOBluetoothUI.py
    _LightAquaBlue.py
    __init__.py
    _bluetoothsockets.py
    _lightblue.py
    _lightbluecommon.py
    _macutil.py
    _obex.py
    _obexcommon.py
   obex.py

为什么没有正确复制框架?

【问题讨论】:

    标签: python setuptools


    【解决方案1】:

    它看起来像 setuptools 的文档 contradicts the implementation,实际上 您不能指定要包含在 package_data 中的目录

    不是很优雅,但是我用过:

    # We can't seem to list a directory as package_data, so we will
    # recursively add all all files we find
    package_data['lightblue'] = []
    for path, _, files in os.walk('osx/LightAquaBlue.framework'):
        for f in files:
            include = os.path.join(path, f)[4:]  # trim off osx/
            package_data['lightblue'].append(include)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-28
      • 2010-09-28
      • 2023-04-02
      • 2022-06-10
      • 1970-01-01
      • 1970-01-01
      • 2015-10-07
      • 2021-07-18
      相关资源
      最近更新 更多