4. Man

4.1. pyarmor init

In current path create project, update project and show project information

Syntax

[1] pyarmor init -h

[2] pyarmor init [-C] [-s PATH] [-x PATTERN] [-r {0,1,2,3}]

[3] pyarmor init [-e FILE] [-m FILE] [-p PATH]

[4] pyarmor init

Description

Option
-s PATH, --src PATH

Specify project src, absolute path or relative path

-x PATTERN, --exclude PATTERN

Exclude patterns when searching files in project src

It supports fnmatch wildcards

Use this option multiple times to exclude more

For example:

__pycache__
config.py
test_*.py
data*

If need exclude one package items, use package as prefix. For example:

pkgname:test_*.py
pkgname:config
-e FILE, --entry FILE

Add script to project, use this option multiple times for more scripts

It could be absolute path, or relative path. For example:

$ pyarmor init --src ../joker -e ../joker/card.py

Note that wildcard is allowable, but quote it. For example:

$ pyarmor init --src ../joker -e "../joker/*.py"

Project script should not be imported by any other moudles

-m FILE, --module FILE

Add module to project, use this option multiple times for more module

It’s almost same as -e, but project module could be imported by scripts or other modules

-p PATH, --package PATH

Add package to project, use this option multiple times for more packages

The package name is last path name. For example, add package joker to project:

$ pyarmor init -p lib/joker

If package name is different, use suffix @pkgname. For example:

$ pyarmor init -p lib/src@joker
-r, --recursive

Enable to search modules and packages in project src

-C, --clean

Remove all old project information before create new project

Usage

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

$ pyarmor init -r

If need exclude some files or paths:

$ pyarmor init -r --exclude venv --exclude "test*.py"

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

$ pyarmor init

Check all the files in the project:

$ pyarmor build --list

Re-create project in current path, only include one script:

$ pyarmor init -C -e foo.py

By -C, all the old project information are removed, otherwise, only update project

After project is created, use pyarmor env to update project

Examples

All of these examples assume there is still no project in work path

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

    $ pyarmor init -r
    
  2. Same as above, but not include path venv and all scripts which start with test:

    $ pyarmor init -r --exclude venv --exclude "test*.py"
    
  3. Update project src, -C is required to clean old project:

    $ pyarmor init -C --src another/src -r
    
  4. Create one project which src is not current path:

    $ pyarmor init -s eke/src -r
    
  5. Create one project with only one script:

    $ pyarmor init -e foo.py
    
  6. Create one project with only one module:

    $ pyarmor init -m fibo.py
    
  7. Create one project with one package joker which locates in the sub-folder`joker`:

    $ pyarmor init -p joker
    
  8. Create one project with one package joker which locates in the joker/src:

    $ pyarmor init -p joker/src@joker
    
  9. Create one project with many packages:

    $ pyarmor init -p mypkg -p lib/mypkg1 -p lib/mypkg2
    
  10. Create one project with script, module and package:

    $ pyarmor init -e main.py -m lib/*.py -p lib/mypkg
    

4.2. pyarmor env

Get or set Pyarmor configuration and project settings

There are 3 domains for this command:

  • global

  • local

  • project

Each doamin has many sections, each section has many options

For the same options, the priority is project domain > local domain > global domain

Refer to Configuration for all available options

Syntax

[5] pyarmor env -h

[6] pyarmor env [-l | -g | -p] info [NAME]

[7] pyarmor env [-l | -g | -p] get OPTION

[8] pyarmor env [-l | -g | -p] set OPTION VALUE

[9] pyarmor env [-l | -g | -p] reset OPTION

[10] pyarmor env [-l | -g | -p] [pop | push] OPTION VALUE …

[11] pyarmor env [-l | -g | -p]

Description

Options
-l, --local

Select local doamin:

$ pyarmor env -l
(local) ls
-g, --global

Select global domain:

$ pyarmor env -g
(global)
-p, --project

Select project doamin:

$ pyarmor env -p
(project)
info

Show available sections and options, and usage of options

For example, print all options and sections in project domain:

$ pyarmor env -p info

Sections:
rft

Options:
src  scripts  modules  packages  excludes  recursive

...

Show the usage of option excludes:

$ pyarmor env -p info excludes

Show all the options in section rft:

$ pyarmor env -p info rft

Show the usage of option argument_mode in the section rft:

$ pyarmor env -p info rft:argument_mode
get

Show option value. For example:

$ pyarmor env -p get excludes

OPTION may be format like SECTION:OPTION. For example:

$ pyarmor env -p get rft:argument_mode
set, reset

Change option value or restore default value. For example:

$ pyarmor env -p set recursive 1
$ pyarmor env -p set rft:argument_mode 0

$ pyarmor env -p reset recursive
$ pyarmor env -p reset rft:argument_mode
push, pop

Add or remove one item to value list of option

For example, add new pattern to project option excludes:

$ pyarmor env -p push excludes "test*.py"

Add many items in one command:

$ pyarmor env -p push excludes venv test

Quote special characaters. For example:

$ pyarmor env -p push excludes "test 2" "venv 2"

Remove one item:

$ pyarmor env -p pop excludes "test*.py"
Interactive Mode

If this command is executed without action options, it will enter interactive mode. For example:

$ pyarmor env -p
(project)

Type ? then press Enter, show all commands:

(project) ?
cd exit get help info ls pop push reset set use
(project)
Table-2. Interactive Commands

Action

Description

Examples

?

Show command help

Show usage of command ls:

(project) ? ls

use

Switch domain

Swith to global, then back to project:

(project) use global
(global) use project
(project)

ls

List all the options and sections in current scope

Check options and sections in project domain:

(project) ls
Sections:
rft

Options:
src  scripts  modules  packages  excludes  recursive

cd

Switch section

Enter section rft, then back to parent:

(project) cd rft
(project)[rft] cd ..
(project)

get

Show option value

Show project option scripts value:

(project) get scripts
scripts              = hanoi.py

Show all values of project options:

(project) get
src                  = /Users/zhaojunde/eksuite/src
scripts              = hanoi.py

set

Change option value

Set project option src to new path:

(project) set src /Users/zhaojunde/eksuite/src

reset

Restore option value to default

Remove project option src:

(project) reset src

push

Add one or more items to value list of option

Add foo.py and fibo.py to project scripts:

(project) push scripts foo.py fibo.py
(project) push scripts "foo.py" "fibo.py"

pop

Remove one item from value list of option

Remove script fibo.py from project:

(project) pop scripts fibo.py

info

Show option usage or available options

Show all sections and options in project domain:

(project) info

List all options in section rft:

(project) info rft

Show option argument_mode usage:

(project) cd rft
(project)[rft] info argument_mode

4.3. pyarmor build

Generate obfuscated scripts for project

Syntax

[12] pyarmor build -h

[13] pyarmor build [–mini | –rft | –mini-rft]

[14] pyarmor build [–autofix {0,1,2,3}]

[15] pyarmor build [–randname {0,1}]

Describition

--mini

Generate Mini Script for this project:

$ pyarmor build --mini
--rft

Generate RFT Script for this project:

$ pyarmor build --rft
--mini-rft

First refactor the scripts as RFT Script, then generate Mini Script for this project:

$ pyarmor build --mini-rft
--autofix {0,1,2,3}

This option can fix refactor issues for complex scripts, it support 3 modes - 1: simple way, but many attributes may not be renamed - 2: normal way, most attributes will be renamed, but sometimes need manually update the rules - 3: difficult way, it could rename attributes as many as possible (more than mode 2), need manually add most of rules

The basic steps are

  1. First start one autofix mode to generate rules. For example:

    $ pyarmor build --autofix 1
    
  2. Next build the script based on these rules:

    $ pyarmor build --rft
    
  3. Then test the result script:

    $ python dist/foo.py
    
  1. Fix rules .pyarmor/project/rft_autofix.rules by errors

  2. Loop from step 2, until no error

Refer to Refactor complex script by autofix mode <../../learn/en/commands.html#project-rft-autofix>

If need disable auto-fix mode, run this command:

$ pyarmor build --autofix 0

Then build project again:

$ pyarmor build --rft
--randname {0,1}

By default, the names in refactor script are prefix pyarmor__ with one serial number. For example:

pyarmor__1 = 1
pyarmor__2 = 'a'

If this option is enabled, the suffix will be random name. For example:

$ pyarmor build --randname 1
$ pyarmor build --rft
$ cat dist/foo.py

pyarmor20af2cdf6a = 1
pyarmor5688af382c = 'a'

If need disable random name mode, run this command:

$ pyarmor build --randname 0

Then build project again:

$ pyarmor build --rft