File tree Expand file tree Collapse file tree 3 files changed +48
-0
lines changed
Expand file tree Collapse file tree 3 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ Options:
3030 -h, --help Show this message and exit.
3131
3232Commands:
33+ check Check to see if it can be encrypted
3334 decrypt Decrypt encrypted pye file
3435 encrypt Encrypt your python code
3536 generate Generate loader file using specified key
@@ -73,6 +74,17 @@ Options:
7374 -h, --help Show this message and exit.
7475` ` `
7576
77+ # ## Check
78+ ` ` ` shell
79+ ~ $ pyencrypt check -h
80+ Usage: cli.py check [OPTIONS] ENTRY
81+
82+ Check to see if it can be encrypted
83+
84+ Options:
85+ -h, --help Show this message and exit.
86+ ` ` `
87+
7688# # Example
7789# ## Encrypt
7890` ` ` shell
Original file line number Diff line number Diff line change 1+ from importlib import abc
2+ from importlib .machinery import ModuleSpec
3+ from typing import Sequence , Union
4+ import types
5+ from importlib ._bootstrap_external import _NamespacePath
6+ from pathlib import Path
7+ import os
8+
9+ _Path = Union [bytes , str ]
10+
11+
12+ class CheckFinder (abc .MetaPathFinder ):
13+ def find_spec (self , fullname : str , path : Sequence [_Path ],
14+ target : types .ModuleType = None ) -> ModuleSpec :
15+ if path :
16+ if isinstance (path , _NamespacePath ):
17+ file_path = Path (
18+ path ._path [0 ]) / f'{ fullname .rsplit ("." ,1 )[- 1 ]} .py'
19+ else :
20+ file_path = Path (path [0 ]) / f'{ fullname .rsplit ("." ,1 )[- 1 ]} .py'
21+ else :
22+ file_path = f'{ fullname } .py'
23+ if not os .path .exists (file_path ):
24+ return None
25+ return None
Original file line number Diff line number Diff line change @@ -167,5 +167,16 @@ def generate_loader(ctx, key):
167167 click .echo (FINISH_GENERATE_MSG )
168168
169169
170+ @cli .command (name = 'check' )
171+ @click .argument ('entry' , type = click .Path (exists = True ))
172+ @click .help_option ('-h' , '--help' )
173+ def check (entry ):
174+ """Check to see if it can be encrypted"""
175+ sys .path .insert (0 ,os .getcwd ())
176+ sys .meta_path .insert (0 ,CheckFinder ())
177+ entry = Path (entry ).as_posix ().rstrip ('.py' ).replace ('/' ,'.' )
178+ __import__ (entry )
179+
180+
170181if __name__ == '__main__' :
171182 cli ()
You can’t perform that action at this time.
0 commit comments