Skip to content

Commit ebab816

Browse files
authored
Merge pull request #17 from Codeplain-ai/07-03-deploy
Standardize commit messages, minor improvements and bug fixes
2 parents a7f0429 + 54f7aa2 commit ebab816

File tree

3 files changed

+60
-15
lines changed

3 files changed

+60
-15
lines changed

git_utils.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,20 @@
55

66
import file_utils
77

8-
INITIAL_COMMIT_MESSAGE = "[Codeplain] Initial commit"
9-
BASE_FOLDER_COMMIT_MESSAGE = "[Codeplain] Initialize build with Base Folder content"
10-
REFACTORED_CODE_COMMIT_MESSAGE = "[Codeplain] Refactored code after implementing {}"
8+
FUNCTIONAL_REQUIREMENT_IMPLEMENTED_COMMIT_MESSAGE = (
9+
"[Codeplain] Implemented code and unit tests for functional requirement {}"
10+
)
11+
REFACTORED_CODE_COMMIT_MESSAGE = "[Codeplain] Refactored code after implementing functional requirement {}"
1112
CONFORMANCE_TESTS_PASSED_COMMIT_MESSAGE = (
1213
"[Codeplain] Fixed issues in the implementation code identified during conformance testing"
1314
)
15+
16+
# Following messages are used as checkpoints in the git history
17+
# Changing them will break backwards compatibility so change them with care
1418
FUNCTIONAL_REQUIREMENT_FINISHED_COMMIT_MESSAGE = "[Codeplain] Functional requirement ID (FRID):{} fully implemented"
19+
INITIAL_COMMIT_MESSAGE = "[Codeplain] Initial commit"
20+
BASE_FOLDER_COMMIT_MESSAGE = "[Codeplain] Initialize build with Base Folder content"
21+
1522

1623
RENDERED_FRID_MESSAGE = "Changes related to Functional requirement ID (FRID): {}"
1724
RENDER_ID_MESSAGE = "Render ID: {}"

plain2code.py

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from plain2code_arguments import parse_arguments
1919
from plain2code_console import console
2020
from plain2code_state import CONFORMANCE_TESTS_DEFINITION_FILE_NAME, ConformanceTestsUtils, ExecutionState, RunState
21+
from plain2code_utils import RetryOnlyFilter
2122
from system_config import system_config
2223

2324
TEST_SCRIPT_EXECUTION_TIMEOUT = 120 # 120 seconds
@@ -884,7 +885,10 @@ def render_functional_requirement( # noqa: C901
884885
changed_files.add(file_name)
885886

886887
git_utils.add_all_files_and_commit(
887-
args.build_folder, functional_requirement_text, frid, run_state.render_id
888+
args.build_folder,
889+
f"{git_utils.FUNCTIONAL_REQUIREMENT_IMPLEMENTED_COMMIT_MESSAGE.format(frid)}\n\n{functional_requirement_text}",
890+
frid,
891+
run_state.render_id,
888892
)
889893
break
890894

@@ -907,12 +911,20 @@ def render_functional_requirement( # noqa: C901
907911
# Phase 3: Refactor the source code if needed.
908912
console.info("[b]Refactoring the generated code...[/b]")
909913
num_refactoring_iterations = 0
910-
while num_refactoring_iterations < MAX_REFACTORING_ITERATIONS:
914+
while True:
911915
num_refactoring_iterations += 1
916+
917+
existing_files = file_utils.list_all_text_files(args.build_folder)
918+
919+
if num_refactoring_iterations > MAX_REFACTORING_ITERATIONS:
920+
console.info(
921+
f"Refactoring iterations limit of {MAX_REFACTORING_ITERATIONS} reached for functional requirement {frid}."
922+
)
923+
break
924+
912925
if args.verbose:
913926
console.info(f"\nRefactoring iteration {num_refactoring_iterations}.")
914927

915-
existing_files = file_utils.list_all_text_files(args.build_folder)
916928
existing_files_content = file_utils.get_existing_files_content(args.build_folder, existing_files)
917929
if args.verbose:
918930
console.print_files(
@@ -1043,23 +1055,29 @@ def render_functional_requirement( # noqa: C901
10431055

10441056
def render(args, run_state: RunState):
10451057
if args.verbose:
1058+
1059+
logging.basicConfig(level=logging.DEBUG)
1060+
logging.getLogger("urllib3").setLevel(logging.WARNING)
1061+
logging.getLogger("httpx").setLevel(logging.WARNING)
1062+
logging.getLogger("httpcore").setLevel(logging.WARNING)
1063+
logging.getLogger("anthropic").setLevel(logging.WARNING)
1064+
logging.getLogger("langsmith").setLevel(logging.WARNING)
1065+
logging.getLogger("git").setLevel(logging.WARNING)
1066+
logging.getLogger("anthropic._base_client").setLevel(logging.DEBUG)
1067+
10461068
# Try to load logging configuration from YAML file
10471069
if os.path.exists(LOGGING_CONFIG_PATH):
10481070
try:
10491071
with open(LOGGING_CONFIG_PATH, "r") as f:
10501072
config = yaml.safe_load(f)
10511073
logging.config.dictConfig(config)
10521074
console.info(f"Loaded logging configuration from {LOGGING_CONFIG_PATH}")
1053-
except Exception:
1054-
pass
1075+
except Exception as e:
1076+
console.warning(f"Failed to load logging configuration from {LOGGING_CONFIG_PATH}: {str(e)}")
10551077

1056-
logging.basicConfig(level=logging.DEBUG)
1057-
1058-
logging.getLogger("urllib3").setLevel(logging.WARNING)
1059-
logging.getLogger("httpx").setLevel(logging.WARNING)
1060-
logging.getLogger("httpcore").setLevel(logging.WARNING)
1061-
logging.getLogger("anthropic").setLevel(logging.WARNING)
1062-
logging.getLogger("langsmith").setLevel(logging.WARNING)
1078+
# if we have debug level for anthropic._base_client to debug, catch only logs relevant to retrying (ones that are relevant for us)
1079+
if logging.getLogger("anthropic._base_client").level == logging.DEBUG:
1080+
logging.getLogger("anthropic._base_client").addFilter(RetryOnlyFilter())
10631081

10641082
formatter = IndentedFormatter("%(levelname)s:%(name)s:%(message)s")
10651083
console_handler = logging.StreamHandler()

plain2code_utils.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import logging
2+
3+
4+
class RetryOnlyFilter(logging.Filter):
5+
def filter(self, record):
6+
# Allow all logs with level > DEBUG (i.e., INFO and above)
7+
if record.levelno > logging.DEBUG:
8+
return True
9+
# For DEBUG logs, only allow if message matches retry-related patterns
10+
msg = record.getMessage().lower()
11+
return (
12+
"retrying due to" in msg
13+
or "raising timeout error" in msg
14+
or "raising connection error" in msg
15+
or "encountered exception" in msg
16+
or "retrying request" in msg
17+
or "retry left" in msg
18+
or "1 retry left" in msg
19+
or "retries left" in msg
20+
)

0 commit comments

Comments
 (0)