@@ -673,14 +673,15 @@ def imports_from_code(full_content):
673673 return sorted (imports )
674674
675675
676- def get_all_imports (
677- backend , auto_file_content , mod_names , current_module , visited = None
676+ def get_all_imports ( # pylint: disable=too-many-arguments,too-many-locals, too-many-branches
677+ backend , auto_file_content , auto_file_path , mod_names , current_module , visited = None
678678):
679679 """
680680 Recursively retrieve imports from files on the backend
681681
682682 :param Backend backend: The current backend object
683683 :param str auto_file_content: Content of the python file to analyse
684+ :param str auto_file_path: Path to the python file to analyse
684685 :param list mod_names: Lits of supported bundle mod names
685686 :param str current_module: Name of the call context module if recursive call
686687 :param set visited: Modules previously visited
@@ -714,18 +715,37 @@ def get_all_imports(
714715 install_module = install
715716 # possible files for the module: .py or __init__.py (if directory)
716717 file_name = os .path .join (* install_module .split ("." )) + ".py"
717- exists = backend .file_exists (file_name )
718+ try :
719+ file_location = os .path .join (
720+ * auto_file_path .replace (str (backend .device_location ), "" ).split (
721+ "/"
722+ )[:- 1 ]
723+ )
724+
725+ full_location = os .path .join (file_location , file_name )
726+
727+ except TypeError :
728+ # file is in root of CIRCUITPY
729+ full_location = file_name
730+
731+ exists = backend .file_exists (full_location )
718732 if not exists :
719733 file_name = os .path .join (* install_module .split ("." ), "__init__.py" )
720- exists = backend .file_exists (file_name )
734+ full_location = file_name
735+ exists = backend .file_exists (full_location )
721736 if not exists :
722737 continue
723738 install_module += ".__init__"
724739 # get the content and parse it recursively
725- auto_file_content = backend .get_file_content (file_name )
740+ auto_file_content = backend .get_file_content (full_location )
726741 if auto_file_content :
727742 sub_imports = get_all_imports (
728- backend , auto_file_content , mod_names , install_module , visited
743+ backend ,
744+ auto_file_content ,
745+ auto_file_path ,
746+ mod_names ,
747+ install_module ,
748+ visited ,
729749 )
730750 requested_installs .extend (sub_imports )
731751
@@ -775,7 +795,9 @@ def libraries_from_auto_file(backend, auto_file, mod_names):
775795 # from file name to module name (in case it's in a subpackage)
776796 click .secho (f"Finding imports from: { auto_file } " , fg = "green" )
777797 current_module = auto_file .rstrip (".py" ).replace (os .path .sep , "." )
778- return get_all_imports (backend , auto_file_content , mod_names , current_module )
798+ return get_all_imports (
799+ backend , auto_file_content , auto_file , mod_names , current_module
800+ )
779801
780802
781803def get_device_path (host , port , password , path ):
0 commit comments