社区微信群开通啦,扫一扫抢先加入社区官方微信群
社区微信群
import os
import re
from distutils.core import Extension, setup
from Cython.Build import cythonize
from Cython.Compiler import Options
exclude_so = ['__init__.py', "setup.py"]
sources = ['./']
extensions = []
for source in sources:
for dirpath, foldernames, filenames in os.walk(source):
for filename in filter(lambda x: re.match(r'.*[.]py$', x), filenames):
print(filename)
file_path = os.path.join(dirpath, filename)
if filename not in exclude_so:
print("debug point ", file_path[:-3].replace('/', '.')[2:])
extensions.append(
Extension(file_path[:-3].replace('/', '.')[2:], [file_path], extra_compile_args = ["-Os", "-g0"],
extra_link_args = ["-Wl,--strip-all"]))
print("debug point 1")
Options.docstrings = False
compiler_directives = {'optimize.unpack_method_calls': False}
setup(
ext_modules = cythonize(extensions, exclude = None, nthreads = 20, quiet = True, build_dir = './build',
language_level = 3 , compiler_directives = compiler_directives))
#python setup.py build_ext --inplace
然后将文件夹下的非__init__.py的*.py 源码文件删除
图二中的ralbotgen.py的文件和图一中的同名文件不同,图二中的ralbotgen.py是整个项目的应用文件,里面会调用项目顶层文件中的类或者函数实现对应的功能,当然需要import相应的库。
```
from ralbotgen import ralbotGenerator
from ralbotgen import RDLMessagePrinter
if __name__ == "__main__":
ralbotGenerator(RDLMessagePrinter()).export()
```
如果需要从ubuntu移植到redhat,最好用源码重新执行build。
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!