python代码封装加密_python项目加密打包PyBuilder-exe

背景

最近东家要求源码保密,要求连除项目经理外的其他成员也只能看到自己负责的那部分源码,于是乎就只能将源码编译或制成库后引入项目,最后还要求项目打包制成可执行程序。为了方便使用,本人将其制成了包,源码地址。

简化python程序的打包,支持.py译成.so,保护源码

依赖

Cython: python源码编译

PyInstaller: python程序打包

Hooks

# build data将开始解析时

def hook_data(data: BuildData): ...

# 已解析出项目中excludes项时

def hook_excludes(target: typing.List[str], data: BuildData) -> typing.List[str]: ...

# 已解析出项目中ignores项时

def hook_ignores(target: typing.List[str], data: BuildData) -> typing.List[str]: ...

# 已解析出项目中的包路径项时

def hook_build_lib_path(target: typing.List[str], data: BuildData) -> typing.List[str]: ...

# 已解析出项目中的资源文件时

def hook_build_data(target: typing.List[typing.Tuple[str, str]],

data: BuildData) -> typing.List[typing.Tuple[str, str]]: ...

# 已解析出项目中的隐藏导入项时

def hook_build_imports(target: typing.List[str], data: BuildData) -> typing.List[str]: ...

# 将开始编译时

def hook_pre_compile(data: BuildData): ...

# 已编译完成时

def hook_compiled(data: BuildData): ...

# 将开始build时

def hook_pre_build(data: BuildData): ...

# 已build完成时

def hook_built(data: BuildData): ...

使用

具体使用可参照example

安装

pip install PyBuilder-exe

在python脚本中调用

from PyBuilder import run

# run函数定义

def run(name, target_file=‘‘, src_dir=‘‘, build_dir=‘‘, hook_file=‘‘, excludes_file=‘‘,

ignores_file=‘‘, single=_default_config.single, no_compile=_default_config.no_compile):

"""

打包

:param name: 打包后的程序名

:param target_file: 入口文件相对于`src_dir`的相对路径

:param src_dir: 源文件根目录路径,默认为运行环境的根目录路径

:param build_dir: build目录路径,默认为与运行环境的根目录同级的`builder`目录

:param hook_file: hook文件路径

:param excludes_file: `excludes`文件路径

:param ignores_file: `ignore`文件路径

:param single: 是否build为单文件程序,默认为False

:param no_compile: 是否不编译.py文件,默认为False

:return:

"""

...

命令行调用

PyBuilder -h

[PyBuilder-exe]Python build tools

optional arguments:

-h, --help show this help message and exit

-n NAME, --name NAME the execution name.

-tf TARGET_FILE, --target-file TARGET_FILE

the target file path relative the sources

dir.(default: main.py)

-sd SRC_DIR, --src-dir SRC_DIR

the sources dir path.

-bd BUILD_DIR, --build-dir BUILD_DIR

the build dir path.

-hf HOOK_FILE, --hook-file HOOK_FILE

the .py file of hook build.

-ef EXCLUDES_FILE, --excludes-file EXCLUDES_FILE

the excludes file path.

-if IGNORES_FILE, --ignores-file IGNORES_FILE

the ignores file path.

-F build a single file execution.(default: False)

-nc, --no-compile not compile, only build.(default: False)

注意

参考

原文:https://www.cnblogs.com/leocll/p/13041079.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值