Skip to main content

Use Cython to compile Python code to binary and support git-diff to get changed files conveniently.

Project description

简体中文

Encrypt your Python project

Use Cython to compile Python code to binary and support git-diff to get changed files conveniently.

Installation

$ pip install encryptpy

Basic Usage

Usage: encryptpy [OPTIONS] COMMAND [ARGS]...

  Encrypt your Python code

Options:
  --config TEXT  The config file, ignore if given is invalid  [default:
                 .encryptpy.cfg]
  --help         Show this message and exit.

Commands:
  clean     Simply clean `build` and `__pycache__` directory in DIRS
  git-diff  Compile files between two COMMITS, see `git-diff`: `--name-only`
  init      Copy src to build-dir and do compile, usually used for the...
  run       Compile given Python code files

For the subcommand info, use encryptpy <subcommand> --help.

Examples

For example, there is a package named package_a (notice the work directory):

$ tree -a .

.
├── .encryptpy.cfg
└── package_a
    ├── __init__.py
    ├── main.py
    ├── README.md
    ├── setup.py
    └── utils.py

1 directory, 6 files

The .encryptpy.cfg's contents are as follow:

[encryptpy]
; Files will be compiled
paths =
    package_a
; Files will be ignored when compiling, support Regex
ignores =
    setup.py
; For command `init`, files will be ignored when copying, Glob-style
copy_ignores =
    *.pyc
    *.md
; The build directory
build_dir = build
; For commands `run` and `git-diff`, whether the source .py will be removed
clean_py = 0

1. Use in the first time

$ encryptpy init .

Look the build directory:

$ tree -a build

build
├── .encryptpy.cfg
└── package_a
    ├── __init__.cpython-38-x86_64-linux-gnu.so
    ├── main.cpython-38-x86_64-linux-gnu.so
    ├── setup.py
    └── utils.cpython-38-x86_64-linux-gnu.so

1 directory, 5 files

2. Use normally by run

$ encryptpy run package_a/main.py

The package_a/main.py will be recompiled to package_amain.cpython-38-x86_64-linux-gnu.so

3. Use normally by git-diff

$ encryptpy git-diff 0.1 0.2

The changed files between tag(or commit, or branch) 0.1 and 0.2 will be compiled.

Defect

The defects mainly come from Cython - some Python code can not be compiled correctly. Here are known issues:

  1. Assignment Expressions :=: Implement PEP 572: Assignment Expressions #2636

  2. @dataclass: Implement @dataclass for cdef classes #2903

  3. Class method decorators combination: Combining @staticmethod with other decorators is broken #1434

    e.g.

    class C:
        @staticmethod
        @some_decorator
        def f():
            pass
    

    but this can be rewrite to f = staticmethod(some_decorator(f)), it's ok.

If you have some code like the above, you can refactor or just ignore them, it is safe enough for most projects.

2022.08.10 UPDATE: It seems that the first two defects have been resolved.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

encryptpy-1.0.5.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

encryptpy-1.0.5-py3-none-any.whl (1.1 MB view details)

Uploaded Python 3

File details

Details for the file encryptpy-1.0.5.tar.gz.

File metadata

  • Download URL: encryptpy-1.0.5.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.6

File hashes

Hashes for encryptpy-1.0.5.tar.gz
Algorithm Hash digest
SHA256 33ef322974a574f84dbd76a3e02a8d2f2ab96823337f23aa16ab567d4e676c63
MD5 8f8f3c18f831f70040b1569228bb5b6a
BLAKE2b-256 9ac8ce3100b1e7f8cd8a00bc978b264934105faa1371ea395ba467a7260493dc

See more details on using hashes here.

Provenance

File details

Details for the file encryptpy-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: encryptpy-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.6

File hashes

Hashes for encryptpy-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 85e60db8f251d2d7e30b3cc868446e29247ce29e029c7af4f3f7a381ad65c843
MD5 7ec956b06b8fe7144e1e4be56c611ffd
BLAKE2b-256 853e95353fc9cc097f07b3dc2524f0d6217c69a465e5e999326a4d56439f4ccc

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page