From 359d29ca68791663f846319fd2c7a71d992e2a75 Mon Sep 17 00:00:00 2001 From: Falko Habel Date: Sun, 9 Feb 2025 21:33:41 +0100 Subject: [PATCH 01/10] bugfix in version number --- pyproject.toml | 6 ++++++ setup.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 8bb404a..0d7ded4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,3 +8,9 @@ version = "1.0.0" description = "A module for analyzing and creating directory structures" scripts = {prodir = "prodir.__main__:main"} dependencies = [] + +license = {text = "Creative Commons Attribution 4.0 International"} + +authors = [ + { name="Falko Habel", email="falko.habel@fabelous.app" } +] diff --git a/setup.py b/setup.py index baf9d09..190d430 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ tree_structurer_module = Extension( setup( name='prodir', - version='0.1.0', + version='1.0.0', description='A module for analyzing directory structures', ext_modules=[tree_structurer_module], packages=find_packages(where="src"), From 53c302585622a6e712b2a46e182136c34b12b67b Mon Sep 17 00:00:00 2001 From: Falko Habel Date: Mon, 10 Feb 2025 18:15:34 +0100 Subject: [PATCH 02/10] updated namings --- .gitea/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/test.yaml b/.gitea/workflows/test.yaml index 4989700..5d8b0b9 100644 --- a/.gitea/workflows/test.yaml +++ b/.gitea/workflows/test.yaml @@ -1,4 +1,4 @@ -name: Gitea Actions For Tree-Structurer +name: Gitea Actions For prodir run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀 on: [push] From 1a3f6cb451ed6e4b52ac0ae469f96abacfd1f27b Mon Sep 17 00:00:00 2001 From: Falko Habel Date: Mon, 21 Apr 2025 22:59:22 +0200 Subject: [PATCH 03/10] implemented allowance comments in the example / correct display of line is still WIP --- src/prodir/cpp/tree_structurer.cpp | 215 +++++++++++++++++++++++------ 1 file changed, 174 insertions(+), 41 deletions(-) diff --git a/src/prodir/cpp/tree_structurer.cpp b/src/prodir/cpp/tree_structurer.cpp index 2302cce..fe31f25 100644 --- a/src/prodir/cpp/tree_structurer.cpp +++ b/src/prodir/cpp/tree_structurer.cpp @@ -1,5 +1,5 @@ #include "tree_structurer.hpp" - +#include #include #include #include @@ -123,62 +123,166 @@ std::vector TreeStructurer::get_filtered_paths(const fs::path& start) std::vector TreeStructurer::get_directory_structure(const std::string& startpath) { std::vector result; - // Normalize the input path by removing ./ or .\ prefix if present std::string normalized_path = startpath; - if (startpath.substr(0, 2) == ".\\" || startpath.substr(0, 2) == "./") { - normalized_path = startpath.substr(2); + if (normalized_path.size() >= 2 && + (normalized_path.substr(0, 2) == ".\\" || normalized_path.substr(0, 2) == "./")) { + normalized_path = normalized_path.substr(2); } - fs::path start = normalized_path.empty() ? fs::current_path() : fs::path(normalized_path); - + try { - auto paths = get_filtered_paths(start); - if (paths.empty()) { - throw std::runtime_error("No valid files or directories found in: " + start.string()); + if (!fs::exists(start)) { + throw std::runtime_error("Directory does not exist: " + start.string()); } - std::vector is_last_at_level(256, false); - for (size_t i = 1; i < paths.size(); ++i) { - const auto& path = paths[i]; + if (!fs::is_directory(start)) { + throw std::runtime_error("Path is not a directory: " + start.string()); + } + + // Start with the root node + std::string root_name = start.filename().string(); + result.push_back(root_name + "/"); + + // First, collect all paths and organize them by their parent directories + std::map> dir_contents; + std::vector dir_paths; // To maintain order of directories + + // Add root directory + dir_contents["/"] = {}; + dir_paths.push_back("/"); + + // Collect files and directories + for (const auto& entry : fs::recursive_directory_iterator(start)) { + const auto& path = entry.path(); std::string rel_path = get_relative_path(path, start); - int level = std::count(rel_path.begin(), rel_path.end(), fs::path::preferred_separator); - - bool is_last = true; - for (size_t j = i + 1; j < paths.size(); ++j) { - std::string next_rel_path = get_relative_path(paths[j], start); - int next_level = std::count(next_rel_path.begin(), next_rel_path.end(), fs::path::preferred_separator); - if (next_level == level) { - is_last = false; - break; - } - if (next_level < level) { + // Replace backslashes with forward slashes + std::replace(rel_path.begin(), rel_path.end(), '\\', '/'); + + // Skip if it should be ignored + bool should_skip = false; + for (const auto& component : path) { + if (should_ignore_dir(component.string())) { + should_skip = true; break; } } - - is_last_at_level[level] = is_last; - - std::string line; - for (int j = 0; j < level; ++j) { - if (j == level - 1) { - line += is_last ? "└── " : "├── "; - } else { - line += is_last_at_level[j] ? " " : "│ "; + if (should_skip) continue; + + if (entry.is_directory()) { + if (should_ignore_dir(path.filename().string())) { + continue; } + + // Add directory to its parent + std::string parent_path = "/"; + size_t last_slash = rel_path.find_last_of('/'); + if (last_slash != std::string::npos) { + parent_path = rel_path.substr(0, last_slash); + if (parent_path.empty()) { + parent_path = "/"; + } + } + + // Create parent directory entry if it doesn't exist + if (dir_contents.find(parent_path) == dir_contents.end()) { + dir_contents[parent_path] = {}; + dir_paths.push_back(parent_path); + } + + // Create directory entry + dir_contents[parent_path].push_back(path); + + // Create entry for this directory's contents + dir_contents[rel_path] = {}; + dir_paths.push_back(rel_path); + } else { + if (should_ignore_file(path.filename().string())) { + continue; + } + + // Add file to its parent + std::string parent_path = "/"; + size_t last_slash = rel_path.find_last_of('/'); + if (last_slash != std::string::npos) { + parent_path = rel_path.substr(0, last_slash); + if (parent_path.empty()) { + parent_path = "/"; + } + } + + // Create parent directory entry if it doesn't exist + if (dir_contents.find(parent_path) == dir_contents.end()) { + dir_contents[parent_path] = {}; + dir_paths.push_back(parent_path); + } + + dir_contents[parent_path].push_back(path); } - - line += path.filename().string(); - if (fs::is_directory(path)) { - line += "/"; - } - result.push_back(line); } + + // Now create the tree structure + std::function&)> + build_tree = [&](const std::string& dir_path, const std::string& prefix, std::vector& is_last_stack) { + // Sort paths - directories first, then files + std::vector& paths = dir_contents[dir_path]; + std::sort(paths.begin(), paths.end(), [](const fs::path& a, const fs::path& b) { + bool a_is_dir = fs::is_directory(a); + bool b_is_dir = fs::is_directory(b); + if (a_is_dir != b_is_dir) { + return a_is_dir > b_is_dir; // Directories before files + } + return a.filename() < b.filename(); // Alphabetical order + }); + + // Add entries for this directory + for (size_t i = 0; i < paths.size(); ++i) { + const auto& path = paths[i]; + bool is_last = (i == paths.size() - 1); + + // Build the line prefix + std::string line_prefix = prefix; + if (!prefix.empty()) { + line_prefix += is_last ? "└── " : "├── "; + } + + // Add the file/directory name + std::string name = path.filename().string(); + std::string line = line_prefix + name; + + if (fs::is_directory(path)) { + line += "/"; + } + + result.push_back(line); + + // If it's a directory, process its contents with updated prefix + if (fs::is_directory(path)) { + std::string rel_path = get_relative_path(path, start); + std::replace(rel_path.begin(), rel_path.end(), '\\', '/'); + + std::string next_prefix = prefix; + if (!prefix.empty()) { + next_prefix += is_last ? " " : "│ "; + } + + std::vector next_is_last_stack = is_last_stack; + next_is_last_stack.push_back(is_last); + + build_tree(rel_path, next_prefix, next_is_last_stack); + } + } + }; + + // Start building the tree from the root + std::vector is_last_stack; + build_tree("/", "", is_last_stack); + } catch (const fs::filesystem_error& e) { throw std::runtime_error("Failed to access directory: " + std::string(e.what())); } - + return result; } @@ -406,7 +510,7 @@ void TreeStructurer::create_file(const fs::path& path) { } } -// Reads a structure file into a vector of non-empty lines. +// Reads a structure file into a vector of non-empty lines, ignoring comments. std::vector TreeStructurer::read_structure_file(const std::string& filepath) { std::vector lines; // Open file in binary mode to avoid Windows CRLF conversion @@ -416,16 +520,45 @@ std::vector TreeStructurer::read_structure_file(const std::string& } std::string line; + while (std::getline(file, line)) { // Remove carriage return if present (Windows files) if (!line.empty() && line.back() == '\r') { line.pop_back(); } - + + std::cout << "Processing line: " << line << std::endl; + + size_t hash_pos = line.find('#'); + size_t single_line_comment_pos = line.find("//"); + size_t multi_line_comment_start_pos = line.find("/*"); + + if (hash_pos != std::string::npos) { + // Trim the line at the hash comment + line = line.substr(0, hash_pos); + std::cout << "Trimmed line at hash comment position: " << hash_pos << std::endl; + } else if (single_line_comment_pos != std::string::npos) { + // Trim the line at the single-line comment + line = line.substr(0, single_line_comment_pos); + std::cout << "Trimmed line at single-line comment position: " << single_line_comment_pos << std::endl; + } else if (multi_line_comment_start_pos != std::string::npos) { + // Trim the line at the multi-line comment start + line = line.substr(0, multi_line_comment_start_pos); + std::cout << "Trimmed line at multi-line comment start position: " << multi_line_comment_start_pos << std::endl; + } + + // Remove leading and trailing whitespace + line.erase(0, line.find_first_not_of(" \t\n\r\f\v")); + line.erase(line.find_last_not_of(" \t\n\r\f\v") + 1); + if (!line.empty()) { lines.push_back(line); + std::cout << "Added non-empty line: " << line << std::endl; + } else { + std::cout << "Skipped empty or commented-out line." << std::endl; } } + return lines; } // Checks the structure for obvious mistakes (e.g. a jump in indentation). From 88ac87a0b6d9e7e56ad07e7202d6fd8b93f659d7 Mon Sep 17 00:00:00 2001 From: Falko Habel Date: Mon, 21 Apr 2025 22:59:34 +0200 Subject: [PATCH 04/10] added an example --- example.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 example.md diff --git a/example.md b/example.md new file mode 100644 index 0000000..c2a870c --- /dev/null +++ b/example.md @@ -0,0 +1,16 @@ +my_project/ +├── src/ +│ ├── __init__.py # init file +│ ├── main.py +│ └── utils.py +├── tests/ +│ ├── __init__.py +│ ├── test_main.py +│ └── test_utils.py +├── data/ +│ └── sample_data.csv +├── docs/ +│ └── README.md +├── .gitignore +├── requirements.txt +└── setup.py \ No newline at end of file From 64596eaf4621ce74445aa81e28eb9701ab63818c Mon Sep 17 00:00:00 2001 From: Falko Habel Date: Tue, 22 Apr 2025 15:51:32 +0200 Subject: [PATCH 05/10] fixed display for tree_structurer --- src/prodir/cpp/tree_structurer.cpp | 176 +++++++++-------------------- 1 file changed, 51 insertions(+), 125 deletions(-) diff --git a/src/prodir/cpp/tree_structurer.cpp b/src/prodir/cpp/tree_structurer.cpp index fe31f25..6a961d9 100644 --- a/src/prodir/cpp/tree_structurer.cpp +++ b/src/prodir/cpp/tree_structurer.cpp @@ -123,7 +123,6 @@ std::vector TreeStructurer::get_filtered_paths(const fs::path& start) std::vector TreeStructurer::get_directory_structure(const std::string& startpath) { std::vector result; - // Normalize the input path by removing ./ or .\ prefix if present std::string normalized_path = startpath; if (normalized_path.size() >= 2 && (normalized_path.substr(0, 2) == ".\\" || normalized_path.substr(0, 2) == "./")) { @@ -140,144 +139,70 @@ std::vector TreeStructurer::get_directory_structure(const std::stri throw std::runtime_error("Path is not a directory: " + start.string()); } - // Start with the root node - std::string root_name = start.filename().string(); - result.push_back(root_name + "/"); + // Get all paths and sort them + std::vector paths; + std::map> dir_contents; - // First, collect all paths and organize them by their parent directories - std::map> dir_contents; - std::vector dir_paths; // To maintain order of directories - - // Add root directory - dir_contents["/"] = {}; - dir_paths.push_back("/"); - - // Collect files and directories - for (const auto& entry : fs::recursive_directory_iterator(start)) { - const auto& path = entry.path(); - std::string rel_path = get_relative_path(path, start); - - // Replace backslashes with forward slashes - std::replace(rel_path.begin(), rel_path.end(), '\\', '/'); - - // Skip if it should be ignored - bool should_skip = false; - for (const auto& component : path) { - if (should_ignore_dir(component.string())) { - should_skip = true; - break; - } - } - if (should_skip) continue; - + // First, collect all paths + for (const auto& entry : fs::directory_iterator(start)) { + fs::path path = entry.path(); if (entry.is_directory()) { - if (should_ignore_dir(path.filename().string())) { - continue; - } - - // Add directory to its parent - std::string parent_path = "/"; - size_t last_slash = rel_path.find_last_of('/'); - if (last_slash != std::string::npos) { - parent_path = rel_path.substr(0, last_slash); - if (parent_path.empty()) { - parent_path = "/"; + if (!should_ignore_dir(path.filename().string())) { + paths.push_back(path); + // Collect contents of this directory + for (const auto& subentry : fs::directory_iterator(path)) { + if (!should_ignore_file(subentry.path().filename().string()) && + !should_ignore_dir(subentry.path().filename().string())) { + dir_contents[path].push_back(subentry.path()); + } } } - - // Create parent directory entry if it doesn't exist - if (dir_contents.find(parent_path) == dir_contents.end()) { - dir_contents[parent_path] = {}; - dir_paths.push_back(parent_path); - } - - // Create directory entry - dir_contents[parent_path].push_back(path); - - // Create entry for this directory's contents - dir_contents[rel_path] = {}; - dir_paths.push_back(rel_path); } else { - if (should_ignore_file(path.filename().string())) { - continue; + if (!should_ignore_file(path.filename().string())) { + paths.push_back(path); } - - // Add file to its parent - std::string parent_path = "/"; - size_t last_slash = rel_path.find_last_of('/'); - if (last_slash != std::string::npos) { - parent_path = rel_path.substr(0, last_slash); - if (parent_path.empty()) { - parent_path = "/"; - } - } - - // Create parent directory entry if it doesn't exist - if (dir_contents.find(parent_path) == dir_contents.end()) { - dir_contents[parent_path] = {}; - dir_paths.push_back(parent_path); - } - - dir_contents[parent_path].push_back(path); } } - // Now create the tree structure - std::function&)> - build_tree = [&](const std::string& dir_path, const std::string& prefix, std::vector& is_last_stack) { - // Sort paths - directories first, then files - std::vector& paths = dir_contents[dir_path]; - std::sort(paths.begin(), paths.end(), [](const fs::path& a, const fs::path& b) { - bool a_is_dir = fs::is_directory(a); - bool b_is_dir = fs::is_directory(b); - if (a_is_dir != b_is_dir) { - return a_is_dir > b_is_dir; // Directories before files - } - return a.filename() < b.filename(); // Alphabetical order - }); + // Sort paths + std::sort(paths.begin(), paths.end()); + for (auto& [dir, contents] : dir_contents) { + std::sort(contents.begin(), contents.end()); + } + + // Add root directory + std::string root_name = start.filename().string(); + result.push_back(root_name + "/"); + + // Process each path + for (size_t i = 0; i < paths.size(); ++i) { + bool is_last = (i == paths.size() - 1); + std::string line = is_last ? "└── " : "├── "; - // Add entries for this directory - for (size_t i = 0; i < paths.size(); ++i) { - const auto& path = paths[i]; - bool is_last = (i == paths.size() - 1); - - // Build the line prefix - std::string line_prefix = prefix; - if (!prefix.empty()) { - line_prefix += is_last ? "└── " : "├── "; - } - - // Add the file/directory name - std::string name = path.filename().string(); - std::string line = line_prefix + name; - - if (fs::is_directory(path)) { - line += "/"; - } - - result.push_back(line); - - // If it's a directory, process its contents with updated prefix - if (fs::is_directory(path)) { - std::string rel_path = get_relative_path(path, start); - std::replace(rel_path.begin(), rel_path.end(), '\\', '/'); + std::string name = paths[i].filename().string(); + if (fs::is_directory(paths[i])) { + name += "/"; + } + line += name; + result.push_back(line); + + // If it's a directory, process its contents + if (fs::is_directory(paths[i])) { + const auto& contents = dir_contents[paths[i]]; + for (size_t j = 0; j < contents.size(); ++j) { + bool is_last_child = (j == contents.size() - 1); + std::string child_line = is_last ? " " : "│ "; + child_line += is_last_child ? "└── " : "├── "; - std::string next_prefix = prefix; - if (!prefix.empty()) { - next_prefix += is_last ? " " : "│ "; + std::string child_name = contents[j].filename().string(); + if (fs::is_directory(contents[j])) { + child_name += "/"; } - - std::vector next_is_last_stack = is_last_stack; - next_is_last_stack.push_back(is_last); - - build_tree(rel_path, next_prefix, next_is_last_stack); + child_line += child_name; + result.push_back(child_line); } } - }; - - // Start building the tree from the root - std::vector is_last_stack; - build_tree("/", "", is_last_stack); + } } catch (const fs::filesystem_error& e) { throw std::runtime_error("Failed to access directory: " + std::string(e.what())); @@ -286,6 +211,7 @@ std::vector TreeStructurer::get_directory_structure(const std::stri return result; } + // ----------------------------------------------------------------------------- // Structure Creation from a Tree-like File or String // ----------------------------------------------------------------------------- From e230128be035f154cb86928b13b01e8a3812f192 Mon Sep 17 00:00:00 2001 From: Falko Habel Date: Tue, 22 Apr 2025 17:06:24 +0200 Subject: [PATCH 06/10] added missing requirements --- .vscode/settings.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 5dc5c07..c145493 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -70,6 +70,8 @@ "xutility": "cpp", "fstream": "cpp", "iostream": "cpp", - "codecvt": "cpp" + "codecvt": "cpp", + "map": "cpp", + "xtree": "cpp" } } \ No newline at end of file From 2a034e9c0e61e1ff2fd40cb3f81b696f6852470f Mon Sep 17 00:00:00 2001 From: Falko Habel Date: Tue, 22 Apr 2025 17:07:30 +0200 Subject: [PATCH 07/10] updated folder printing with better loooking ui and removed debu prints --- src/prodir/cpp/tree_structurer.cpp | 106 +++++++++++------------------ 1 file changed, 39 insertions(+), 67 deletions(-) diff --git a/src/prodir/cpp/tree_structurer.cpp b/src/prodir/cpp/tree_structurer.cpp index 6a961d9..ad33960 100644 --- a/src/prodir/cpp/tree_structurer.cpp +++ b/src/prodir/cpp/tree_structurer.cpp @@ -138,70 +138,50 @@ std::vector TreeStructurer::get_directory_structure(const std::stri if (!fs::is_directory(start)) { throw std::runtime_error("Path is not a directory: " + start.string()); } + + std::vector paths = get_filtered_paths(start); + std::vector is_last_per_level; - // Get all paths and sort them - std::vector paths; - std::map> dir_contents; - - // First, collect all paths - for (const auto& entry : fs::directory_iterator(start)) { - fs::path path = entry.path(); - if (entry.is_directory()) { - if (!should_ignore_dir(path.filename().string())) { - paths.push_back(path); - // Collect contents of this directory - for (const auto& subentry : fs::directory_iterator(path)) { - if (!should_ignore_file(subentry.path().filename().string()) && - !should_ignore_dir(subentry.path().filename().string())) { - dir_contents[path].push_back(subentry.path()); - } - } - } - } else { - if (!should_ignore_file(path.filename().string())) { - paths.push_back(path); - } + // Skip the first path as it's the root + for (size_t i = 1; i < paths.size(); ++i) { + fs::path relative = fs::relative(paths[i], start); + std::vector components; + for (const auto& comp : relative) { + components.push_back(comp.string()); } - } - - // Sort paths - std::sort(paths.begin(), paths.end()); - for (auto& [dir, contents] : dir_contents) { - std::sort(contents.begin(), contents.end()); - } - - // Add root directory - std::string root_name = start.filename().string(); - result.push_back(root_name + "/"); - - // Process each path - for (size_t i = 0; i < paths.size(); ++i) { - bool is_last = (i == paths.size() - 1); - std::string line = is_last ? "└── " : "├── "; - std::string name = paths[i].filename().string(); - if (fs::is_directory(paths[i])) { - name += "/"; + // Calculate the current level + size_t level = components.size() - 1; + + // Adjust is_last_per_level vector size + while (is_last_per_level.size() <= level) { + is_last_per_level.push_back(false); } - line += name; + + // Determine if this is the last item at its level + bool is_last = (i == paths.size() - 1) || + (i + 1 < paths.size() && + fs::relative(paths[i + 1], start).begin()->string() != components[0]); + + is_last_per_level[level] = is_last; + + // Build the line prefix + std::string line; + for (size_t j = 0; j < level; ++j) { + if (j == level - 1) { + line += is_last ? "└── " : "├── "; + } else { + line += is_last_per_level[j] ? " " : "│ "; + } + } + + // Add the file/directory name + line += components.back(); + if (fs::is_directory(paths[i])) { + line += "/"; + } + result.push_back(line); - - // If it's a directory, process its contents - if (fs::is_directory(paths[i])) { - const auto& contents = dir_contents[paths[i]]; - for (size_t j = 0; j < contents.size(); ++j) { - bool is_last_child = (j == contents.size() - 1); - std::string child_line = is_last ? " " : "│ "; - child_line += is_last_child ? "└── " : "├── "; - - std::string child_name = contents[j].filename().string(); - if (fs::is_directory(contents[j])) { - child_name += "/"; - } - child_line += child_name; - result.push_back(child_line); - } - } } } catch (const fs::filesystem_error& e) { @@ -211,7 +191,6 @@ std::vector TreeStructurer::get_directory_structure(const std::stri return result; } - // ----------------------------------------------------------------------------- // Structure Creation from a Tree-like File or String // ----------------------------------------------------------------------------- @@ -453,8 +432,6 @@ std::vector TreeStructurer::read_structure_file(const std::string& line.pop_back(); } - std::cout << "Processing line: " << line << std::endl; - size_t hash_pos = line.find('#'); size_t single_line_comment_pos = line.find("//"); size_t multi_line_comment_start_pos = line.find("/*"); @@ -462,15 +439,12 @@ std::vector TreeStructurer::read_structure_file(const std::string& if (hash_pos != std::string::npos) { // Trim the line at the hash comment line = line.substr(0, hash_pos); - std::cout << "Trimmed line at hash comment position: " << hash_pos << std::endl; } else if (single_line_comment_pos != std::string::npos) { // Trim the line at the single-line comment line = line.substr(0, single_line_comment_pos); - std::cout << "Trimmed line at single-line comment position: " << single_line_comment_pos << std::endl; } else if (multi_line_comment_start_pos != std::string::npos) { // Trim the line at the multi-line comment start line = line.substr(0, multi_line_comment_start_pos); - std::cout << "Trimmed line at multi-line comment start position: " << multi_line_comment_start_pos << std::endl; } // Remove leading and trailing whitespace @@ -479,9 +453,7 @@ std::vector TreeStructurer::read_structure_file(const std::string& if (!line.empty()) { lines.push_back(line); - std::cout << "Added non-empty line: " << line << std::endl; } else { - std::cout << "Skipped empty or commented-out line." << std::endl; } } From eec232ae53574d72baeabdd4b655900c5afe208a Mon Sep 17 00:00:00 2001 From: Falko Habel Date: Tue, 22 Apr 2025 17:07:46 +0200 Subject: [PATCH 08/10] updated the verbose handling for new version --- src/prodir/__main__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/prodir/__main__.py b/src/prodir/__main__.py index f6beed9..6c8f796 100644 --- a/src/prodir/__main__.py +++ b/src/prodir/__main__.py @@ -69,10 +69,9 @@ def main(): create_tree_structurer() if args.command == 'display': - if args.verbose: - print(f"Analyzing directory: {args.path}") try: structure = get_structure(args.path) + print(f"Analyzing directory: {args.path}") for line in structure: print(line) except FileNotFoundError: From 048c275b555851aefebfbcce175a7671a9132fc9 Mon Sep 17 00:00:00 2001 From: Falko Habel Date: Tue, 22 Apr 2025 17:07:52 +0200 Subject: [PATCH 09/10] updated tests --- tests/test__main__.py | 52 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/tests/test__main__.py b/tests/test__main__.py index 8f136b3..6381df7 100644 --- a/tests/test__main__.py +++ b/tests/test__main__.py @@ -67,16 +67,50 @@ def test_display_verbose(tmp_path): # Only check if we got any output, ignoring encoding errors assert stdout != "" or stderr != "" + +# ... rest of code here ... + +# ... rest of code here ... + def test_create_directory_from_file(tmp_path): - structure_file = tmp_path / 'structure.txt' - structure_content = "dir1/\n file1.txt" - structure_file.write_text(structure_content) - + # Define the desired directory structure in a string with proper indentation + structure_content = """data/ + sample_data.csv +docs/ + README.md +requirements.txt +setup.py +src/ + __init__.py + main.py + utils.py +tests/ + __init__.py + test_main.py + test_utils.py""" + + output_dir = tmp_path / 'output' output_dir.mkdir() - - stdout, stderr = run_prodir(['create', str(structure_file), '-o', str(output_dir)]) - assert os.path.exists(output_dir / 'dir1' / 'file1.txt') + + stdout, stderr = run_prodir(['create', "example.md" '-o']) + + # Print the stdout and stderr for debugging + print("stdout:", stdout) + print("stderr:", stderr) + + + assert os.path.exists('my_project/data/sample_data.csv') + assert os.path.exists('my_project/docs/README.md') + assert os.path.exists('my_project/requirements.txt') + assert os.path.exists('my_project/setup.py') + assert os.path.exists('my_project/src/__init__.py') + assert os.path.exists('my_project/src/main.py') + assert os.path.exists('my_project/src/utils.py') + assert os.path.exists('my_project/tests/__init__.py') + assert os.path.exists('my_project/tests/test_main.py') + assert os.path.exists('my_project/tests/test_utils.py') + def test_create_verbose(tmp_path): structure_file = tmp_path / 'structure.txt' @@ -86,9 +120,9 @@ def test_create_verbose(tmp_path): output_dir = tmp_path / 'output' output_dir.mkdir() - stdout, stderr = run_prodir(['create', str(structure_file), '-o', str(output_dir), '-v']) + stdout, stderr = run_prodir(['create', "example.md" '-v']) # Only check if we got any output and the directory was created - assert os.path.exists(output_dir / 'dir1' / 'file1.txt') + assert os.path.exists( 'my_project/requirements.txt') def test_display_invalid_path(): # Use an absolute path with some random UUID to ensure it doesn't exist From 59957781c0c273989d8b1c19594f3167a752a8ae Mon Sep 17 00:00:00 2001 From: Falko Habel Date: Tue, 22 Apr 2025 17:08:14 +0200 Subject: [PATCH 10/10] new version !!1 --- pyproject.toml | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 0d7ded4..830f41b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "prodir" -version = "1.0.0" +version = "1.0.1" description = "A module for analyzing and creating directory structures" scripts = {prodir = "prodir.__main__:main"} dependencies = [] diff --git a/setup.py b/setup.py index 190d430..a06be42 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ tree_structurer_module = Extension( setup( name='prodir', - version='1.0.0', + version='1.0.1', description='A module for analyzing directory structures', ext_modules=[tree_structurer_module], packages=find_packages(where="src"),