From 9e3910e0f9cff36c937076d720ed8d635a036c0a Mon Sep 17 00:00:00 2001 From: Falko Habel Date: Sun, 19 Jan 2025 22:32:48 +0100 Subject: [PATCH] corrected code to dispaly __init__ and __main__ files as well --- example.py | 6 ++++-- tree_structurer/cpp/tree_structurer.cpp | 11 ++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/example.py b/example.py index c0e7345..4dd9443 100644 --- a/example.py +++ b/example.py @@ -1,3 +1,5 @@ -import tree_structurer +from tree_structurer import create_tree_structurer, get_structure -tree_structurer.get_structure() \ No newline at end of file +create_tree_structurer() +for file in get_structure(): + print(file) \ No newline at end of file diff --git a/tree_structurer/cpp/tree_structurer.cpp b/tree_structurer/cpp/tree_structurer.cpp index 23ff0db..5e35bed 100644 --- a/tree_structurer/cpp/tree_structurer.cpp +++ b/tree_structurer/cpp/tree_structurer.cpp @@ -10,6 +10,11 @@ bool TreeStructurer::should_ignore_dir(const std::string& dirname) { ".git", ".idea", ".vscode", "__pycache__", "**pycache**" }; + // Check for __main__.py or __init__.py files + if (!dirname.empty() && (dirname == "__main__.py" || dirname == "__init__.py")) { + return false; // Do not ignore these files + } + if (std::find(ignore_list.begin(), ignore_list.end(), dirname) != ignore_list.end()) { return true; } @@ -26,13 +31,17 @@ bool TreeStructurer::should_ignore_dir(const std::string& dirname) { return false; } -// Add the missing should_ignore_file implementation bool TreeStructurer::should_ignore_file(const std::string& filename) { static const std::vector ignore_extensions = { ".pyc", ".pyo", ".pyd", ".so", ".dll", ".dylib", ".o", ".obj", ".a", ".lib" }; + // Check for __main__.py or __init__.py files + if (!filename.empty() && (filename == "__main__.py" || filename == "__init__.py")) { + return false; // Do not ignore these files + } + if (!filename.empty() && (filename[0] == '.' || filename[0] == '_')) { return true; }