Skip to content

Commit 7e08edb

Browse files
committed
perf: ⚡️ change find_spec -> classmethod
1 parent 32db20c commit 7e08edb

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

pyencrypt/encrypt.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ def _encrypt_file(
3333
def can_encrypt(path: Path) -> bool:
3434
if path.name in NOT_ALLOWED_ENCRYPT_FILES:
3535
return False
36-
if "management/commands/" in path.as_posix():
37-
return False
3836
if path.suffix != ".py":
3937
return False
4038
return True

pyencrypt/loader.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ def get_data(self, path: _Path) -> bytes:
7373

7474

7575
class EncryptFileFinder(abc.MetaPathFinder, Base):
76+
@classmethod
7677
def find_spec(
77-
self, fullname: str, path: Sequence[_Path], target: types.ModuleType = None
78+
cls, fullname: str, path: Sequence[_Path], target: types.ModuleType = None
7879
) -> ModuleSpec:
7980
if path:
8081
if isinstance(path, _NamespacePath):
@@ -92,6 +93,10 @@ def find_spec(
9293
loader = EncryptFileLoader(file_path)
9394
return spec_from_loader(name=fullname, loader=loader, origin="origin-encrypt")
9495

96+
@classmethod
97+
def invalidate_caches(cls):
98+
pass
99+
95100

96101
# TODO: generate randomly AES Class
97-
sys.meta_path.insert(0, EncryptFileFinder())
102+
sys.meta_path.insert(0, EncryptFileFinder)

tests/test_encrypt.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def test_encrypt_key(key):
2929
[
3030
(Path("__init__.py"), False),
3131
(Path("pyencrypt/__init__.py"), False),
32-
(Path("management/commands/user.py"), False),
3332
(Path("tests/test.pye"), False),
3433
(Path("tests/test_encrypt.py"), True),
3534
],

0 commit comments

Comments
 (0)