From e5184e0d47465d448e6bcab388cee8de5ddb2f0f Mon Sep 17 00:00:00 2001 From: Qi Zhao Date: Tue, 5 Nov 2024 17:07:43 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E2=9A=A1=EF=B8=8F=20change=20`find=5Fs?= =?UTF-8?q?pec`=20->=20classmethod?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyencrypt/encrypt.py | 2 -- pyencrypt/loader.py | 5 +++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/pyencrypt/encrypt.py b/pyencrypt/encrypt.py index 2d58a70..1ee4534 100644 --- a/pyencrypt/encrypt.py +++ b/pyencrypt/encrypt.py @@ -33,8 +33,6 @@ def _encrypt_file( def can_encrypt(path: Path) -> bool: if path.name in NOT_ALLOWED_ENCRYPT_FILES: return False - if "management/commands/" in path.as_posix(): - return False if path.suffix != ".py": return False return True diff --git a/pyencrypt/loader.py b/pyencrypt/loader.py index 069010e..597078b 100644 --- a/pyencrypt/loader.py +++ b/pyencrypt/loader.py @@ -73,8 +73,9 @@ def get_data(self, path: _Path) -> bytes: class EncryptFileFinder(abc.MetaPathFinder, Base): + @classmethod def find_spec( - self, fullname: str, path: Sequence[_Path], target: types.ModuleType = None + cls, fullname: str, path: Sequence[_Path], target: types.ModuleType = None ) -> ModuleSpec: if path: if isinstance(path, _NamespacePath): @@ -94,4 +95,4 @@ def find_spec( # TODO: generate randomly AES Class -sys.meta_path.insert(0, EncryptFileFinder()) +sys.meta_path.insert(0, EncryptFileFinder)