基于@hoefling的回答,我能够打包resource_folder并混淆了二进制a.so文件。
setup.py的配方
from Cython.Distutils import build_extfrom Cython.Build import cythonizefrom setuptools.extension import Extensionfrom setuptools.command.build_py import build_py as build_py_origfrom pathlib import Pathfrom setuptools import find_packages, setup, Commandimport osimport shutilhere = os.path.abspath(os.path.dirname(__file__)) packages = find_packages(exclude=('tests',))def get_package_files_in_directory(directory): paths = [] for (path, directories, filenames) in os.walk(directory): for filename in filenames: paths.append(os.path.join('..', path, filename)) return paths#to copy the __init__.py as specified in above references linksclass MyBuildExt(build_ext): def run(self): build_ext.run(self) build_dir = Path(self.build_lib) root_dir = Path(__file__).parent target_dir = build_dir if not self.inplace else root_dir self.copy_file(Path('main_folder') / '__init__.py', root_dir, target_dir) def copy_file(self, path, source_dir, destination_dir): if not (source_dir / path).exists(): return shutil.copyfile(str(source_dir / path), str(destination_dir / path))#as specified by @hoefling to ignore .py and not resource_folderclass build_py(build_py_orig): def build_packages(self): passsetup( packages=find_packages(), # needed for obfuscation ext_modules=cythonize( [Extension("main_folder.*", ["main_folder/*.py"]) ], build_dir="build", compiler_directives=dict( always_allow_keywords=True )), package_data={p: get_package_files_in_directory(os.path.join(here, p, 'resource_folder')) for p in packages}, #package_data as found in another reference cmdclass={ 'build_py': build_py }, entry_points={ },)
创建混淆的* .whl软件包命令集
python setup.py build_ext #creates the a.sopython setup.py build_py #copies the resource_folder excluding .pypython setup.py bdist_wheel # then whl generation
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)