Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions Components.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import os
import sys
import imp
import inspect
import zipfile
import zipimport
Expand All @@ -40,7 +39,6 @@

from tempfile import gettempdir


if builtins.__dict__.get('GUI_FLAG',True):
import wx

Expand All @@ -50,8 +48,6 @@

import ZipManager

#from DomainInterface.DomainBehavior import DomainBehavior
#from DomainInterface.DomainStructure import DomainStructure
from ReloadModule import recompile
from Utilities import GetActiveWindow, path_to_module, install_and_import, printOnStatusBar
from NetManager import Net
Expand Down Expand Up @@ -743,13 +739,13 @@ def GetModule(filename):

# find and load module
#try:
#name, ext = os.path.splitext(module_name)
#pkg = '.'.join(modulename.split('.')[0:-1])
#module = importlib.import_module(name, package=pkg)
name, ext = os.path.splitext(module_name)
pkg = '.'.join(module_name.split('.')[0:-1])
module = importlib.import_module(name, package=pkg)

f, fn, description = imp.find_module(module_name, [dir_name])
module = imp.load_module(module_name, f, fn, description)
f.close()
#f, fn, description = imp.find_module(module_name, [dir_name])
#module = imp.load_module(module_name, f, fn, description)
#f.close()
return module

#except Exception as info:
Expand Down Expand Up @@ -787,7 +783,7 @@ def GetBlock(filename, label):
def CreateBlock(*argv, **kwargs):
""" Create Block from python_file and other info coming from wizard.
"""

from Container import iPort, oPort, MsgBoxError
### import are here because the simulator (PyDEVS or PyPDEVS) require it
from DomainInterface.DomainBehavior import DomainBehavior
Expand Down
5 changes: 1 addition & 4 deletions Container.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,12 @@

from tempfile import gettempdir
from traceback import format_exception

from math import * ### for eval

import DomainInterface.MasterModel

if builtins.__dict__.get('GUI_FLAG',True):
import ConnectDialog
import DiagramConstantsDialog
import SpreadSheet
#from PluginManager import PluginManager
import ZipManager
import DropTarget
import PlotGUI
Expand Down Expand Up @@ -385,6 +381,7 @@ def makeDEVSInstance(diagram = None):
if diagram.getDEVSModel():
diagram.ClearAllPorts()
else:
import DomainInterface.MasterModel
diagram.setDEVSModel(DomainInterface.MasterModel.Master())

### shape list of diagram
Expand Down
Empty file added DEVSimPy-v4_0_Container.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion DomainInterface/DomainBehavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
### for py 3.X
import importlib
BaseDEVS = importlib.import_module("DEVSKernel%s.DEVS"%d)
### for py 2.X
#exec("import DEVSKernel%s.DEVS as BaseDEVS"%(d))

Expand Down
4 changes: 2 additions & 2 deletions DomainInterface/MasterModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
### for py 3.X
import importlib
BaseDEVS = importlib.import_module("DEVSKernel%s.DEVS"%d)

#exec("import DEVSKernel%s.DEVS as BaseDEVS"%(d))

#import DomainStructure

### ====================================================================== #
Expand Down
4 changes: 2 additions & 2 deletions Editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
import keyword
import inspect
import zipfile
import imp
import threading
import re
import codecs
import tabnanny
import builtins
import types
import traceback

from traceback import format_exception, extract_tb
Expand Down Expand Up @@ -99,7 +99,7 @@ def getObjectFromString(scriptlet):

else:
# Create the new 'temp' module.
temp = imp.new_module("temp")
temp = types.ModuleType('temp')
sys.modules["temp"] = temp

### there is syntaxe error ?
Expand Down
4 changes: 2 additions & 2 deletions LibPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ def BuildToolbar(self):
if wx.VERSION_STRING < '4.0':
tb.AddTool(Menu.ID_NEW_LIB, wx.Bitmap(os.path.join(ICON_PATH_16_16,'db+2.png')), shortHelpString=_('Import'), longHelpString=_('Import new libraries from directory'))
tb.AddTool(Menu.ID_DELETE_LIB, wx.Bitmap(os.path.join(ICON_PATH_16_16,'db-2.png')), shortHelpString=_('Delete'), longHelpString=_('Delete the selected libraries'))
tb.AddTool(Menu.ID_REFRESH_LIB, wx.Bitmap(os.path.join(ICON_PATH_16_16,'db_refresh2.png')), shortHelpString=_('Refresh'), longHelpString=_('Force the refresh of the loaded libraries'))
tb.AddTool(Menu.ID_REFRESH_LIB, wx.Bitmap(os.path.join(ICON_PATH_16_16,'db_refresh2.png')), shortHelpString=_('Reload'), longHelpString=_('Force to reload libraries'))
#tb.AddTool(Menu.ID_IMPORT_LIB, wx.Bitmap(os.path.join(ICON_PATH_16_16,'dbimport2.png')), shortHelpString=_('Import library'), longHelpString=_('Call the import manager'))
tb.AddTool(Menu.ID_HELP_LIB, wx.Bitmap(os.path.join(ICON_PATH_16_16, 'dbinfo2.png')), shortHelpString=_('Help'), longHelpString=_('Information about import manager'))
else:
tb.AddTool(Menu.ID_NEW_LIB, "", wx.Bitmap(os.path.join(ICON_PATH_16_16,'db+2.png')), shortHelp=_('Import'))
tb.AddTool(Menu.ID_DELETE_LIB, "", wx.Bitmap(os.path.join(ICON_PATH_16_16,'db-2.png')), shortHelp=_('Delete'))
tb.AddTool(Menu.ID_REFRESH_LIB, "", wx.Bitmap(os.path.join(ICON_PATH_16_16,'db_refresh2.png')), shortHelp=_('Refresh'))
tb.AddTool(Menu.ID_REFRESH_LIB, "", wx.Bitmap(os.path.join(ICON_PATH_16_16,'db_refresh2.png')), shortHelp=_('Reload'))
tb.AddTool(Menu.ID_HELP_LIB, "", wx.Bitmap(os.path.join(ICON_PATH_16_16, 'dbinfo2.png')), shortHelp=_('Help'))
tb.AddCheckTool(Menu.ID_MCC_LIB, '', wx.Bitmap(os.path.join(ICON_PATH_16_16,'a-z.png')), shortHelp='MacCabe')
tb.ToggleTool(Menu.ID_MCC_LIB, True)
Expand Down
2 changes: 1 addition & 1 deletion LibraryTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ def GetItemChildren(self, item, recursively = False):
def GetPYFileList(dName, ext=".py"):
""" Return .py files that are instanciable.
"""

### import are here because the simulator (PyDEVS or PyPDEVS) require it
from DomainInterface.DomainBehavior import DomainBehavior

Expand Down
2 changes: 1 addition & 1 deletion Menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ def __init__(self, parent):
wx.Menu.__init__(self)

new = wx.MenuItem(self, ID_NEW_LIB, _('New/Import'), _('Create or import library'))
refresh = wx.MenuItem(self, ID_REFRESH_LIB, _('Refresh'), _('Refresh library'))
refresh = wx.MenuItem(self, ID_REFRESH_LIB, _('Reload'), _('Reload library'))
#upgrade = wx.MenuItem(self, ID_UPGRADE_LIB, _('Upgrade'), _('Upgrade library'))
info = wx.MenuItem(self, ID_HELP_LIB, _('Help'), _('Library description'))

Expand Down
3 changes: 1 addition & 2 deletions Mixins/Plugable.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import sys
import os
import zipimport
import imp
import inspect
import types
import zipfile
Expand Down Expand Up @@ -53,7 +52,7 @@ def Load_Module(fileName):
code = importer.get_code(old_plugin_name)

# Create the new 'temp' module.
temp = imp.new_module(new_plugin_name)
temp = types.ModuleType(new_plugin_name)
sys.modules[new_plugin_name] = temp

### there is syntax error ?
Expand Down
4 changes: 2 additions & 2 deletions NetManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"""

import sys
import imp
import http.client
import types
from urllib.parse import urlparse

class Net:
Expand All @@ -40,7 +40,7 @@ def GetMoldule(python_file=""):
pass

### make new module
mod = imp.new_module(module_name)
mod = types.ModuleType(module_name)
sys.modules[module_name] = mod
mod.__file__ = self._py_net_file

Expand Down
2 changes: 1 addition & 1 deletion PluginsGUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def Importing(self, root, basename):
### if module is exception (or tuple)
if not inspect.ismodule(module):
error = str(module)
module = importlib.new_module(basename)
module = types.ModuleType(basename)
module.__doc__ = error
module.__file__ = None

Expand Down
28 changes: 10 additions & 18 deletions PreferencesGUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ def onSc(self, evt):
self.sim_defaut_plot_dyn_freq = val

def OnApply(self, evt):
""" Apply changes
""" Apply changes.
"""

### Reload DomainBehavior and DomainStructure
Expand All @@ -478,26 +478,18 @@ def OnApply(self, evt):
builtins.__dict__['DEFAULT_DEVS_DIRNAME'] = self.default_devs_dir

### recompile the modules.
### recompile DomainInterface.DomainBehavior with all loaded module depending on this one
d = copy.copy(sys.modules)
for m in d:
if d[m]:
try:
clsmembers = inspect.getmembers(d[m], inspect.isclass)
if clsmembers != [] and clsmembers[0][0] == 'DomainBehavior':
module_path = os.path.dirname(d[m].__file__)
### if m come from amd or cmd, pass path to recompile method to differentiate
if zipfile.is_zipfile(module_path):
ReloadModule.recompile(module_path)
else:
ReloadModule.recompile(m)
except Exception as info:
sys.stdout.write("Exception in PreferenceGui")
sys.stdout.write(str(info))

### recompile DomainInterface.DomainBehavior , DomainInterfaceStructure and MasterModel
### recompile all librairies that depend on DomainBehavior (all loaded lib)

ReloadModule.recompile("DomainInterface.DomainBehavior")
ReloadModule.recompile("DomainInterface.DomainStructure")
ReloadModule.recompile("DomainInterface.MasterModel")

mainW = wx.GetApp().GetTopWindow()
nb1 = mainW.GetControlNotebook()
tree = nb1.GetTree()
tree.UpdateAll()

### enable the priority (DEVS select function) icon depending on the selected DEVS kernel
mainW = wx.GetApp().GetTopWindow()
tb = mainW.GetToolBar()
Expand Down
54 changes: 0 additions & 54 deletions RQ.py

This file was deleted.

69 changes: 57 additions & 12 deletions ReloadModule.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
import types
import pkgutil

import gettext
_ = gettext.gettext

from traceback import format_exception
from Utilities import listf

def reloadall(module):
importlib.reload(module)
for child in pkgutil.walk_packages(module.__path__):
if isinstance(child, types.ModuleType):
reloadall(child)
if hasattr(module, '__path__'):
for child in pkgutil.walk_packages(module.__path__):
if isinstance(child, types.ModuleType):
reloadall(child)

def recompile(modulename):
""" recompile module from modulename
Expand All @@ -29,10 +33,7 @@ def recompile(modulename):
else:
try:
### first, see if the module can be imported at all...
name, ext = os.path.splitext(modulename)
pkg = '.'.join(modulename.split('.')[0:-1])
tmp = importlib.import_module(name, package=pkg)
#tmp = __import__(modulename, globals(), locals(), fromlist = [modulename.split('.')[-1]])
tmp = __import__(modulename, globals(), locals(), fromlist = [modulename.split('.')[-1]])

except Exception as info:
return info
Expand Down Expand Up @@ -65,8 +66,52 @@ def recompile(modulename):
### reload recursivelly!
try:
reloadall(tmp)
return sys.modules[tmp.__name__]
except:
sys.stdout.write('Error trying to reload dependencies in recompile module!')
else:
return importlib.reload(tmp)
except Exception as info:
sys.stdout.write(_('Error trying to reload dependencies in recompile module: %s\n')%info)
finally:
return importlib.reload(sys.modules[modulename])

#return importlib.reload(tmp)

def recompile2(modulename):
""" recompile module from modulename
"""

### modulename is file type
if os.path.isfile(modulename) and os.path.exists(modulename):
import ZipManager
zf = ZipManager.Zip(modulename)
return zf.Recompile()
else:

try:
#name, ext = os.path.splitext(modulename)
#pkg = '.'.join(modulename.split('.')[0:-1])
#tmp = importlib.import_module(name, package=pkg)

### first, see if the module can be imported at all...
tmp = __import__(modulename, globals(), locals(), fromlist = [modulename.split('.')[-1]])

except Exception as info:
return info

### Use the imported module to determine its actual path
pycfile = os.path.abspath(tmp.__file__)
modulepath = pycfile.replace(".pyc", ".py")

### Try to open the specified module as a file
code = open(modulepath, 'rU').read()

### see if the file we opened can compile. If not, return the error that it gives.
### if compile() fails, the module will not be replaced.
compile(code, modulename, "exec")


### Ok, it compiled. But will it execute without error?
exec(compile(open(modulepath).read(), modulepath, 'exec'), globals())

reloadall(tmp)

### at this point, the code both compiled and ran without error. Load it up
### replacing the original code.
return importlib.reload(sys.modules[modulename])
Loading