Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
phil65 committed Dec 14, 2024
1 parent 51730ab commit 64f4dac
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 44 deletions.
5 changes: 2 additions & 3 deletions src/llmling/resources/loaders/callable.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ async def _load_impl(

# If we have a URI context, extract and merge parameters
if self.context:
uri_params = self.get_params_from_uri(
self.create_uri(name=self.context.name)
)
uri = self.create_uri(name=self.context.name)
uri_params = self.get_params_from_uri(uri)
kwargs.update(uri_params)

# Execute the callable with combined parameters
Expand Down
44 changes: 21 additions & 23 deletions src/llmling/resources/loaders/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,29 +93,27 @@ async def _load_impl(

if path.is_dir():
# Handle directory recursively
for file_path in path.rglob("*"):
if file_path.is_file():
content = file_path.read_text("utf-8")
if processor_registry and (procs := resource.processors):
processed = await processor_registry.process(content, procs)
content = processed.content

yield create_loaded_resource(
content=content,
source_type="path",
uri=self.create_uri(
name=file_path.name
), # Use filename for URI
mime_type=self.supported_mime_types[0],
name=resource.description or file_path.name,
description=resource.description,
additional_metadata={
"type": "path",
"path": str(file_path),
"scheme": file_path.protocol,
"relative_to": str(path), # Add original directory
},
)
files = [p for p in path.rglob("*") if p.is_file()]
for file_path in files:
content = file_path.read_text("utf-8")
if processor_registry and (procs := resource.processors):
processed = await processor_registry.process(content, procs)
content = processed.content
meta = {
"type": "path",
"path": str(file_path),
"scheme": file_path.protocol,
"relative_to": str(path),
}
yield create_loaded_resource(
content=content,
source_type="path",
uri=self.create_uri(name=file_path.name), # Use filename for URI
mime_type=self.supported_mime_types[0],
name=resource.description or file_path.name,
description=resource.description,
additional_metadata=meta,
)
else:
# Handle single file
content = path.read_text("utf-8")
Expand Down
27 changes: 11 additions & 16 deletions src/llmling/resources/loaders/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,8 @@ async def _load_impl(
branch=resource.ref,
)
if resource.sparse_checkout:
repo.git.sparse_checkout(
"set", " ".join(resource.sparse_checkout)
)
path_str = " ".join(resource.sparse_checkout)
repo.git.sparse_checkout("set", path_str)
self._cache_repo(resource.repo_url, repo)

# Switch to requested ref
Expand All @@ -119,20 +118,16 @@ async def _load_impl(
yield loaded
else:
# Directory - yield all matching files
for file_path in base_path.rglob("*"):
if file_path.is_file():
rel_path = file_path.relative_to(base_path)
loaded = self._create_resource(
file_path,
str(rel_path),
resource,
files = [p for p in base_path.rglob("*") if p.is_file()]
for file_path in files:
rel_path = file_path.relative_to(base_path)
loaded = self._create_resource(file_path, str(rel_path), resource)
if processor_registry and resource.processors:
result = await processor_registry.process(
loaded.content, resource.processors
)
if processor_registry and resource.processors:
result = await processor_registry.process(
loaded.content, resource.processors
)
loaded.content = result.content
yield loaded
loaded.content = result.content
yield loaded

except git.exc.GitCommandError as exc:
msg = f"Git operation failed: {exc}"
Expand Down
3 changes: 1 addition & 2 deletions src/llmling/resources/watching/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ def load_patterns(
# Add patterns from file
if ignore_file:
try:
path = UPath(ignore_file)
if path.exists():
if (path := UPath(ignore_file)).exists():
# Filter empty lines and comments
file_patterns = [
line.strip()
Expand Down

0 comments on commit 64f4dac

Please sign in to comment.