Merge pull request 'Quickfix' (#4) from Quickfix into develop
Gitea Actions For Tree-Structurer / Explore-Gitea-Actions (push) Successful in 9m20s
Details
Gitea Actions For Tree-Structurer / Explore-Gitea-Actions (push) Successful in 9m20s
Details
Reviewed-on: Fabel/Tree-Structurer#4
This commit is contained in:
commit
2d3813fc44
|
@ -0,0 +1,37 @@
|
||||||
|
name: Run VectorLoader Script
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
Explore-Gitea-Actions:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container: catthehacker/ubuntu:act-latest
|
||||||
|
steps:
|
||||||
|
- name: Check out repository code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v3
|
||||||
|
with:
|
||||||
|
python-version: '3.11.7'
|
||||||
|
|
||||||
|
- name: Clone additional repository
|
||||||
|
run: |
|
||||||
|
git config --global credential.helper cache
|
||||||
|
git clone https://fabel:${{ secrets.CICD }}@gitea.fabelous.app/fabel/VectorLoader.git
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
cd VectorLoader
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
pip install -r requirements.txt
|
||||||
|
|
||||||
|
- name: Run vectorizing
|
||||||
|
env:
|
||||||
|
VECTORDB_TOKEN: ${{ secrets.VECTORDB_TOKEN }}
|
||||||
|
run: |
|
||||||
|
cd VectorLoader
|
||||||
|
python -m src.run --full
|
|
@ -0,0 +1,36 @@
|
||||||
|
name: Gitea Actions For Tree-Structurer
|
||||||
|
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
|
||||||
|
on: [push]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
Explore-Gitea-Actions:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container: catthehacker/ubuntu:act-latest
|
||||||
|
steps:
|
||||||
|
- name: Check out repository code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: '3.11.7'
|
||||||
|
|
||||||
|
- name: Cache pip and model
|
||||||
|
uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.cache/pip
|
||||||
|
./fabel
|
||||||
|
key: ${{ runner.os }}-pip-model-${{ hashFiles('requirements-dev.txt')}}
|
||||||
|
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-pip-model-
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
pip install -r requirements-dev.txt
|
||||||
|
- name: Run tests
|
||||||
|
run: |
|
||||||
|
pip install -e .
|
||||||
|
pytest tests
|
|
@ -0,0 +1,6 @@
|
||||||
|
[pytest]
|
||||||
|
python_files = test_*.py
|
||||||
|
python_classes = Test*
|
||||||
|
python_functions = test_*
|
||||||
|
addopts = -v --tb=short
|
||||||
|
testpaths = tests
|
|
@ -0,0 +1,11 @@
|
||||||
|
[tool:pytest]
|
||||||
|
minversion = 6.0
|
||||||
|
addopts = -ra -q
|
||||||
|
testpaths =
|
||||||
|
tests
|
||||||
|
python_files =
|
||||||
|
test_*.py
|
||||||
|
*_test.py
|
||||||
|
markers =
|
||||||
|
slow: marks tests as slow (deselect with '-m "not slow"')
|
||||||
|
integration: marks tests as integration tests
|
2
setup.py
2
setup.py
|
@ -20,7 +20,7 @@ tree_structurer_module = Extension(
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='tree_structurer',
|
name='tree_structurer',
|
||||||
version='0.0.5',
|
version='0.0.6',
|
||||||
description='A module for analyzing directory structures',
|
description='A module for analyzing directory structures',
|
||||||
ext_modules=[tree_structurer_module],
|
ext_modules=[tree_structurer_module],
|
||||||
packages=['tree_structurer'],
|
packages=['tree_structurer'],
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
import os
|
||||||
|
import pytest
|
||||||
|
import shutil
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def temp_directory(tmp_path):
|
||||||
|
"""Create a temporary directory structure for testing."""
|
||||||
|
# Create main test directory
|
||||||
|
test_dir = tmp_path / "test_project"
|
||||||
|
test_dir.mkdir()
|
||||||
|
|
||||||
|
# Create some regular directories
|
||||||
|
(test_dir / "src").mkdir()
|
||||||
|
(test_dir / "src" / "utils").mkdir()
|
||||||
|
(test_dir / "docs").mkdir()
|
||||||
|
|
||||||
|
# Create some files
|
||||||
|
(test_dir / "src" / "main.py").write_text("print('hello')")
|
||||||
|
(test_dir / "src" / "utils" / "helper.py").write_text("# helper")
|
||||||
|
(test_dir / "src" / "__init__.py").touch()
|
||||||
|
(test_dir / "README.md").write_text("# Test Project")
|
||||||
|
|
||||||
|
# Create some directories that should be ignored
|
||||||
|
(test_dir / "__pycache__").mkdir()
|
||||||
|
(test_dir / ".git").mkdir()
|
||||||
|
(test_dir / "venv").mkdir()
|
||||||
|
|
||||||
|
# Create some files that should be ignored
|
||||||
|
(test_dir / "src" / "main.pyc").touch()
|
||||||
|
(test_dir / ".gitignore").touch()
|
||||||
|
|
||||||
|
yield test_dir
|
|
@ -0,0 +1,89 @@
|
||||||
|
import pytest
|
||||||
|
from pathlib import Path
|
||||||
|
from tree_structurer import create_tree_structurer, get_structure
|
||||||
|
|
||||||
|
def test_basic_structure(temp_directory):
|
||||||
|
"""Test that the basic directory structure is correctly represented."""
|
||||||
|
create_tree_structurer()
|
||||||
|
structure = get_structure(str(temp_directory))
|
||||||
|
|
||||||
|
# Convert structure to set for easier comparison
|
||||||
|
structure_set = set(structure)
|
||||||
|
|
||||||
|
# Print actual structure for debugging
|
||||||
|
print("\nActual structure:")
|
||||||
|
for line in structure:
|
||||||
|
print(f"'{line}'")
|
||||||
|
|
||||||
|
# Expected entries (adjusted based on actual implementation)
|
||||||
|
must_contain = [
|
||||||
|
"README.md",
|
||||||
|
"docs",
|
||||||
|
"src",
|
||||||
|
"__init__.py",
|
||||||
|
"main.py",
|
||||||
|
"utils",
|
||||||
|
"helper.py"
|
||||||
|
]
|
||||||
|
|
||||||
|
# Check that all required components are present somewhere in the structure
|
||||||
|
for entry in must_contain:
|
||||||
|
assert any(entry in line for line in structure), \
|
||||||
|
f"Required entry '{entry}' not found in structure"
|
||||||
|
|
||||||
|
# Check that ignored directories/files are not present
|
||||||
|
ignored_patterns = {
|
||||||
|
"__pycache__",
|
||||||
|
".git",
|
||||||
|
"venv",
|
||||||
|
"main.pyc",
|
||||||
|
".gitignore"
|
||||||
|
}
|
||||||
|
|
||||||
|
for entry in structure:
|
||||||
|
for ignored in ignored_patterns:
|
||||||
|
assert ignored not in entry, \
|
||||||
|
f"Ignored pattern '{ignored}' found in entry '{entry}'"
|
||||||
|
|
||||||
|
def test_empty_directory(tmp_path):
|
||||||
|
"""Test handling of an empty directory."""
|
||||||
|
create_tree_structurer()
|
||||||
|
try:
|
||||||
|
structure = get_structure(str(tmp_path))
|
||||||
|
pytest.fail("Expected an exception for nonexistent directory")
|
||||||
|
except Exception as e: # Changed from RuntimeError
|
||||||
|
assert "Directory is empty" in str(e)
|
||||||
|
|
||||||
|
def test_nonexistent_directory():
|
||||||
|
"""Test handling of a nonexistent directory."""
|
||||||
|
create_tree_structurer()
|
||||||
|
try:
|
||||||
|
get_structure("/path/that/does/not/exist")
|
||||||
|
pytest.fail("Expected an exception for nonexistent directory")
|
||||||
|
except Exception as e: # Changed from RuntimeError
|
||||||
|
assert "Directory does not exist" in str(e)
|
||||||
|
|
||||||
|
def test_nested_structure(temp_directory):
|
||||||
|
"""Test deeply nested directory structure."""
|
||||||
|
# Create deep nested structure
|
||||||
|
deep_path = temp_directory / "deep" / "nested" / "structure"
|
||||||
|
deep_path.mkdir(parents=True)
|
||||||
|
(deep_path / "test.py").touch()
|
||||||
|
|
||||||
|
create_tree_structurer()
|
||||||
|
structure = get_structure(str(temp_directory))
|
||||||
|
|
||||||
|
# Print actual structure for debugging
|
||||||
|
print("\nDeep structure:")
|
||||||
|
for line in structure:
|
||||||
|
print(f"'{line}'")
|
||||||
|
|
||||||
|
# Verify that all components of the deep path are present
|
||||||
|
deep_components = ["deep", "nested", "structure", "test.py"]
|
||||||
|
for component in deep_components:
|
||||||
|
assert any(component in line for line in structure), \
|
||||||
|
f"Deep component '{component}' not found in structure"
|
||||||
|
|
||||||
|
# Verify tree-like formatting is present
|
||||||
|
assert any("└" in line or "├" in line for line in structure), \
|
||||||
|
"Tree-like formatting characters not found in structure"
|
|
@ -14,15 +14,23 @@ def main():
|
||||||
try:
|
try:
|
||||||
if args.verbose:
|
if args.verbose:
|
||||||
print(f"Analyzing directory: {args.path}")
|
print(f"Analyzing directory: {args.path}")
|
||||||
|
|
||||||
create_tree_structurer()
|
create_tree_structurer()
|
||||||
# Get and print structure directly
|
|
||||||
structure = get_structure(args.path)
|
structure = get_structure(args.path)
|
||||||
|
|
||||||
for line in structure:
|
for line in structure:
|
||||||
print(line)
|
print(line)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error: {e}", file=sys.stderr)
|
error_msg = str(e)
|
||||||
|
if "Directory does not exist" in error_msg:
|
||||||
|
print(f"Error: The specified directory does not exist: {args.path}", file=sys.stderr)
|
||||||
|
elif "Directory is empty" in error_msg:
|
||||||
|
print(f"Error: The specified directory is empty: {args.path}", file=sys.stderr)
|
||||||
|
elif "Path is not a directory" in error_msg:
|
||||||
|
print(f"Error: The specified path is not a directory: {args.path}", file=sys.stderr)
|
||||||
|
else:
|
||||||
|
print(f"Error: {error_msg}", file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
|
@ -66,29 +66,41 @@ std::vector<fs::path> TreeStructurer::get_filtered_paths(const fs::path& start)
|
||||||
fs::directory_options options = fs::directory_options::skip_permission_denied;
|
fs::directory_options options = fs::directory_options::skip_permission_denied;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (fs::exists(start) && fs::is_directory(start)) {
|
if (!fs::exists(start)) {
|
||||||
paths.push_back(start);
|
throw std::runtime_error("Directory does not exist: " + start.string());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fs::is_directory(start)) {
|
||||||
|
throw std::runtime_error("Path is not a directory: " + start.string());
|
||||||
|
}
|
||||||
|
|
||||||
for (const auto& entry : fs::recursive_directory_iterator(start, options)) {
|
paths.push_back(start);
|
||||||
const auto& path = entry.path();
|
|
||||||
|
|
||||||
bool should_skip = false;
|
// Check if directory is empty
|
||||||
for (const auto& component : path) {
|
bool is_empty = fs::directory_iterator(start) == fs::directory_iterator();
|
||||||
if (should_ignore_dir(component.string())) {
|
if (is_empty) {
|
||||||
should_skip = true;
|
throw std::runtime_error("Directory is empty: " + start.string());
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
for (const auto& entry : fs::recursive_directory_iterator(start, options)) {
|
||||||
|
const auto& path = entry.path();
|
||||||
|
|
||||||
|
bool should_skip = false;
|
||||||
|
for (const auto& component : path) {
|
||||||
|
if (should_ignore_dir(component.string())) {
|
||||||
|
should_skip = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (should_skip) continue;
|
}
|
||||||
|
if (should_skip) continue;
|
||||||
|
|
||||||
if (entry.is_directory()) {
|
if (entry.is_directory()) {
|
||||||
if (!should_ignore_dir(path.filename().string())) {
|
if (!should_ignore_dir(path.filename().string())) {
|
||||||
paths.push_back(path);
|
paths.push_back(path);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!should_ignore_file(path.filename().string())) {
|
if (!should_ignore_file(path.filename().string())) {
|
||||||
paths.push_back(path);
|
paths.push_back(path);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,14 +125,9 @@ std::vector<std::string> TreeStructurer::get_directory_structure(const std::stri
|
||||||
|
|
||||||
try {
|
try {
|
||||||
auto paths = get_filtered_paths(start);
|
auto paths = get_filtered_paths(start);
|
||||||
if (paths.empty()) return result;
|
if (paths.empty()) {
|
||||||
|
throw std::runtime_error("No valid files or directories found in: " + start.string());
|
||||||
// Don't add the start directory name to the output
|
}
|
||||||
// Remove the following lines:
|
|
||||||
// if (start != fs::current_path()) {
|
|
||||||
// result.push_back(start.filename().string());
|
|
||||||
// }
|
|
||||||
|
|
||||||
std::vector<bool> is_last_at_level(256, false);
|
std::vector<bool> is_last_at_level(256, false);
|
||||||
|
|
||||||
for (size_t i = 1; i < paths.size(); ++i) {
|
for (size_t i = 1; i < paths.size(); ++i) {
|
||||||
|
|
Loading…
Reference in New Issue