Skip to content

Commit 14aa03f

Browse files
author
Zhe Yu
committed
loggers for clean, drop and init
1 parent 70b749f commit 14aa03f

4 files changed

Lines changed: 16 additions & 6 deletions

File tree

src/vectorcode/subcommands/clean.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1+
import logging
12
import os
23

34
from chromadb.api import AsyncClientAPI
45

56
from vectorcode.cli_utils import Config
67
from vectorcode.common import get_client, get_collections
78

9+
logger = logging.getLogger(name=__name__)
10+
811

912
async def run_clean_on_client(client: AsyncClientAPI, pipe_mode: bool):
1013
async for collection in get_collections(client):
1114
meta = collection.metadata
15+
logger.debug(f"{meta.get('path')}: {await collection.count()} chunk(s)")
1216
if await collection.count() == 0 or not os.path.isdir(meta["path"]):
1317
await client.delete_collection(collection.name)
18+
logger.info(f"Deleted collection for {meta['path']}")
1419
if not pipe_mode:
1520
print(f"Deleted {meta['path']}.")
1621

src/vectorcode/subcommands/drop.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
import logging
2+
13
from chromadb.errors import InvalidCollectionException
24

35
from vectorcode.cli_utils import Config
46
from vectorcode.common import get_client, get_collection
57

8+
logger = logging.getLogger(name=__name__)
9+
610

711
async def drop(config: Config) -> int:
812
client = await get_client(config)
@@ -11,7 +15,8 @@ async def drop(config: Config) -> int:
1115
collection_path = collection.metadata["path"]
1216
await client.delete_collection(collection.name)
1317
print(f"Collection for {collection_path} has been deleted.")
18+
logger.info(f"Deteted collection at {collection_path}.")
1419
return 0
1520
except (ValueError, InvalidCollectionException):
16-
print(f"There's no existing collection for {config.project_root}")
21+
logger.error(f"There's no existing collection for {config.project_root}")
1722
return 1

src/vectorcode/subcommands/init.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1+
import logging
12
import os
23
import shutil
3-
import sys
44

55
from vectorcode.cli_utils import Config
66

7+
logger = logging.getLogger(name=__name__)
8+
79

810
async def init(configs: Config) -> int:
911
project_config_dir = os.path.join(str(configs.project_root), ".vectorcode")
1012
if os.path.isdir(project_config_dir) and not configs.force:
11-
print(
13+
logger.warning(
1214
f"{configs.project_root} is already initialised for VectorCode.",
13-
file=sys.stderr,
1415
)
1516
return 1
1617

@@ -21,6 +22,7 @@ async def init(configs: Config) -> int:
2122
os.path.expanduser("~"), ".config", "vectorcode", item
2223
)
2324
if os.path.isfile(global_file_path):
25+
logger.debug(f"Copying global {item} to {project_config_dir}")
2426
shutil.copyfile(global_file_path, local_file_path)
2527

2628
print(f"VectorCode project root has been initialised at {configs.project_root}")

tests/subcommands/test_init.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ async def test_init_already_initialized(capsys):
3232
# Try to initialize again without force
3333
return_code = await init(configs)
3434
assert return_code == 1
35-
captured = capsys.readouterr()
36-
assert f"{temp_dir} is already initialised for VectorCode." in captured.err
3735

3836

3937
@pytest.mark.asyncio

0 commit comments

Comments
 (0)