@@ -1965,7 +1965,7 @@ def _setup_dev_tools(self, **kwargs):
19651965
19661966 return dev_tools
19671967
1968- def enable_dev_tools (
1968+ def enable_dev_tools ( # pylint: disable=too-many-branches
19691969 self ,
19701970 debug : Optional [bool ] = None ,
19711971 dev_tools_ui : Optional [bool ] = None ,
@@ -2080,10 +2080,10 @@ def enable_dev_tools(
20802080 _reload = self ._hot_reload
20812081 _reload .hash = generate_hash ()
20822082
2083- # find_loader should return None on __main__ but doesn't
2083+ # find_spec should return None on __main__ but doesn't
20842084 # on some Python versions https://bugs.python.org/issue14710
20852085 packages = [
2086- pkgutil . find_loader (x )
2086+ find_spec (x )
20872087 for x in list (ComponentRegistry .registry )
20882088 if x != "__main__"
20892089 ]
@@ -2097,27 +2097,49 @@ def enable_dev_tools(
20972097 )
20982098
20992099 for index , package in enumerate (packages ):
2100- if isinstance (package , AssertionRewritingHook ):
2100+ if package and isinstance (package . loader , AssertionRewritingHook ):
21012101 dash_spec = importlib .util .find_spec ("dash" ) # type: ignore[reportAttributeAccess]
2102- dash_test_path = dash_spec .submodule_search_locations [0 ]
2103- setattr (dash_spec , "path" , dash_test_path )
21042102 packages [index ] = dash_spec
21052103
2106- component_packages_dist = [
2107- dash_test_path # type: ignore[reportPossiblyUnboundVariable]
2108- if isinstance (package , ModuleSpec )
2109- else os .path .dirname (package .path ) # type: ignore[reportAttributeAccessIssue]
2110- if hasattr (package , "path" )
2111- else os .path .dirname (
2112- package ._path [0 ] # type: ignore[reportAttributeAccessIssue]; pylint: disable=protected-access
2113- )
2114- if hasattr (package , "_path" )
2115- else package .filename # type: ignore[reportAttributeAccessIssue]
2116- for package in packages
2117- ]
2104+ component_packages_dist = []
2105+ for package in packages :
2106+ if package and isinstance (package , ModuleSpec ):
2107+ # For ModuleSpec objects, use submodule_search_locations or origin
2108+ if package .submodule_search_locations :
2109+ component_packages_dist .append (
2110+ package .submodule_search_locations [0 ]
2111+ )
2112+ elif package .origin :
2113+ component_packages_dist .append (os .path .dirname (package .origin ))
2114+ else :
2115+ component_packages_dist .append ("" )
2116+ else :
2117+ # Fallback for non-ModuleSpec objects (shouldn't happen with find_spec)
2118+ if hasattr (package , "path" ):
2119+ component_packages_dist .append (os .path .dirname (package .path )) # type: ignore[reportAttributeAccessIssue]
2120+ elif hasattr (package , "_path" ):
2121+ component_packages_dist .append (os .path .dirname (package ._path [0 ])) # type: ignore[reportAttributeAccessIssue]; pylint: disable=protected-access
2122+ elif hasattr (package , "filename" ):
2123+ component_packages_dist .append (package .filename ) # type: ignore[reportAttributeAccessIssue]
2124+ else :
2125+ component_packages_dist .append ("" )
21182126
21192127 for i , package in enumerate (packages ):
2120- if hasattr (package , "path" ) and "dash/dash" in os .path .dirname (
2128+ if package and isinstance (package , ModuleSpec ):
2129+ # Check origin for ModuleSpec objects
2130+ pkg_dir = (
2131+ package .submodule_search_locations [0 ]
2132+ if package .submodule_search_locations
2133+ else os .path .dirname (package .origin )
2134+ if package .origin
2135+ else None
2136+ )
2137+ if pkg_dir and "dash/dash" in pkg_dir :
2138+ component_packages_dist [i : i + 1 ] = [
2139+ os .path .join (pkg_dir , x )
2140+ for x in ["dcc" , "html" , "dash_table" ]
2141+ ]
2142+ elif hasattr (package , "path" ) and "dash/dash" in os .path .dirname (
21212143 package .path # type: ignore[reportAttributeAccessIssue]
21222144 ):
21232145 component_packages_dist [i : i + 1 ] = [
0 commit comments