TL;DR
[^ 1]: Exactly on Maya's Python interpreter. [^ 2]: Censored.
firstimport_hook.py
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import __builtin__
import types
import copy
import sys
import inspect
# reload()For countermeasures__import__Store after confirming that is Builtin Function.
if isinstance(__import__, types.BuiltinFunctionType):
_original__import__ = copy.deepcopy(__import__)
#For example, if it is imported hooked by another module,
# _original__import__Can not be defined, so throw an error appropriately
elif '_original__import__' not in globals():
raise ImportError('Definition of _original__import__ failed.')
def __get_modulefile_from_load_module():
try:
#Get the module file to read from
currentframe = inspect.currentframe()
module_file = currentframe.f_back.f_back.f_code.co_filename
finally:
#Del to correct the reference count.
del currentframe
return module_file
def print_modulefile_post_first_import(*args, **kwargs):
"""View module files after initial import"""
#Get module loading status before importing
loaded_module_names = sys.modules.keys()
# __import__Run
module = _original__import__(*args, **kwargs)
#Do not process modules that have already been loaded
if module.__name__ in loaded_module_names:
return module
# __file__Do not show the path of modules that do not have
filepath = getattr(module, '__file__', None)
if filepath:
path_from_load_module = __get_modulefile_from_load_module()
print('%s -> %s' % (path_from_load_module, filepath))
return module
def enable_import_hook():
"""Enable import hooks"""
__builtin__.__import__ = print_modulefile_post_first_import
def disable_import_hook():
"""Disable import hooks"""
__builtin__.__import__ = _original__import__
if __name__ == '__main__':
#Enable import hook
enable_import_hook()
import json
reload(json)
startup.py
import firstimport_hook
firstimport_hook.enable_import_hook()
Now, when you import a Python file for the first time, you can print () the path of the loaded module. After that, if you send it to the server appropriately, it will be possible to aggregate.
mel? You don't know ...