Skip to content

Commit

Permalink
First boostrap commit (#653)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonOsika authored Sep 2, 2023
1 parent 72361ae commit 3b4ffe1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
19 changes: 10 additions & 9 deletions gpt_engineer/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,27 @@

from dataclasses import dataclass
from pathlib import Path
from typing import Any, Optional, Union


# This class represents a simple database that stores its data as files in a directory.
class DB:
"""A simple key-value store, where keys are filenames and values are file contents."""

def __init__(self, path):
def __init__(self, path: Union[str, Path]):
"""
Initialize the DB class.
Parameters
----------
path : str
path : Union[str, Path]
The path to the directory where the database files are stored.
"""
self.path = Path(path).absolute()
self.path: Path = Path(path).absolute()

self.path.mkdir(parents=True, exist_ok=True)

def __contains__(self, key):
def __contains__(self, key: str) -> bool:
"""
Check if a file with the specified name exists in the database.
Expand All @@ -38,7 +39,7 @@ def __contains__(self, key):
"""
return (self.path / key).is_file()

def __getitem__(self, key):
def __getitem__(self, key: str) -> str:
"""
Get the content of a file in the database.
Expand All @@ -64,7 +65,7 @@ def __getitem__(self, key):
with full_path.open("r", encoding="utf-8") as f:
return f.read()

def get(self, key, default=None):
def get(self, key: str, default: Optional[Any] = None) -> Any:
"""
Get the content of a file in the database, or a default value if the file does not exist.
Expand All @@ -85,13 +86,13 @@ def get(self, key, default=None):
except KeyError:
return default

def __setitem__(self, key: str | Path, val: str):
def __setitem__(self, key: Union[str, Path], val: str) -> None:
"""
Set the content of a file in the database.
Parameters
----------
key : str
key : Union[str, Path]
The name of the file to set the content of.
val : str
The content to set.
Expand Down Expand Up @@ -125,7 +126,7 @@ class DBs:
archive: DB


def archive(dbs: DBs):
def archive(dbs: DBs) -> None:
"""
Archive the memory and workspace databases.
Expand Down
12 changes: 8 additions & 4 deletions gpt_engineer/file_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,14 @@ def ask_for_selection(self) -> List[str]:
List[str]: list of selected paths
"""
user_input = input(
"\nSelect files by entering the numbers separated by commas/spaces or "
+ "specify range with a dash. "
+ "Example: 1,2,3-5,7,9,13-15,18,20 (enter 'all' to select everything)"
+ "\n\nSelect files:"
"\n".join(
[
"Select files by entering the numbers separated by commas/spaces or",
"specify range with a dash. ",
"Example: 1,2,3-5,7,9,13-15,18,20 (enter 'all' to select everything)",
"\n\nSelect files:",
]
)
)
selected_paths = []
regex = r"\d+(-\d+)?([, ]\d+(-\d+)?)*"
Expand Down

0 comments on commit 3b4ffe1

Please sign in to comment.