Skip to content

Commit a071ad1

Browse files
committed
fix: 🐛 add ENCRYPT_SUFFIX for inspect.getmodulename
1 parent 7e08edb commit a071ad1

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

pyencrypt/loader.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import sys
33
import traceback
44
import types
5-
from importlib import abc
5+
from importlib import abc, machinery
66
from importlib._bootstrap_external import _NamespacePath
77
from importlib.machinery import ModuleSpec
88
from importlib.util import spec_from_loader
@@ -21,6 +21,9 @@ def __dir__(self) -> Iterable[str]:
2121
return []
2222

2323

24+
ENCRYPT_SUFFIX = ".pye"
25+
26+
2427
class EncryptFileLoader(abc.SourceLoader, Base):
2528
POSSIBLE_PATH = [
2629
Path(os.path.expanduser("~")) / ".licenses" / "license.lic",
@@ -79,12 +82,17 @@ def find_spec(
7982
) -> ModuleSpec:
8083
if path:
8184
if isinstance(path, _NamespacePath):
82-
file_path = Path(path._path[0]) / f'{fullname.rsplit(".", 1)[-1]}.pye'
85+
file_path = (
86+
Path(path._path[0])
87+
/ f'{fullname.rsplit(".", 1)[-1]}{ENCRYPT_SUFFIX}'
88+
)
8389
else:
84-
file_path = Path(path[0]) / f'{fullname.rsplit(".", 1)[-1]}.pye'
90+
file_path = (
91+
Path(path[0]) / f'{fullname.rsplit(".", 1)[-1]}{ENCRYPT_SUFFIX}'
92+
)
8593
else:
8694
for p in sys.path:
87-
file_path = Path(p) / f"{fullname}.pye"
95+
file_path = Path(p) / f"{fullname}{ENCRYPT_SUFFIX}"
8896
if file_path.exists():
8997
break
9098
file_path = file_path.absolute().as_posix()
@@ -99,4 +107,5 @@ def invalidate_caches(cls):
99107

100108

101109
# TODO: generate randomly AES Class
110+
machinery.EXTENSION_SUFFIXES.append(ENCRYPT_SUFFIX)
102111
sys.meta_path.insert(0, EncryptFileFinder)

0 commit comments

Comments
 (0)