@@ -125,10 +125,16 @@ def set_up_eb_package(parent_path, eb_pkg_name, subpkgs=None, pkg_init_body=None
125125
126126def verify_imports (pymods , pypkg , from_path ):
127127 """Verify that import of specified modules from specified package and expected location works."""
128- saved_modules = sys .modules .copy ()
129128
130129 for pymod in pymods :
131130 pymod_spec = '%s.%s' % (pypkg , pymod )
131+
132+ # force re-import if the specified modules was already imported;
133+ # this is required to ensure that an easyblock that is included via --include-easyblocks-from-pr
134+ # gets preference over one that is included via --include-easyblocks
135+ if pymod_spec in sys .modules :
136+ del sys .modules [pymod_spec ]
137+
132138 try :
133139 pymod = __import__ (pymod_spec , fromlist = [pypkg ])
134140 # different types of exceptions may be thrown, not only ImportErrors
@@ -142,10 +148,6 @@ def verify_imports(pymods, pypkg, from_path):
142148
143149 _log .debug ("Import of %s from %s verified" , pymod_spec , from_path )
144150
145- # restore sys.modules to its original state (not only verified modules but also their dependencies)
146- sys .modules .clear ()
147- sys .modules .update (saved_modules )
148-
149151
150152def is_software_specific_easyblock (module ):
151153 """Determine whether Python module at specified location is a software-specific easyblock."""
@@ -279,7 +281,7 @@ def include_toolchains(tmpdir, paths):
279281 sys .modules [tcpkg ].__path__ .insert (0 , os .path .join (toolchains_path , 'easybuild' , 'toolchains' , subpkg ))
280282
281283 # sanity check: verify that included toolchain modules can be imported (from expected location)
282- verify_imports ([os .path .splitext (mns )[0 ] for mns in included_toolchains ], 'easybuild.toolchains' , tcs_dir )
284+ verify_imports ([os .path .splitext (tc )[0 ] for tc in included_toolchains ], 'easybuild.toolchains' , tcs_dir )
283285 for subpkg in toolchain_subpkgs :
284286 pkg = '.' .join (['easybuild' , 'toolchains' , subpkg ])
285287 loc = os .path .join (tcs_dir , subpkg )
0 commit comments