python: Fix params/proxy import loop
authorAndreas Sandberg <andreas.sandberg@arm.com>
Sat, 26 Jan 2019 09:23:16 +0000 (09:23 +0000)
committerAndreas Sandberg <andreas.sandberg@arm.com>
Mon, 25 Feb 2019 10:04:32 +0000 (10:04 +0000)
There is a circular dependency between params and proxy at import
time. This causes issues for Python 3. Add the imports to the specific
methods with the dependencies to make the import happen when the
method is executed instead.

Change-Id: I770112fd3c07c395459e204976942bda3dc7236f
Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/15993
Reviewed-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
Reviewed-by: Juha Jäykkä <juha.jaykka@arm.com>
src/python/m5/params.py
src/python/m5/proxy.py

index 72cc0b2ad2a050557242c6f3f8e63eefe0b38f61..757a4f2385a135a88676f4fd777347e75277b5c0 100644 (file)
@@ -73,12 +73,15 @@ from . import ticks
 from .util import *
 
 def isSimObject(*args, **kwargs):
+    from . import SimObject
     return SimObject.isSimObject(*args, **kwargs)
 
 def isSimObjectSequence(*args, **kwargs):
+    from . import SimObject
     return SimObject.isSimObjectSequence(*args, **kwargs)
 
 def isSimObjectClass(*args, **kwargs):
+    from . import SimObject
     return SimObject.isSimObjectClass(*args, **kwargs)
 
 allParams = {}
@@ -175,6 +178,7 @@ class ParamDesc(object):
 
     def __getattr__(self, attr):
         if attr == 'ptype':
+            from . import SimObject
             ptype = SimObject.allClasses[self.ptype_str]
             assert isSimObjectClass(ptype)
             self.ptype = ptype
@@ -2158,5 +2162,3 @@ __all__ = ['Param', 'VectorParam',
            'NextEthernetAddr', 'NULL',
            'MasterPort', 'SlavePort',
            'VectorMasterPort', 'VectorSlavePort']
-
-from . import SimObject
index 346ed928bfdbfc535052931e1749739efde84ee1..b939bc0596215fc657bca22edabed59927281713 100644 (file)
@@ -50,7 +50,6 @@ from __future__ import absolute_import
 
 import copy
 
-from . import params
 
 class BaseProxy(object):
     def __init__(self, search_self, search_up):
@@ -235,6 +234,7 @@ class AllProxy(BaseProxy):
         return 'all'
 
 def isproxy(obj):
+    from . import params
     if isinstance(obj, (BaseProxy, params.EthernetAddr)):
         return True
     elif isinstance(obj, (list, tuple)):
@@ -264,6 +264,3 @@ Self = ProxyFactory(search_self = True, search_up = False)
 
 # limit exports on 'from proxy import *'
 __all__ = ['Parent', 'Self']
-
-# see comment on imports at end of __init__.py.
-import params # for EthernetAddr