Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,7 +12,7 @@ dependencies = [
"numpy",
"psutil",
"httpx",
"tree-sitter!=0.25.0",
"tree-sitter>=0.25.1,<0.26.0",
"tree-sitter-language-pack",
"pygments",
"transformers>=4.36.0,!=4.51.0,!=4.51.1,!=4.51.2",
Expand Down
12 changes: 6 additions & 6 deletions src/vectorcode/chunking.py
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
import logging
import os
import re
from abc import ABC, abstractmethod
from dataclasses import dataclass
from functools import cache
from io import TextIOWrapper
from typing import Generator, Optional, cast

Check failure on line 8 in src/vectorcode/chunking.py

View workflow job for this annotation

GitHub Actions/ style-check

ruff (UP035)

src/vectorcode/chunking.py:8:1: UP035 Import from `collections.abc` instead: `Generator` help: Import from `collections.abc`

from pygments.lexer import Lexer
from pygments.lexers import get_lexer_for_filename
from pygments.util import ClassNotFound
from tree_sitter import Node, Point
from tree_sitter_language_pack import SupportedLanguage, get_parser
from tree_sitter_language_pack import Error as TreeSitterLanguagePackError

from vectorcode.cli_utils import Config

Check failure on line 17 in src/vectorcode/chunking.py

View workflow job for this annotation

GitHub Actions/ style-check

ruff (I001)

src/vectorcode/chunking.py:1:1: I001 Import block is un-sorted or un-formatted help: Organize imports

Expand DownExpand Up@@ -63,7 +64,7 @@


class ChunkerBase(ABC): # pragma: nocover
def __init__(self, config: Optional[Config] = None) -> None:

Check failure on line 67 in src/vectorcode/chunking.py

View workflow job for this annotation

GitHub Actions/ style-check

ruff (UP045)

src/vectorcode/chunking.py:67:32: UP045 Use `X | None` for type annotations help: Convert to `X | None`
if config is None:
config = Config()
assert 0 <= config.overlap_ratio < 1, (
Expand All@@ -73,18 +74,18 @@

@abstractmethod
def chunk(
self, data, opts: Optional[ChunkOpts] = None

Check failure on line 77 in src/vectorcode/chunking.py

View workflow job for this annotation

GitHub Actions/ style-check

ruff (UP045)

src/vectorcode/chunking.py:77:27: UP045 Use `X | None` for type annotations help: Convert to `X | None`
) -> Generator[Chunk, None, None]:
raise NotImplementedError


class StringChunker(ChunkerBase):
def __init__(self, config: Optional[Config] = None) -> None:

Check failure on line 83 in src/vectorcode/chunking.py

View workflow job for this annotation

GitHub Actions/ style-check

ruff (UP045)

src/vectorcode/chunking.py:83:32: UP045 Use `X | None` for type annotations help: Convert to `X | None`
if config is None:
config = Config()
super().__init__(config)

def chunk(self, data: str, opts: Optional[ChunkOpts] = None):

Check failure on line 88 in src/vectorcode/chunking.py

View workflow job for this annotation

GitHub Actions/ style-check

ruff (UP045)

src/vectorcode/chunking.py:88:38: UP045 Use `X | None` for type annotations help: Convert to `X | None`
start_pos = Point(row=1, column=0)
if opts is not None:
start_pos = opts.start_pos
Expand DownExpand Up@@ -134,13 +135,13 @@


class FileChunker(ChunkerBase):
def __init__(self, config: Optional[Config] = None) -> None:

Check failure on line 138 in src/vectorcode/chunking.py

View workflow job for this annotation

GitHub Actions/ style-check

ruff (UP045)

src/vectorcode/chunking.py:138:32: UP045 Use `X | None` for type annotations help: Convert to `X | None`
if config is None:
config = Config()
super().__init__(config)

def chunk(
self, data: TextIOWrapper, opts: Optional[ChunkOpts] = None

Check failure on line 144 in src/vectorcode/chunking.py

View workflow job for this annotation

GitHub Actions/ style-check

ruff (UP045)

src/vectorcode/chunking.py:144:42: UP045 Use `X | None` for type annotations help: Convert to `X | None`
) -> Generator[Chunk, None, None]:
logger.info("Started chunking %s using FileChunker.", data.name)
lines = data.readlines()
Expand DownExpand Up@@ -194,7 +195,7 @@


class TreeSitterChunker(ChunkerBase):
def __init__(self, config: Optional[Config] = None):

Check failure on line 198 in src/vectorcode/chunking.py

View workflow job for this annotation

GitHub Actions/ style-check

ruff (UP045)

src/vectorcode/chunking.py:198:32: UP045 Use `X | None` for type annotations help: Convert to `X | None`
if config is None:
config = Config()
super().__init__(config)
Expand DownExpand Up@@ -370,11 +371,10 @@
f"\nInvalid regex pattern '{pattern}' for language '{language}' in filetype_map"
)
raise
except LookupError as e:
e.add_note(
f"\nTreeSitter Parser for language '{language}' not found. Please check your filetype_map config."
)
raise
except (LookupError, TreeSitterLanguagePackError) as e:
raise LookupError(
f"TreeSitter Parser for language '{language}' not found. Please check your filetype_map config."
) from e

logger.debug(f"No matching filetype map entry found for {filename}.")
return None
Expand DownExpand Up@@ -412,7 +412,7 @@
language,
)
break
except LookupError: # pragma: nocover
except (LookupError, TreeSitterLanguagePackError): # pragma: nocover
pass

if parser is None:
Expand Down
29 changes: 18 additions & 11 deletions tests/test_cli_utils.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -210,9 +210,7 @@ async def test_load_config_file_invalid_json():
@pytest.mark.asyncio
async def test_load_from_default_config():
for name in ("config.json5", "config.json"):
with (
tempfile.TemporaryDirectory() as fake_home,
):
with (tempfile.TemporaryDirectory() as fake_home,):
os.environ.update({"HOME": fake_home})
config_path = os.path.join(fake_home, ".config", "vectorcode", name)
config_dir = os.path.join(fake_home, ".config", "vectorcode")
Expand DownExpand Up@@ -562,14 +560,23 @@ def test_cleanup_path():

def test_shtab():
for shell in ("bash", "zsh", "tcsh"):
assert (
subprocess.Popen(
[sys.executable, "-m", "vectorcode.main", "-s", shell],
stderr=subprocess.PIPE,
)
.stderr.read()
.decode()
) == ""
result = subprocess.Popen(
[sys.executable, "-m", "vectorcode.main", "-s", shell],
stderr=subprocess.PIPE,
stdout=subprocess.PIPE,
)
assert result.stderr is not None

stderr_output = result.stderr.read().decode()

# Filter out ONNX Runtime warnings which are not test failures
filtered_stderr = "\n".join(
line
for line in stderr_output.split("\n")
if "onnxruntime" not in line.lower() and line.strip()
)

assert filtered_stderr == ""


@pytest.mark.asyncio
Expand Down
Loading