Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
12 changes: 12 additions & 0 deletions .github/workflows/test_and_cov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: install pdm and dependencies
if: matrix.os != 'macos-14'
run: |
pdm lock --group dev --group lsp --group mcp --group debug
pdm install

- name: install pdm and dependencies for legacy system
if: matrix.os == 'macos-14'
run: |
pdm lock --group dev --group lsp --group mcp --group legacy --group debug
pdm install

- name: Install uv
uses: astral-sh/setup-uv@v5
with:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
DEFAULT_GROUPS=--group dev --group lsp --group mcp

deps:
pdm lock $(DEFAULT_GROUPS) || pdm lock $(DEFAULT_GROUPS) --group legacy; \
pdm lock --group dev --group lsp --group mcp --group debug; \
pdm install

test:
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ omit = [
"./tests/*",
"src/vectorcode/_version.py",
"src/vectorcode/__init__.py",
"src/vectorcode/debugging.py",
"/tmp/*",
]
include = ['src/vectorcode/**/*.py']
Expand All @@ -63,14 +64,12 @@ write_template = "__version__ = '{}' # pragma: no cover"
dev = [
"ipython>=8.31.0",
"ruff>=0.9.1",
"viztracer>=1.0.0",
"pre-commit>=4.0.1",
"pytest>=8.3.4",
"pdm-backend>=2.4.3",
"coverage>=7.6.12",
"pytest-asyncio>=0.25.3",
"debugpy>=1.8.12",
"coredumpy>=0.4.1",
"basedpyright>=1.29.2",
]

Expand All @@ -79,6 +78,7 @@ legacy = ["numpy<2.0.0", "torch==2.2.2", "transformers<=4.49.0"]
intel = ['optimum[openvino]', 'openvino']
lsp = ['pygls<2.0.0', 'lsprotocol']
mcp = ['mcp<2.0.0', 'pydantic']
debug = ["coredumpy>=0.4.1"]

[tool.basedpyright]
typeCheckingMode = "standard"
Expand Down
8 changes: 8 additions & 0 deletions src/vectorcode/cli_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class FilesAction(StrEnum):

@dataclass
class Config:
debug: bool = False
no_stderr: bool = False
recursive: bool = False
include_hidden: bool = False
Expand Down Expand Up @@ -198,6 +199,12 @@ async def merge_from(self, other: "Config") -> "Config":
def get_cli_parser():
__default_config = Config()
shared_parser = argparse.ArgumentParser(add_help=False)
shared_parser.add_argument(
"--debug",
default=False,
action="store_true",
help="Enable debug mode (requires vectorcode[debug]).",
)
chunking_parser = argparse.ArgumentParser(add_help=False)
chunking_parser.add_argument(
"--overlap",
Expand Down Expand Up @@ -423,6 +430,7 @@ async def parse_cli_args(args: Optional[Sequence[str]] = None):
"action": CliAction(main_args.action),
"project_root": main_args.project_root,
"pipe": main_args.pipe,
"debug": main_args.debug,
}

match main_args.action:
Expand Down
49 changes: 49 additions & 0 deletions src/vectorcode/debugging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import logging
import os
import cProfile
import pstats
from datetime import datetime

import atexit

__LOG_DIR = os.path.expanduser("~/.local/share/vectorcode/logs/")

logger = logging.getLogger(name=__name__)

__profiler: cProfile.Profile | None = None


def finish():
"""Clean up profiling and save results"""
if __profiler is not None:
try:
__profiler.disable()
stats_file = os.path.join(
__LOG_DIR,
f"cprofile-{datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}.stats",
)
__profiler.dump_stats(stats_file)
logger.info(f"cProfile stats saved to: {stats_file}")

# Print summary stats
stats = pstats.Stats(__profiler)
stats.sort_stats('cumulative')
stats.print_stats(20)
except Exception as e:
logger.warning(f"Failed to save cProfile output: {e}")


def enable():
"""Enable cProfile-based profiling"""
global __profiler

try:
# Initialize cProfile for comprehensive profiling
__profiler = cProfile.Profile()
__profiler.enable()
atexit.register(finish)
logger.info("cProfile profiling enabled successfully")

except Exception as e:
logger.error(f"Failed to initialize cProfile: {e}")
logger.warning("Profiling will not be available for this session")
6 changes: 5 additions & 1 deletion src/vectorcode/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import sys
import traceback

from vectorcode import __version__, debugging
import httpx

from vectorcode import __version__
from vectorcode.cli_utils import (
CliAction,
config_logging,
Expand All @@ -23,6 +23,10 @@ async def async_main():
cli_args = await parse_cli_args()
if cli_args.no_stderr:
sys.stderr = open(os.devnull, "w")

if cli_args.debug:
debugging.enable()

logger.info("Collected CLI arguments: %s", cli_args)

if cli_args.project_root is None:
Expand Down
Loading