Compare commits
No commits in common. "40e55ca55a5b72cf1f27fb95404ffbc70ecea397" and "9907388a14e81274f8d01cc50eaedf98ae75a892" have entirely different histories.
40e55ca55a
...
9907388a14
|
@ -34,4 +34,4 @@ jobs:
|
||||||
VECTORDB_TOKEN: ${{ secrets.VECTORDB_TOKEN }}
|
VECTORDB_TOKEN: ${{ secrets.VECTORDB_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
cd VectorLoader
|
cd VectorLoader
|
||||||
python -m src.run
|
python -m src.run --full
|
||||||
|
|
|
@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "prodir"
|
name = "prodir"
|
||||||
version = "0.0.8"
|
version = "0.0.7"
|
||||||
description = "A module for analyzing and creating directory structures"
|
description = "A module for analyzing and creating directory structures"
|
||||||
scripts = {prodir = "prodir.__main__:main"}
|
scripts = {prodir = "prodir.__main__:main"}
|
||||||
dependencies = []
|
dependencies = []
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -20,7 +20,7 @@ tree_structurer_module = Extension(
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='prodir',
|
name='prodir',
|
||||||
version='0.0.9',
|
version='0.0.7',
|
||||||
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=find_packages(where="src"),
|
packages=find_packages(where="src"),
|
||||||
|
|
|
@ -8,9 +8,7 @@ from prodir import (
|
||||||
)
|
)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# Create the main parser
|
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
prog='prodir', # Set program name to prodir
|
|
||||||
description='Directory structure tool: Display and create directory structures'
|
description='Directory structure tool: Display and create directory structures'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -18,9 +16,7 @@ def main():
|
||||||
subparsers = parser.add_subparsers(dest='command', help='Available commands')
|
subparsers = parser.add_subparsers(dest='command', help='Available commands')
|
||||||
|
|
||||||
# Display command
|
# Display command
|
||||||
display_parser = subparsers.add_parser('display',
|
display_parser = subparsers.add_parser('display', help='Display directory structure')
|
||||||
prog='prodir display', # Set display command name
|
|
||||||
help='Display directory structure')
|
|
||||||
display_parser.add_argument(
|
display_parser.add_argument(
|
||||||
'path',
|
'path',
|
||||||
nargs='?',
|
nargs='?',
|
||||||
|
@ -34,9 +30,7 @@ def main():
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create command
|
# Create command
|
||||||
create_parser = subparsers.add_parser('create',
|
create_parser = subparsers.add_parser('create', help='Create directory structure')
|
||||||
prog='prodir create', # Set create command name
|
|
||||||
help='Create directory structure')
|
|
||||||
create_parser.add_argument(
|
create_parser.add_argument(
|
||||||
'file',
|
'file',
|
||||||
help='File containing the directory structure'
|
help='File containing the directory structure'
|
||||||
|
@ -52,14 +46,9 @@ def main():
|
||||||
help='Show more detailed output'
|
help='Show more detailed output'
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check if a direct path was provided
|
|
||||||
if len(sys.argv) > 1 and not sys.argv[1].startswith('-') and not sys.argv[1] in ['display', 'create']:
|
|
||||||
# Convert to display command with path
|
|
||||||
sys.argv.insert(1, 'display')
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# If no command is specified, use display with current directory
|
# If no command is specified, default to display
|
||||||
if not args.command:
|
if not args.command:
|
||||||
args.command = 'display'
|
args.command = 'display'
|
||||||
args.path = os.getcwd()
|
args.path = os.getcwd()
|
||||||
|
@ -71,47 +60,42 @@ def main():
|
||||||
if args.command == 'display':
|
if args.command == 'display':
|
||||||
if args.verbose:
|
if args.verbose:
|
||||||
print(f"Analyzing directory: {args.path}")
|
print(f"Analyzing directory: {args.path}")
|
||||||
try:
|
|
||||||
structure = get_structure(args.path)
|
structure = get_structure(args.path)
|
||||||
for line in structure:
|
for line in structure:
|
||||||
print(line)
|
print(line)
|
||||||
except FileNotFoundError:
|
|
||||||
print("Error: Directory does not exist", file=sys.stderr)
|
|
||||||
sys.exit(1)
|
|
||||||
except Exception as e:
|
|
||||||
print(f"Error: {str(e)}", file=sys.stderr)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
elif args.command == 'create':
|
elif args.command == 'create':
|
||||||
if args.verbose:
|
if args.verbose:
|
||||||
print(f"Creating directory structure in: {args.output}")
|
print(f"Creating directory structure in: {args.output}")
|
||||||
print(f"Using structure from file: {args.file}")
|
print(f"Using structure from file: {args.file}")
|
||||||
|
|
||||||
# Check if the output path exists
|
|
||||||
if not os.path.exists(args.output):
|
|
||||||
print(f"Error: The specified output path '{args.output}' does not exist.", file=sys.stderr)
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
try:
|
|
||||||
create_structure_from_file(args.file, args.output)
|
create_structure_from_file(args.file, args.output)
|
||||||
|
|
||||||
if args.verbose:
|
if args.verbose:
|
||||||
print("Structure created successfully")
|
print("Structure created successfully")
|
||||||
print("\nResulting structure:")
|
print("\nResulting structure:")
|
||||||
structure = get_structure(args.output)
|
structure = get_structure(args.output)
|
||||||
for line in structure:
|
for line in structure:
|
||||||
print(line)
|
print(line)
|
||||||
except FileNotFoundError as e:
|
|
||||||
if 'structure file' in str(e):
|
|
||||||
print("Error: Unable to open structure file", file=sys.stderr)
|
|
||||||
else:
|
|
||||||
print("Error: Directory does not exist", file=sys.stderr)
|
|
||||||
sys.exit(1)
|
|
||||||
except Exception as e:
|
|
||||||
print(f"Error: {str(e)}", file=sys.stderr)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error: {str(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 if args.command == 'display' else args.output}",
|
||||||
|
file=sys.stderr)
|
||||||
|
elif "Directory is empty" in error_msg:
|
||||||
|
print(f"Error: The specified directory is empty: {args.path if args.command == 'display' else args.output}",
|
||||||
|
file=sys.stderr)
|
||||||
|
elif "Path is not a directory" in error_msg:
|
||||||
|
print(f"Error: The specified path is not a directory: {args.path if args.command == 'display' else args.output}",
|
||||||
|
file=sys.stderr)
|
||||||
|
elif "Unable to open structure file" in error_msg:
|
||||||
|
print(f"Error: Unable to open structure file: {args.file}", file=sys.stderr)
|
||||||
|
elif "Invalid structure format" in error_msg:
|
||||||
|
print(f"Error: Invalid structure format in {'file' if args.file else 'string'}", file=sys.stderr)
|
||||||
|
else:
|
||||||
|
print(f"Error: {error_msg}", file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
13
test.txt
13
test.txt
|
@ -1,13 +0,0 @@
|
||||||
project/
|
|
||||||
├── src/
|
|
||||||
│ ├── __init__.py
|
|
||||||
│ ├── main.py
|
|
||||||
│ ├── module1.py
|
|
||||||
│ └── module2.py
|
|
||||||
├── config/
|
|
||||||
│ └── config.yaml
|
|
||||||
├── .gitignore
|
|
||||||
├── pyproject.toml
|
|
||||||
├── setup.py
|
|
||||||
├── LICENSE
|
|
||||||
└── README.m
|
|
|
@ -1,121 +0,0 @@
|
||||||
import os
|
|
||||||
import tempfile
|
|
||||||
import subprocess
|
|
||||||
import sys
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
def run_prodir(command):
|
|
||||||
"""Helper function to run the prodir command and capture output"""
|
|
||||||
try:
|
|
||||||
# Use sys.executable to ensure we're using the correct Python interpreter
|
|
||||||
env = os.environ.copy()
|
|
||||||
env["PYTHONIOENCODING"] = "utf-8" # Force UTF-8 encoding
|
|
||||||
result = subprocess.run(
|
|
||||||
[sys.executable, '-m', 'prodir'] + command,
|
|
||||||
capture_output=True,
|
|
||||||
text=True,
|
|
||||||
encoding='utf-8',
|
|
||||||
env=env
|
|
||||||
)
|
|
||||||
return result.stdout, result.stderr
|
|
||||||
except Exception as e:
|
|
||||||
return "", str(e)
|
|
||||||
|
|
||||||
def test_help_message():
|
|
||||||
stdout, stderr = run_prodir(["-h"])
|
|
||||||
assert "usage: prodir" in stdout
|
|
||||||
assert stderr == ""
|
|
||||||
|
|
||||||
def test_direct_path():
|
|
||||||
stdout, stderr = run_prodir([os.getcwd()])
|
|
||||||
# Only check if we got any output, ignoring encoding errors
|
|
||||||
assert stdout != "" or stderr != ""
|
|
||||||
|
|
||||||
def test_display_help_message():
|
|
||||||
stdout, stderr = run_prodir(['display', '-h'])
|
|
||||||
assert "usage: prodir display" in stdout
|
|
||||||
assert stderr == ""
|
|
||||||
|
|
||||||
def test_create_help_message():
|
|
||||||
stdout, stderr = run_prodir(['create', '-h'])
|
|
||||||
assert "usage: prodir create" in stdout
|
|
||||||
assert stderr == ""
|
|
||||||
|
|
||||||
def test_display_current_directory():
|
|
||||||
stdout, stderr = run_prodir(['display'])
|
|
||||||
# Only check if we got any output, ignoring encoding errors
|
|
||||||
assert stdout != "" or stderr != ""
|
|
||||||
|
|
||||||
def test_display_specific_path(tmp_path):
|
|
||||||
dir_structure = tmp_path / 'test_dir'
|
|
||||||
dir_structure.mkdir()
|
|
||||||
(dir_structure / 'test_file.txt').touch()
|
|
||||||
|
|
||||||
stdout1, stderr1 = run_prodir([str(dir_structure)])
|
|
||||||
stdout2, stderr2 = run_prodir(['display', str(dir_structure)])
|
|
||||||
|
|
||||||
# Check if either stdout contains the filename or if we got encoding errors
|
|
||||||
assert ('test_file.txt' in stdout1) or ('charmap' in stderr1)
|
|
||||||
assert ('test_file.txt' in stdout2) or ('charmap' in stderr2)
|
|
||||||
|
|
||||||
def test_display_verbose(tmp_path):
|
|
||||||
dir_structure = tmp_path / 'test_dir'
|
|
||||||
dir_structure.mkdir()
|
|
||||||
(dir_structure / 'test_file.txt').touch()
|
|
||||||
|
|
||||||
stdout, stderr = run_prodir(['display', str(dir_structure), '-v'])
|
|
||||||
# Only check if we got any output, ignoring encoding errors
|
|
||||||
assert stdout != "" or stderr != ""
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
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')
|
|
||||||
|
|
||||||
def test_create_verbose(tmp_path):
|
|
||||||
structure_file = tmp_path / 'structure.txt'
|
|
||||||
structure_content = "dir1/\n file1.txt"
|
|
||||||
structure_file.write_text(structure_content)
|
|
||||||
|
|
||||||
output_dir = tmp_path / 'output'
|
|
||||||
output_dir.mkdir()
|
|
||||||
|
|
||||||
stdout, stderr = run_prodir(['create', str(structure_file), '-o', str(output_dir), '-v'])
|
|
||||||
# Only check if we got any output and the directory was created
|
|
||||||
assert os.path.exists(output_dir / 'dir1' / 'file1.txt')
|
|
||||||
|
|
||||||
def test_display_invalid_path():
|
|
||||||
# Use an absolute path with some random UUID to ensure it doesn't exist
|
|
||||||
import uuid
|
|
||||||
invalid_path = f"/tmp/definitely-does-not-exist-{uuid.uuid4()}"
|
|
||||||
stdout, stderr = run_prodir(['display', invalid_path])
|
|
||||||
if stderr: # Only check stderr if it's not empty
|
|
||||||
assert any(msg in stderr.lower() for msg in [
|
|
||||||
"does not exist",
|
|
||||||
"invalid path",
|
|
||||||
"no such file or directory",
|
|
||||||
"the specified path does not exist"
|
|
||||||
])
|
|
||||||
else:
|
|
||||||
assert stdout == "" # If no stderr, stdout should be empty
|
|
||||||
|
|
||||||
def test_create_invalid_file(tmp_path):
|
|
||||||
stdout, stderr = run_prodir(['create', str(tmp_path / 'nonexistent.txt'), '-o', str(tmp_path)])
|
|
||||||
assert "Error: Failed to open file:" in stderr or "does not exist" in stderr.lower()
|
|
||||||
|
|
||||||
def test_create_invalid_output_directory(tmp_path):
|
|
||||||
structure_file = tmp_path / 'structure.txt'
|
|
||||||
structure_content = "dir1/\n file1.txt"
|
|
||||||
structure_file.write_text(structure_content)
|
|
||||||
|
|
||||||
nonexistent_output = tmp_path / 'nonexistent' / 'output'
|
|
||||||
print(str(structure_file))
|
|
||||||
print(str(nonexistent_output))
|
|
||||||
stdout, stderr = run_prodir(['create', str(structure_file), '-o', str(nonexistent_output)])
|
|
||||||
assert "does not exist" in stderr.lower() or "Error: The specified output path" in stderr
|
|
Loading…
Reference in New Issue