Skip to content

Commit

Permalink
perf: ⚡️ change find_spec -> classmethod
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhaoQi99 committed Nov 5, 2024
1 parent 32db20c commit 7e08edb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 0 additions & 2 deletions pyencrypt/encrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions pyencrypt/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -92,6 +93,10 @@ def find_spec(
loader = EncryptFileLoader(file_path)
return spec_from_loader(name=fullname, loader=loader, origin="origin-encrypt")

@classmethod
def invalidate_caches(cls):
pass


# TODO: generate randomly AES Class
sys.meta_path.insert(0, EncryptFileFinder())
sys.meta_path.insert(0, EncryptFileFinder)
1 change: 0 additions & 1 deletion tests/test_encrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def test_encrypt_key(key):
[
(Path("__init__.py"), False),
(Path("pyencrypt/__init__.py"), False),
(Path("management/commands/user.py"), False),
(Path("tests/test.pye"), False),
(Path("tests/test_encrypt.py"), True),
],
Expand Down

0 comments on commit 7e08edb

Please sign in to comment.