Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@property
def shortname(self):
if self.__name__ == "__main__":
return self.__file__[:-3].replace('\\', '.')
return self.__name__
def __repr__(self):
return "Module(name=%s, file=%r, path=%r)" % (
self.__name__,
(self.__file__ or "").replace('\\', '/'),
self.__path__
)
class MyModuleFinder(mf27.ModuleFinder):
def __init__(self, fname, *args, **kwargs):
self.args = kwargs
self.verbose = kwargs.get('verbose', 0)
# include all of python std lib (incl. C modules)
self.include_pylib_all = kwargs.pop('pylib_all', False)
# include python std lib modules.
# self.include_pylib = kwargs.pop('pylib', self.include_pylib_all)
self.include_pylib = kwargs.pop('pylib', self.include_pylib_all)
self._depgraph = defaultdict(dict)
self._types = {}
self._last_caller = None
# path=None, debug=0, excludes=[], replace_paths=[]
if not args:
script = "hello.py"
else:
script = args[0]
# Set the path based on sys.path and the script directory
path = sys.path[:]
path[0] = os.path.dirname(script)
path = addpath + path
if debug > 1:
print("path:")
for item in path:
print(" ", repr(item))
# Create the module finder and turn its crank
mf = ModuleFinder(path, debug, exclude)
for arg in args[1:]:
if arg == '-m':
domods = 1
continue
if domods:
if arg[-2:] == '.*':
mf.import_hook(arg[:-2], None, ["*"])
else:
mf.import_hook(arg)
else:
mf.load_file(arg)
mf.run_script(script)
mf.report()
return mf # for -i debugging
self.verbose = kwargs.get('verbose', 0)
# include all of python std lib (incl. C modules)
self.include_pylib_all = kwargs.pop('pylib_all', False)
# include python std lib modules.
# self.include_pylib = kwargs.pop('pylib', self.include_pylib_all)
self.include_pylib = kwargs.pop('pylib', self.include_pylib_all)
self._depgraph = defaultdict(dict)
self._types = {}
self._last_caller = None
# path=None, debug=0, excludes=[], replace_paths=[]
debug = 5 if self.verbose >= 4 else 0
mf27.ModuleFinder.__init__(self,
path=fname,
debug=debug,
# debug=3,
excludes=kwargs.get('excludes', []))