微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Python的“ setuptools”不包含自动生成的SWIG Python文件 ./ README.md 文件 ./ setup.py 文件 ./ swig_example / example.c 文件 ./ swig_example / example.h 文件 ./ swig_example / example.swig 文件 ./ swig_example / init .py 文件 ./ swig_example / example_wrap.c 自动生

如何解决Python的“ setuptools”不包含自动生成的SWIG Python文件 ./ README.md 文件 ./ setup.py 文件 ./ swig_example / example.c 文件 ./ swig_example / example.h 文件 ./ swig_example / example.swig 文件 ./ swig_example / init .py 文件 ./ swig_example / example_wrap.c 自动生

背景

由于我的Python应用程序中的性能原因,我最终将尝试使用C语言编写几个函数,以将整数与VLQ二进制字符串表示形式进行转换。由于我不想处理实现细节,并且由于该应用程序的目标是标准CPython解释器,因此我现在决定使用SWIG包装器生成器,并一直在尝试使用Python打包“ setuptools”,以便自动编译并捆绑示例函数(简单地将数字加1)。

问题

我已经尝试了太长时间了,以至于无法正确地写入我的“ setup.py”文件,以至于它A)编译了相关的C源代码,B)也包括自动生成的Python包装器组件。我能够完成“ A”操作,但不能完成“ B”操作(我一直在检查生成的车轮文件以进行检查)。

尝试的解决方

我尝试阅读'setuptools'文档并检查其源代码包括软件包'distutils'的源代码),并尝试读取Stack Overflow上其他用户的输入,并尝试从中检查各种示例软件包GitHub。如果我现在能解决这个问题,我会解决

可接受的解决方

这基本上只是我的头疼。因此,从最具体的解决方案到最不具体的解决方案依次解决了我的问题:

  • 修复“ setup.py”文件或项目配置/布局的其他方面,使其包含相关的Python源代码(我希望能够在没有“ MANIFEST.in”或二进制文件的情况下进行此操作-数据文件包含黑客)
  • 找到一个仍可与cpython和'pip'一起使用的替代Python打包工具
  • 编译C代码示例并以其他方式创建仍与cpython和'pip'兼容的相关包(例如,使用GNU'make',我非常满意)

其他

我不认为我现在将头文件'example.h'包含在源代码发行版中,因此,我希望能在解决该问题以及修复您可能遇到的其他所有错误方面提供帮助找到。

配置和代码

相关文件

./ README.md

# Greetings programs!!!

Don't panic!

I am primarily using this example package to test my ability to create compiled C code extensions for the Python interpreter via the SWIG mechanism. I will also be using this package to test that I can,ultimately,access the contents of a package of this sort from within 'python' itself on my computer.

# License

Anything contained within this package is licensed under [WTFPL][4] where applicable (though,obvIoUsly,you may not use my username and email without my permission). If there are any files contained within this project that I,Mr. Minty Fresh,do not have copyright control over,then said files' copyright statuses belong to each respective owner(s) (this may or may not include some files automatically generated by SWIG).

文件 ./ setup.py

#!/usr/bin/env python3

import os
import setuptools
from setuptools import Extension,Command,find_packages
from setuptools.command.build_ext import build_ext
from distutils.command.clean import clean


class build_swig(build_ext):
    """Use SWIG on some files within the 'swig_example/' directory."""
    def run(self):
        print("building SWIG interface")
        os.system("swig -python ./swig_example/example.swig")
        super().run()

class clean_swig(clean):
    """Cleanup all files generated by SWIG in the 'swig_example/' directory."""
    def run(self):
        print("removing temporary SWIG files")
        os.system("rm -f ./swig_example/example_wrap.c")
        os.system("rm -f ./swig_example/example.py")
        print("removing dist-ish files")
        os.system("rm -rf ./dist/")
        os.system("rm -rf ./*.egg-info/")
        super().run()

class noop(Command):
    """Do absolutely nothing (successfully)!"""
    user_options = []
    def initialize_options(self): pass
    def finalize_options(self): pass
    def run(self): pass
noop.description = noop.__doc__


with open("README.md","r") as fh:
    long_description = fh.read()

setuptools.setup(
    name = "example-pkg-mrmintyfresh",version = "0.0.1",author = "mrmintyfresh",author_email = "mrmintyfresh@example.com",description = "Sample SWIG usage package.",long_description = long_description,url = "https://www.example.com/",ext_modules = [
        Extension("_example",["./swig_example/example_wrap.c","./swig_example/example.c"]),],cmdclass = {
        "build_ext": build_swig,"clean": clean_swig,"noop": noop,},packages = find_packages("./swig_example/"),python_requires = ">=3.0",)

文件 ./ swig_example / example.c

#include "example.h"

int increment(int x){
    return ++x;
}

文件 ./ swig_example / example.h

#ifndef EXAMPLE_H
#define EXAMPLE_H

    extern int increment(int x);

#endif /* EXAMPLE_H */

文件 ./ swig_example / example.swig

%module example

%{
#include "example.h"
%}

%include "example.h"

文件 ./ swig_example / init .py

(空文件

文件 ./ swig_example / example_wrap.c 自动生成

(为简洁起见,省略了

文件 ./ swig_example / example.py 自动生成

(为简洁起见,省略)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。