Skip to content

Commit 7076551

Browse files
committed
feat(cli): fallback to global file specs.
1 parent 84fdef7 commit 7076551

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

src/vectorcode/cli_utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
GLOBAL_CONFIG_PATH = os.path.join(
1717
os.path.expanduser("~"), ".config", "vectorcode", "config.json"
1818
)
19+
GLOBAL_INCLUDE_SPEC = os.path.join(
20+
os.path.expanduser("~"), ".config", "vectorcode", "vectorcode.include"
21+
)
22+
GLOBAL_EXCLUDE_SPEC = os.path.join(
23+
os.path.expanduser("~"), ".config", "vectorcode", "vectorcode.exclude"
24+
)
1925

2026
CHECK_OPTIONS = ["config"]
2127

src/vectorcode/subcommands/vectorise.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import sys
66
import uuid
77
from asyncio import Lock
8-
from typing import Iterable
8+
from typing import Iterable, Optional
99

1010
import pathspec
1111
import tabulate
@@ -14,7 +14,13 @@
1414
from chromadb.api.types import IncludeEnum
1515

1616
from vectorcode.chunking import Chunk, TreeSitterChunker
17-
from vectorcode.cli_utils import Config, expand_globs, expand_path
17+
from vectorcode.cli_utils import (
18+
GLOBAL_EXCLUDE_SPEC,
19+
GLOBAL_INCLUDE_SPEC,
20+
Config,
21+
expand_globs,
22+
expand_path,
23+
)
1824
from vectorcode.common import get_client, get_collection, verify_ef
1925

2026

@@ -120,11 +126,18 @@ def include_paths_by_spec(paths: Iterable[str], specs: pathspec.PathSpec) -> lis
120126

121127
def load_files_from_include(project_root: str) -> list[str]:
122128
include_file_path = os.path.join(project_root, ".vectorcode", "vectorcode.include")
129+
specs: Optional[pathspec.GitIgnoreSpec] = None
123130
if os.path.isfile(include_file_path):
124131
with open(include_file_path) as fin:
125132
specs = pathspec.GitIgnoreSpec.from_lines(
126133
lines=(os.path.expanduser(i) for i in fin.readlines()),
127134
)
135+
elif os.path.isfile(GLOBAL_INCLUDE_SPEC):
136+
with open(GLOBAL_INCLUDE_SPEC) as fin:
137+
specs = pathspec.GitIgnoreSpec.from_lines(
138+
lines=(os.path.expanduser(i) for i in fin.readlines()),
139+
)
140+
if specs is not None:
128141
return [
129142
result.file
130143
for result in specs.check_tree_files(project_root)
@@ -160,6 +173,8 @@ async def vectorise(configs: Config) -> int:
160173
)
161174
if os.path.isfile(exclude_spec_path):
162175
specs.append(exclude_spec_path)
176+
elif os.path.isfile(GLOBAL_EXCLUDE_SPEC):
177+
specs.append(GLOBAL_EXCLUDE_SPEC)
163178
for spec_path in specs:
164179
if os.path.isfile(spec_path):
165180
with open(spec_path) as fin:

0 commit comments

Comments
 (0)