Skip to content

Commit d269272

Browse files
committed
Refine sample script
1 parent d8f3dee commit d269272

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

docs/how-to/ci.rst

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -92,40 +92,42 @@
9292

9393
.. versionadded:: 9.2.0
9494

95-
如果一次构建使用了多个 `pyarmor gen` 命令,那么尝试使用下面的方式批量执行多个 `pyarmor gen`
95+
如果一次构建使用了多个 `pyarmor gen` 命令,可以合并多个命令到一个,例如::
9696

97-
首先,创建一个脚本 `batch.py` ,例如
97+
# 原来使用三个 pyarmor gen
98+
pyarmor gen -R /path/to/package1
99+
pyarmor gen -R /path/to/package2
100+
pyarmor gen -R /path/to/package3
101+
102+
# 可以合并成为一个
103+
pyarmor gen -R /path/to/package1 /path/to/package2 /path/to/package2
104+
105+
或者使用一个 Python 脚本,在同一个进程当中执行所有的 `pyarmor gen`
106+
107+
例如,创建一个脚本 `batch.py`:
98108

99109
.. code-block:: python
100110
101-
import shlex
102111
import os
112+
import shlex
103113
104114
from pyarmor.cli.__main__ import main_entry as pyarmor_run
105115
106-
# Do not run `pyarmor reg pyarmor-ci-xxxx.zip` here, run it before this script
107-
108-
build_commands = """
109-
pyarmor gen main.py
110-
cd ../package1
111-
pyarmor gen -R --enable-bcc src/
112-
cd ../package2
113-
pyarmor gen -R --enable-jit --private src/
114-
"""
115-
116-
for cmd in build_commands.splitlines():
117-
if cmd.startswith('#'):
118-
continue
119-
120-
if cmd.startswith('cd '):
121-
path = cmd[3:].strip()
122-
print('Change current path:', path)
123-
os.chdir(path)
124-
125-
elif cmd.startswith('pyarmor '):
126-
print('Execute: ', cmd)
127-
args = shlex.split(cmd[8:].strip())
128-
pyarmor_run(args)
116+
# 不要在脚本中运行 `pyarmor reg pyarmor-ci-xxxx.zip`
117+
118+
# 使用下面的方式等价运行命令 pyarmor gen -R /path/to/package1
119+
pyarmor_run(['gen', '-R', '/path/to/package1'])
120+
121+
# 或者这种形式,更接近原来的命令
122+
cmdlist = shlex.split("pyarmor gen -R /path/to/package2")
123+
pyarmor_run(cmdlist[1:])
124+
125+
# 切换当前路径
126+
os.chdir('/path/to/other')
127+
128+
# 执行其它命令
129+
cmdlist = shlex.split("pyarmor gen key -e 30")
130+
pyarmor_run(cmdlist[1:])
129131
130132
然后在工作流中使用下面的方法调用::
131133

0 commit comments

Comments
 (0)