1
# Copyright 2015, Kay Hayen, mailto:kay.hayen@gmail.com
3
# Part of "Nuitka", an optimizing Python compiler that is compatible and
4
# integrates with CPython, but also works on its own.
6
# Licensed under the Apache License, Version 2.0 (the "License");
7
# you may not use this file except in compliance with the License.
8
# You may obtain a copy of the License at
10
# http://www.apache.org/licenses/LICENSE-2.0
12
# Unless required by applicable law or agreed to in writing, software
13
# distributed under the License is distributed on an "AS IS" BASIS,
14
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
# See the License for the specific language governing permissions and
16
# limitations under the License.
20
This is not about caching the search of modules in the file system, but about
21
maintaining a cache of module trees built.
23
It can happen that modules become unused, and then dropped from active modules,
24
and then later active again, via another import, and in this case, we should
28
from logging import warning
30
from nuitka import Utils
35
def addImportedModule(module_relpath, imported_module):
36
if (module_relpath, "__main__") in imported_modules:
38
Re-importing __main__ module via its filename duplicates the module.""")
40
key = module_relpath, imported_module.getFullName()
42
if key in imported_modules:
43
assert imported_module is imported_modules[ key ], key
45
imported_modules[ key ] = imported_module
46
imported_by_name[ imported_module.getFullName() ] = imported_module
48
def isImportedModuleByPath(module_relpath):
49
module_name = Utils.basename(module_relpath)
51
if module_name.endswith(".py"):
52
module_name = module_name[:-3]
54
key = module_relpath, module_name
56
return key in imported_modules
58
def isImportedModuleByName(full_name):
59
return full_name in imported_by_name
61
def getImportedModuleByName(full_name):
62
return imported_by_name[ full_name ]
64
def getImportedModuleByPath(module_relpath):
65
module_name = Utils.basename(module_relpath)
67
if module_name.endswith(".py"):
68
module_name = module_name[:-3]
70
key = module_relpath, module_name
72
return imported_modules[ key ]