23
from nuitka import Options
23
24
from nuitka.nodes.AssignNodes import StatementAssignmentVariable
25
from nuitka.nodes.AttributeNodes import ExpressionAttributeLookup
24
26
from nuitka.nodes.CallNodes import ExpressionCallNoKeywords
25
27
from nuitka.nodes.ConstantRefNodes import ExpressionConstantRef
28
from nuitka.nodes.ContainerMakingNodes import (
26
32
from nuitka.nodes.FutureSpecs import FutureSpec
27
33
from nuitka.nodes.ImportNodes import (
28
34
ExpressionImportModule,
35
ExpressionImportModuleHard,
29
36
ExpressionImportName
31
from nuitka.nodes.ModuleNodes import PythonPackage
38
from nuitka.nodes.ModuleNodes import (
39
ExpressionModuleFileAttributeRef,
32
42
from nuitka.nodes.VariableRefNodes import ExpressionTargetVariableRef
33
43
from nuitka.SourceCodeReferences import SourceCodeReference
44
from nuitka.utils import Utils
35
46
from .Helpers import makeStatementsSequenceFromStatement
36
47
from .VariableClosure import completeVariableClosures
50
def createPathAssignment(source_ref):
51
if Options.getFileReferenceMode() == "original":
52
path_value = ExpressionConstantRef(
54
Utils.dirname(source_ref.getFilename())
56
source_ref = source_ref,
60
path_value = ExpressionMakeList(
62
ExpressionCallNoKeywords(
63
called = ExpressionAttributeLookup(
64
source = ExpressionImportModuleHard(
67
source_ref = source_ref
69
attribute_name = "dirname",
70
source_ref = source_ref
72
args = ExpressionMakeTuple(
74
ExpressionModuleFileAttributeRef(
75
source_ref = source_ref,
78
source_ref = source_ref,
80
source_ref = source_ref,
83
source_ref = source_ref
86
return StatementAssignmentVariable(
87
variable_ref = ExpressionTargetVariableRef(
88
variable_name = "__path__",
89
source_ref = source_ref
92
source_ref = source_ref
95
def createPython3NamespacePath(package_name, module_relpath, source_ref):
96
return StatementAssignmentVariable(
97
variable_ref = ExpressionTargetVariableRef(
98
variable_name = "__path__",
99
source_ref = source_ref
101
source = ExpressionCallNoKeywords(
102
called = ExpressionImportName(
103
module = ExpressionImportModule(
104
module_name = "_frozen_importlib",
107
source_ref = source_ref
109
import_name = "_NamespacePath",
110
source_ref = source_ref
112
args = ExpressionConstantRef(
118
source_ref = source_ref
120
source_ref = source_ref
122
source_ref = source_ref
39
126
def createNamespacePackage(package_name, module_relpath):
40
127
parts = package_name.split('.')
53
140
source_ref = source_ref,
143
if Utils.python_version >= 300:
144
statement = createPython3NamespacePath(
145
package_name = package_name,
146
module_relpath = module_relpath,
147
source_ref = source_ref
150
statement = createPathAssignment(source_ref)
57
153
makeStatementsSequenceFromStatement(
59
StatementAssignmentVariable(
60
variable_ref = ExpressionTargetVariableRef(
61
variable_name = "__path__",
62
source_ref = source_ref
64
source = ExpressionCallNoKeywords(
65
called = ExpressionImportName(
66
module = ExpressionImportModule(
67
module_name = "_frozen_importlib",
70
source_ref = source_ref
72
import_name = "_NamespacePath",
73
source_ref = source_ref
75
args = ExpressionConstantRef(
81
source_ref = source_ref
83
source_ref = source_ref
85
source_ref = source_ref
154
statement = statement