From 3b4ffe17ed4e5ccba658cb0c97fce2a5ddbfe3f2 Mon Sep 17 00:00:00 2001 From: Anton Osika Date: Sat, 2 Sep 2023 20:16:13 +0200 Subject: [PATCH] First boostrap commit (#653) --- gpt_engineer/db.py | 19 ++++++++++--------- gpt_engineer/file_selector.py | 12 ++++++++---- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/gpt_engineer/db.py b/gpt_engineer/db.py index eb2bd3e7af..6664a83c2c 100644 --- a/gpt_engineer/db.py +++ b/gpt_engineer/db.py @@ -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. @@ -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. @@ -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. @@ -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. @@ -125,7 +126,7 @@ class DBs: archive: DB -def archive(dbs: DBs): +def archive(dbs: DBs) -> None: """ Archive the memory and workspace databases. diff --git a/gpt_engineer/file_selector.py b/gpt_engineer/file_selector.py index 8c44d43d1f..b7d3ea3c1c 100644 --- a/gpt_engineer/file_selector.py +++ b/gpt_engineer/file_selector.py @@ -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+)?)*"