Skip to content

Commit 72378d6

Browse files
committed
Refine options
1 parent dc800b1 commit 72378d6

File tree

10 files changed

+188
-68
lines changed

10 files changed

+188
-68
lines changed

pyarmor/docs/en/user/configuration.rst

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
=======================
2-
Configuration Options
3-
=======================
1+
===============
2+
Configuration
3+
===============
44

55
.. contents:: Content
66
:depth: 2
@@ -11,6 +11,8 @@
1111

1212
Bool value is 0, 1
1313

14+
Project configuration is stored in the :file:`.pyarmor/config`
15+
1416
Project Domain
1517
==============
1618

@@ -85,8 +87,27 @@ Set option value. For example::
8587
joker:data
8688
:find.py
8789
* - recursive
88-
- Bool
89-
- Recursively search modules and packages in project src
90+
- Enum
91+
- How to search items in project src
92+
- 0: no search
93+
- 1: only search modules
94+
- 2: search modules and packages
95+
- 3: recursively search all modules and packages
96+
* - pypaths
97+
- List
98+
- Extra Python paths to import module on demand::
99+
100+
path
101+
path,path
102+
modname::path,path
103+
104+
Used by wildcard import or outer base classes. For examle::
105+
106+
import a
107+
from b import *
108+
109+
class C(a.T):
110+
pass
90111

91112
Section: rft
92113
------------
@@ -132,7 +153,7 @@ Set option value. For example::
132153
- 1: only rename position-only arguments
133154
- 2: rename all the arguments except keyword-only arguments
134155
- 3: rename all the arguments
135-
* - auto_export_mode
156+
* - export_mode
136157
- Bool
137158
- 0
138159
- Export all the names list in the module attribute `__all__`
@@ -147,6 +168,8 @@ Set option value. For example::
147168

148169
"inc"
149170
"dir*"
171+
"modname::generic_visit"
172+
"modname::Cls.visit_*"
150173

151174
Note that arguments and local variables are always renamed
152175
* - exclude_funcs
@@ -163,6 +186,27 @@ Set option value. For example::
163186
- List
164187
-
165188
- Define how to rename unknown attributes
189+
190+
One rule one line. For example::
191+
192+
modname::scope:a.b.c
193+
!modname::scope:a.b.c
194+
modname::scope:a.b.c *.?.?
195+
196+
The first line will rename all attributes `b.c`, on the contrary the second form won't
197+
198+
The third form only renames attribute by action `?`
199+
* - call_rules
200+
- List
201+
-
202+
- Define keywords in which function call should be renamed::
203+
204+
foo
205+
visit*
206+
modname::foo
207+
modname:::foo*
208+
modname::Cls.meth:foo
209+
166210
* - extra_builtins
167211
- List
168212
-
@@ -171,3 +215,7 @@ Set option value. For example::
171215
- List
172216
-
173217
- Classes aren't defined in the project
218+
* - external_attrs
219+
- List
220+
-
221+
- Outer attributes should not be renamed

pyarmor/docs/en/user/man.rst

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ In current path create project, update project and show project information
2020

2121
[#]_ pyarmor init -h
2222

23-
[#]_ pyarmor init [-C] [-s PATH] [-x PATTERN]
23+
[#]_ pyarmor init [-C] [-s PATH] [-x PATTERN] [-r {0,1,2,3}]
2424

2525
[#]_ pyarmor init [-e FILE] [-m FILE] [-p PATH]
2626

@@ -37,11 +37,7 @@ In current path create project, update project and show project information
3737

3838
.. option:: -s PATH, --src PATH
3939

40-
Project path, absolute path
41-
42-
If no :option:`-e`, :option:`-m`, :option:`-p`, all the modules and packages in this path will be added into this project
43-
44-
Otherwise, project only includes listed scripts, modules and packages
40+
Specify project src, absolute path or relative path
4541

4642
.. option:: -x PATTERN, --exclude PATTERN
4743

@@ -95,6 +91,15 @@ In current path create project, update project and show project information
9591

9692
$ pyarmor init -p lib/src@joker
9793

94+
.. option:: -r, --recursive {0,1,2,3}
95+
96+
How to search items in project src
97+
98+
- 0: no search
99+
- 1: only search modules
100+
- 2: search modules and packages
101+
- 3: recursively search all modules and packages
102+
98103
.. option:: -C, --clean
99104

100105
Remove all old project information before create new project
@@ -103,17 +108,11 @@ In current path create project, update project and show project information
103108

104109
Create one project, add all scripts and packages in the current path to this project::
105110

106-
$ pyarmor init
107-
108-
This command is same as::
109-
110-
$ pyarmor init --src . -m "*.py" -p "*"
111-
112-
Quote wildcards in command line, otherwise may complain of syntax errors
111+
$ pyarmor init -r 2
113112

114113
If need exclude some files or paths::
115114

116-
$ pyarmor init --exclude venv --exclude "test*.py"
115+
$ pyarmor init -r 2 --exclude venv --exclude "test*.py"
117116

118117
If there has project in current path, this command could show project information::
119118

@@ -137,19 +136,19 @@ All of these examples assume there is still no project in work path
137136

138137
1. Create one project which include all the scripts and packages in current path::
139138

140-
$ pyarmor init
139+
$ pyarmor init -r 3
141140

142141
2. Same as above, but not include path `venv` and all scripts which start with `test`::
143142

144-
$ pyarmor init --exclude venv --exclude "test*.py"
143+
$ pyarmor init -r 3 --exclude venv --exclude "test*.py"
145144

146145
3. Update project src, :option:`-C` is required to clean old project::
147146

148-
$ pyarmor init -C --src another/src
147+
$ pyarmor init -C --src another/src -r 3
149148

150149
4. Create one project which src is not current path::
151150

152-
$ pyarmor init -s eke/src
151+
$ pyarmor init -s eke/src -r 2
153152

154153
5. Create one project with only one script::
155154

@@ -421,7 +420,7 @@ Generate obfuscated scripts for project
421420

422421
[#]_ pyarmor build [--mini | --rft | --mini-rft]
423422

424-
[#]_ pyarmor build [--autofix {0,1}]
423+
[#]_ pyarmor build [--autofix {0,1,2,3}]
425424

426425
[#]_ pyarmor build [--randname {0,1}]
427426

@@ -450,19 +449,14 @@ Generate obfuscated scripts for project
450449

451450
$ pyarmor build --mini-rft
452451

453-
.. option:: --autofix {0,1}
452+
.. option:: --autofix {0,1,2,3}
454453

455454
This option can simplifying the configuration for refactoring scripts.
456455

457456
First enable auto-fix mode by this way::
458457

459458
$ pyarmor build --autofix 1
460459

461-
When auto-fix mode is enabled
462-
463-
- Always `argument_mode = 1`
464-
- Search all unknown attributes and add them to exclude table
465-
466460
Then build the project::
467461

468462
$ pyarmor build --rft

pyarmor/docs/en/user/tutorials.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ First create one project with package `tomjson`::
155155

156156
Because the package will be imported by outer scripts, the exported classes and functions can't be renamed
157157

158-
In order to keep these names, one way is to enable option `auto_export_mode`::
158+
In order to keep these names, one way is to enable option `export_mode`::
159159

160-
$ pyarmor env -p set rft:auto_export_mode 1
160+
$ pyarmor env -p set rft:export_mode 1
161161

162162
Thus all the names list in the module attribute ``__all__`` aren't changed, and
163163

@@ -175,9 +175,9 @@ Create Complex Project
175175

176176
Let's create one comple project, include one script `jsontool.py` and package `tomjson`, but no `fibo.py` and path `venv`::
177177

178-
$ pyarmor init --clean --src . --exclude fibo.py --exclude venv
178+
$ pyarmor init --clean --src . -r 2 --exclude fibo.py --exclude venv
179179

180-
Because there is no :option:`--entry`, :option:`--module` and :option:`--package`, so pyarmor will search all the files and paths in the :option:`--src`, all of them except in the excludes will be added into the project.
180+
Pyarmor will search all the files and paths in the :option:`--src`, all of them except in the excludes will be added into the project.
181181

182182
Check the project items::
183183

pyarmor/docs/zh/user/configuration.rst

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
.. highlight:: console
1111

12+
配置选项存放在文件 `.pyarmor/config` 中
13+
1214
布尔类型的值为 0, 1
1315

1416
工程域
@@ -40,6 +42,8 @@
4042
- 文件列表
4143
- 工程的脚本,可以为空,也可以是一个或者多个文件
4244

45+
脚本一般是不会被工程中其他脚本和模块导入,是直接被执行的文件
46+
4347
文件是相对于 src 的路径或者绝对路径,可以包含通配符,例如::
4448

4549
foo.py
@@ -86,7 +90,26 @@
8690
:find.py
8791
* - recursive
8892
- 布尔
89-
- 是否递归搜索工程源路径
93+
- 搜索工程路径下的模块和包的模式
94+
- 0 不搜索
95+
- 1 只搜索工程目录下的模块
96+
- 2 只搜索工程目录下的模块和包
97+
- 3 递归搜索工程目录下面的所有的模块和包
98+
* - pypaths
99+
- 列表
100+
- 指定动态导入模块时候的额外路径,支持的格式::
101+
102+
path
103+
path,path
104+
modname::path,path
105+
106+
主要用于重构的时候需要导入基类,以及获取 wildcard 导入的名称::
107+
108+
import a
109+
from b import *
110+
111+
class C(a.T):
112+
pass
90113

91114
.. _rft-section:
92115

@@ -134,7 +157,7 @@ rft
134157
- 1: 仅重命名 posonly 参数
135158
- 2: 仅保留 kwonly 的参数名称,其他都重命名
136159
- 3: 重命名所有函数的参数(默认值)
137-
* - auto_export_mode
160+
* - export_mode
138161
- 布尔
139162
- 0
140163
- 是否输出模块属性 `__all__` 中列出的名称
@@ -157,6 +180,8 @@ rft
157180

158181
"inc"
159182
"dir*"
183+
"modname::generic_visit"
184+
"modname::Cls.visit_*"
160185

161186
参数和局部变量总是会被重命名,这里列出的名称对参数和局部变量不起作用
162187
* - exclude_funcs
@@ -167,20 +192,59 @@ rft
167192
"func"
168193
"modname::func"
169194
"modname::cls.method"
170-
171195
* - attr_rules
172196
- 模式列表
173197
-
174198
- 处理未知类型的属性的时候,自定义重命名规则
199+
200+
一个规则占一行,支持如下格式::
201+
202+
modname::scope:a.b.c
203+
!modname::scope:a.b.c
204+
modname::scope:a.b.c *.?.?
205+
206+
第一种格式所有的属性都重命名,第二种格式正好相反,所有的属性都不重命名
207+
208+
第三种格式是指定需要重命名的属性, `?` 对应的属性重命名
209+
* - call_rules
210+
- 模式列表
211+
-
212+
- 处理函数调用的时候,重命名匹配函数的关键字参数
213+
214+
支持的格式为函数名称,或者指定模块和范围,例如::
215+
216+
foo
217+
visit*
218+
modname::foo
219+
modname:::foo*
220+
modname::Cls.meth:foo
221+
175222
* - extra_builtins
176223
- 名称列表
177224
-
178225
- 除了 builtins 模块之外,需要作为内置名称进行处理的额外名称
226+
227+
支持的格式为空格分开的名称,可以多行
179228
* - external_types
180229
- 外部类列表
181230
-
182231
- 处理未知类型的属性的时候,自动排除外部类的属性
183232

233+
支持的格式::
234+
modname
235+
modname::*
236+
modname::Cls
237+
modname::Cls*
238+
239+
只有模块名称则模块中所有的类的属性都会被排除
240+
* - external_attrs
241+
- 外部属性表
242+
-
243+
- 处理未知类型的属性的时候,自动排除这里列出的属性
244+
245+
支持的格式为空格分开的名称,可以多行,不支持通配符
246+
247+
184248
..
185249
* - var_type_table
186250
- 列表

0 commit comments

Comments
 (0)