From 45d3387ae1d3d1937d209ea7ab3293efb5899e34 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 17 Dec 2024 10:30:51 -0600 Subject: [PATCH 1/5] PNG file icon. Find libraries one level deeper from wildcard import of file in learn project code --- create_requirement_images.py | 1 + get_imports.py | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/create_requirement_images.py b/create_requirement_images.py index 1f59017..2e495c3 100755 --- a/create_requirement_images.py +++ b/create_requirement_images.py @@ -71,6 +71,7 @@ def asset_path(asset_name): "txt": file_empty_icon, "toml": file_icon, "bmp": file_image_icon, + "png": file_image_icon, "wav": file_music_icon, "mp3": file_music_icon, "mid": file_music_icon, diff --git a/get_imports.py b/get_imports.py index 22d176c..812a49b 100644 --- a/get_imports.py +++ b/get_imports.py @@ -165,6 +165,7 @@ def get_files_for_project(project_name): def get_libs_for_project(project_name): + # pylint: disable=too-many-nested-blocks """Get the set of libraries for a learn project""" found_libs = set() found_imports = [] @@ -173,11 +174,23 @@ def get_libs_for_project(project_name): if file.endswith(".py"): found_imports = findimports.find_imports(f"{project_dir}{file}") - for cur_import in found_imports: cur_lib = cur_import.name.split(".")[0] if cur_lib in bundle_data or cur_lib in community_bundle_data: found_libs.add(cur_lib) + if cur_import.name.endswith(".*"): + filepath = os.path.join( + project_dir, "/".join(cur_import.name[:-2].split(".")) + ".py" + ) + if os.path.exists(filepath): + second_level_imports = findimports.find_imports(filepath) + for cur_second_level_import in second_level_imports: + cur_lib = cur_second_level_import.name.split(".")[0] + if ( + cur_lib in bundle_data + or cur_lib in community_bundle_data + ): + found_libs.add(cur_lib) return found_libs From 4f2c338fdc41f0d659276366673c136775628548 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 17 Dec 2024 10:59:59 -0600 Subject: [PATCH 2/5] os.path.join instead of string join --- get_imports.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/get_imports.py b/get_imports.py index 812a49b..3b3e62d 100644 --- a/get_imports.py +++ b/get_imports.py @@ -180,7 +180,8 @@ def get_libs_for_project(project_name): found_libs.add(cur_lib) if cur_import.name.endswith(".*"): filepath = os.path.join( - project_dir, "/".join(cur_import.name[:-2].split(".")) + ".py" + project_dir, + os.path.join(*cur_import.name[:-2].split(".")) + ".py", ) if os.path.exists(filepath): second_level_imports = findimports.find_imports(filepath) From 50776040224010ab6b67b5fc7eb371ce9a5db9c0 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 17 Dec 2024 11:02:51 -0600 Subject: [PATCH 3/5] wildcard import comment --- get_imports.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/get_imports.py b/get_imports.py index 3b3e62d..8858f52 100644 --- a/get_imports.py +++ b/get_imports.py @@ -178,6 +178,9 @@ def get_libs_for_project(project_name): cur_lib = cur_import.name.split(".")[0] if cur_lib in bundle_data or cur_lib in community_bundle_data: found_libs.add(cur_lib) + + # check if it's a wildcard import e.g. + # from module.submodule import * if cur_import.name.endswith(".*"): filepath = os.path.join( project_dir, From 0af6ff13a469d5944307258fe807ec2f696a8a0f Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 17 Dec 2024 11:22:45 -0600 Subject: [PATCH 4/5] wildcard import comment --- get_imports.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/get_imports.py b/get_imports.py index 8858f52..f4ef0ac 100644 --- a/get_imports.py +++ b/get_imports.py @@ -179,8 +179,7 @@ def get_libs_for_project(project_name): if cur_lib in bundle_data or cur_lib in community_bundle_data: found_libs.add(cur_lib) - # check if it's a wildcard import e.g. - # from module.submodule import * + # findimports returns import name in the form of ``foo.bar.*`` if cur_import.name.endswith(".*"): filepath = os.path.join( project_dir, From 6a95dd1c5499ba5ebab55c14c581af03c39ecf2d Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 17 Dec 2024 11:29:21 -0600 Subject: [PATCH 5/5] regular quotes --- get_imports.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/get_imports.py b/get_imports.py index f4ef0ac..c8a3988 100644 --- a/get_imports.py +++ b/get_imports.py @@ -179,7 +179,7 @@ def get_libs_for_project(project_name): if cur_lib in bundle_data or cur_lib in community_bundle_data: found_libs.add(cur_lib) - # findimports returns import name in the form of ``foo.bar.*`` + # findimports returns import name in the form of "foo.bar.*" if cur_import.name.endswith(".*"): filepath = os.path.join( project_dir,