Repository navigation
Expand file tree
/
Copy pathruntime.py
More file actions
66 lines (57 loc) · 2.4 KB
/
Copy pathruntime.py
File metadata and controls
66 lines (57 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
#############################################################
# #
# Copyright @ 2023 - Dashingsoft corp. #
# All rights reserved. #
# #
# Pyarmor #
# #
# Version: 8.2.4 - #
# #
#############################################################
#
#
# @File: pyarmor/core/runtime.py
#
# @Author: Jondy Zhao (pyarmor@163.com)
#
# @Create Date: Tue Jun 6 07:50:00 CST 2023
#
from . import map_platform
class PyarmorRuntime(object):
@staticmethod
def get(plat, extra=None, native=True):
from os import scandir, path as os_path
prefix = 'pyarmor_runtime'
extlist = 'so', 'pyd', 'dylib', 'dll'
# Themida is only available for windows
if extra == 'themida' and not plat.startswith('windows'):
extra = None
pkgpath = os_path.dirname(__file__)
if native and not extra:
path = pkgpath
for entry in scandir(path):
parts = entry.name.split('.')
if parts[0] == prefix and parts[-1] in extlist:
return entry.name, os_path.abspath(entry.path)
platname = map_platform(plat)
dirnames = platname.split('.')
path = os_path.join(pkgpath, extra if extra else '', *dirnames)
if not os_path.exists(path):
from pyarmor.cli.bootstrap import check_prebuilt_runtime_library
check_prebuilt_runtime_library([platname], extra)
if os_path.exists(path):
for entry in scandir(path):
parts = entry.name.split('.')
if parts[0] == prefix and parts[-1] in extlist:
return entry.name, os_path.abspath(entry.path)
# Fallback to pyarmor.cli.runtime
try:
from pyarmor.cli.runtime import PyarmorRuntime, __VERSION__ as ver
from logging import getLogger
getLogger('cli').info('fallback to pyarmor.cli.runtime==%s', ver)
return PyarmorRuntime.get(plat, extra=extra)
except ModuleNotFoundError:
pass