Skip to content

Commit ceaaed4

Browse files
committed
Updated logging messaging in the client.
1 parent b5514f2 commit ceaaed4

19 files changed

Lines changed: 83 additions & 62 deletions

codeplain_REST_api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ def _handle_retry_logic(
6767
connection_error_type = "Network error" if is_connection_error else "Error"
6868
if attempt < num_retries:
6969
if not silent:
70-
self.console.info(f"{connection_error_type} on attempt {attempt + 1}/{num_retries + 1}: {error}")
71-
self.console.info(f"Retrying in {retry_delay} seconds...")
70+
self.console.debug(f"{connection_error_type} on attempt {attempt + 1}/{num_retries + 1}: {error}")
71+
self.console.debug(f"Retrying in {retry_delay} seconds...")
7272
time.sleep(retry_delay)
7373
# Exponential backoff
7474
return retry_delay * 2
@@ -117,7 +117,7 @@ def post_request(
117117
try:
118118
response_json = response.json()
119119
except requests.exceptions.JSONDecodeError as e:
120-
print(f"Failed to decode JSON response: {e}. Response text: {response.text}")
120+
self.console.debug(f"Failed to decode JSON response: {e}. Response text: {response.text}")
121121
raise
122122

123123
if response.status_code == requests.codes.bad_request and "error_code" in response_json:

docs/plain2code_cli.md

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
# Plain2Code CLI Reference
22

33
```text
4-
usage: generate_cli.py [-h] [--verbose] [--base-folder BASE_FOLDER] [--build-folder BUILD_FOLDER] [--log-to-file | --no-log-to-file] [--log-file-name LOG_FILE_NAME] [--config-name CONFIG_NAME]
5-
[--render-range RENDER_RANGE | --render-from RENDER_FROM] [--force-render] [--unittests-script UNITTESTS_SCRIPT] [--conformance-tests-folder CONFORMANCE_TESTS_FOLDER]
6-
[--conformance-tests-script CONFORMANCE_TESTS_SCRIPT] [--prepare-environment-script PREPARE_ENVIRONMENT_SCRIPT] [--test-script-timeout TEST_SCRIPT_TIMEOUT] [--api [API]] [--api-key API_KEY]
7-
[--full-plain] [--dry-run] [--replay-with REPLAY_WITH] [--template-dir TEMPLATE_DIR] [--copy-build] [--build-dest BUILD_DEST] [--copy-conformance-tests]
8-
[--conformance-tests-dest CONFORMANCE_TESTS_DEST] [--render-machine-graph] [--logging-config-path] [--headless]
4+
usage: generate_cli.py [-h] [--verbose] [--base-folder BASE_FOLDER] [--build-folder BUILD_FOLDER] [--log-to-file | --no-log-to-file]
5+
[--log-file-name LOG_FILE_NAME] [--config-name CONFIG_NAME] [--render-range RENDER_RANGE | --render-from RENDER_FROM]
6+
[--force-render] [--unittests-script UNITTESTS_SCRIPT] [--conformance-tests-folder CONFORMANCE_TESTS_FOLDER]
7+
[--conformance-tests-script CONFORMANCE_TESTS_SCRIPT] [--prepare-environment-script PREPARE_ENVIRONMENT_SCRIPT]
8+
[--test-script-timeout TEST_SCRIPT_TIMEOUT] [--api [API]] [--api-key API_KEY] [--full-plain] [--dry-run]
9+
[--replay-with REPLAY_WITH] [--template-dir TEMPLATE_DIR] [--copy-build] [--build-dest BUILD_DEST]
10+
[--copy-conformance-tests] [--conformance-tests-dest CONFORMANCE_TESTS_DEST] [--render-machine-graph]
11+
[--logging-config-path LOGGING_CONFIG_PATH] [--headless]
912
filename
1013
1114
Render plain code to target code.
1215
1316
positional arguments:
14-
filename Path to the plain file to render. The directory containing this file has highest precedence for template loading, so you can place custom templates here to override the defaults. See --template-dir
15-
for more details about template loading.
17+
filename Path to the plain file to render. The directory containing this file has highest precedence for template loading, so
18+
you can place custom templates here to override the defaults. See --template-dir for more details about template
19+
loading.
1620
1721
options:
1822
-h, --help show this help message and exit
@@ -24,49 +28,58 @@ options:
2428
--log-to-file, --no-log-to-file
2529
Enable logging to a file. Defaults to True. Set to False to disable.
2630
--log-file-name LOG_FILE_NAME
27-
Name of the log file. Defaults to 'codeplain.log'.Always resolved relative to the plain file directory.If file on this path already exists, the already existing log file will be overwritten by the
28-
current logs.
31+
Name of the log file. Defaults to 'codeplain.log'.Always resolved relative to the plain file directory.If file on
32+
this path already exists, the already existing log file will be overwritten by the current logs.
2933
--render-range RENDER_RANGE
30-
Specify a range of functionalities to render (e.g. `1` , `2`, `3`). Use comma to separate start and end IDs. If only one ID is provided, only that requirement is rendered. Range is
31-
inclusive of both start and end IDs.
34+
Specify a range of functionalities to render (e.g. `1` , `2`, `3`). Use comma to separate start and end IDs. If only
35+
one functionality ID is provided, only that functionality is rendered. Range is inclusive of both start and end IDs.
3236
--render-from RENDER_FROM
33-
Continue generation starting from this specific functionality (e.g. `2`). The requirement with this ID will be included in the output. The ID must match one of the functionalities
34-
in your plain file.
37+
Continue generation starting from this specific functionality (e.g. `2`). The functionality with this ID will be
38+
included in the output. The functionality ID must match one of the functionalities in your plain file.
3539
--force-render Force re-render of all the required modules.
3640
--unittests-script UNITTESTS_SCRIPT
37-
Shell script to run unit tests on generated code. Receives the build folder path as its first argument (default: 'plain_modules').
41+
Shell script to run unit tests on generated code. Receives the build folder path as its first argument (default:
42+
'plain_modules').
3843
--conformance-tests-folder CONFORMANCE_TESTS_FOLDER
3944
Folder for conformance test files
4045
--conformance-tests-script CONFORMANCE_TESTS_SCRIPT
41-
Path to conformance tests shell script. Every conformance test script should accept two arguments: 1) Path to a folder (e.g. `plain_modules/module_name`) containing generated source code, 2) Path
42-
to a subfolder of the conformance tests folder (e.g. `conformance_tests/subfoldername`) containing test files.
46+
Path to conformance tests shell script. Every conformance test script should accept two arguments: 1) Path to a
47+
folder (e.g. `plain_modules/module_name`) containing generated source code, 2) Path to a subfolder of the conformance
48+
tests folder (e.g. `conformance_tests/subfoldername`) containing test files.
4349
--prepare-environment-script PREPARE_ENVIRONMENT_SCRIPT
44-
Path to a shell script that prepares the testing environment. The script should accept the source code folder path as its first argument.
50+
Path to a shell script that prepares the testing environment. The script should accept the source code folder path as
51+
its first argument.
4552
--test-script-timeout TEST_SCRIPT_TIMEOUT
4653
Timeout for test scripts in seconds. If not provided, the default timeout of 120 seconds is used.
4754
--api [API] Alternative base URL for the API. Default: `https://api.codeplain.ai`
4855
--api-key API_KEY API key used to access the API. If not provided, the `CODEPLAIN_API_KEY` environment variable is used.
49-
--full-plain Full preview ***plain specification before code generation.Use when you want to preview context of all ***plain primitives that are going to be included in order to render the given module.
56+
--full-plain Full preview ***plain specification before code generation.Use when you want to preview context of all ***plain
57+
primitives that are going to be included in order to render the given module.
5058
--dry-run Dry run preview of the code generation (without actually making any changes).
5159
--replay-with REPLAY_WITH
5260
--template-dir TEMPLATE_DIR
53-
Path to a custom template directory. Templates are searched in the following order: 1) Directory containing the plain file, 2) Custom template directory (if provided through this argument), 3)
54-
Built-in standard_template_library directory
55-
--copy-build If set, copy the rendered contents of code in `--base-folder` folder to `--build-dest` folder after successful rendering.
61+
Path to a custom template directory. Templates are searched in the following order: 1) Directory containing the plain
62+
file, 2) Custom template directory (if provided through this argument), 3) Built-in standard_template_library
63+
directory
64+
--copy-build If set, copy the rendered contents of code in `--base-folder` folder to `--build-dest` folder after successful
65+
rendering.
5666
--build-dest BUILD_DEST
5767
Target folder to copy rendered contents of code to (used only if --copy-build is set).
5868
--copy-conformance-tests
59-
If set, copy the conformance tests of code in `--conformance-tests-folder` folder to `--conformance-tests-dest` folder successful rendering. Requires --conformance-tests-script.
69+
If set, copy the conformance tests of code in `--conformance-tests-folder` folder to `--conformance-tests-dest`
70+
folder successful rendering. Requires --conformance-tests-script.
6071
--conformance-tests-dest CONFORMANCE_TESTS_DEST
6172
Target folder to copy conformance tests of code to (used only if --copy-conformance-tests is set).
6273
--render-machine-graph
6374
If set, render the state machine graph.
64-
--logging-config-path
75+
--logging-config-path LOGGING_CONFIG_PATH
6576
Path to the logging configuration file.
66-
--headless Run in headless mode: no TUI, no terminal output except a single render-started message. All logs are written to the log file.
77+
--headless Run in headless mode: no TUI, no terminal output except a single render-started message. All logs are written to the
78+
log file.
6779
6880
configuration:
6981
--config-name CONFIG_NAME
70-
Path to the config file, defaults to config.yaml
82+
Name of the config file to look for. Looked up in the plain file directory and the current working directory.
83+
Defaults to config.yaml.
7184
7285
```

file_utils.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from liquid2.exceptions import UndefinedError
88

99
import plain_spec
10+
from plain2code_console import console
1011
from plain2code_nodes import Plain2CodeIncludeTag, Plain2CodeLoaderMixin
1112
from plain_modules import CODEPLAIN_MEMORY_SUBFOLDER, CODEPLAIN_METADATA_FOLDER
1213

@@ -79,7 +80,7 @@ def list_all_text_files(directory):
7980
with open(os.path.join(root, filename), "rb") as f:
8081
f.read().decode("utf-8")
8182
except UnicodeDecodeError:
82-
print(f"WARNING! Not listing {filename} in {root}. File is not a text file. Skipping it.")
83+
console.debug(f"WARNING! Not listing {filename} in {root}. File is not a text file. Skipping it.")
8384
continue
8485

8586
all_files.append(os.path.join(modified_root, filename))
@@ -178,7 +179,7 @@ def get_existing_files_content(build_folder, existing_files):
178179
try:
179180
existing_files_content[file_name] = content.decode("utf-8")
180181
except UnicodeDecodeError:
181-
print(f"WARNING! Error loading {file_name}. File is not a text file. Skipping it.")
182+
console.debug(f"WARNING! Error loading {file_name}. File is not a text file. Skipping it.")
182183

183184
return existing_files_content
184185

@@ -193,7 +194,7 @@ def store_response_files(target_folder, response_files, existing_files):
193194
os.remove(full_file_name)
194195
existing_files.remove(file_name)
195196
else:
196-
print(f"WARNING! Cannot delete file! File {full_file_name} does not exist.")
197+
console.debug(f"WARNING! Cannot delete file! File {full_file_name} does not exist.")
197198

198199
continue
199200

@@ -219,7 +220,9 @@ def open_from(dirs, file_name):
219220
try:
220221
content_text = content.decode("utf-8")
221222
except UnicodeDecodeError:
222-
print(f"WARNING! Error loading {file_name} ({file_name}). File is not a text file. Skipping it.")
223+
console.debug(
224+
f"WARNING! Error loading {file_name} ({file_name}). File is not a text file. Skipping it."
225+
)
223226
return content_text
224227

225228
return None

memory_management.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def fetch_memory_files(memory_folder: str) -> tuple[list[str], dict[str, str]]:
2121
return [], {}
2222
memory_files = file_utils.list_all_text_files(memory_path)
2323
memory_files_content = file_utils.get_existing_files_content(memory_path, memory_files)
24-
console.info(f"Loaded {len(memory_files_content)} memory files.")
24+
console.debug(f"Loaded {len(memory_files_content)} memory files.")
2525
return memory_files, memory_files_content
2626

2727
def __init__(self, codeplain_api, module_build_folder: str):

module_renderer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def _render_module(
199199
required_modules = []
200200
has_any_required_module_changed = False
201201
if not self.args.render_machine_graph and required_modules_list:
202-
console.info(f"Analyzing required modules of module {module_name}...")
202+
console.debug(f"Analyzing required modules of module {module_name}...")
203203
for required_module_name in required_modules_list:
204204
required_module_filename = required_module_name + plain_file.PLAIN_SOURCE_FILE_EXTENSION
205205
has_module_changed, sub_required_modules, rendering_failed = self._render_module(

plain2code.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,13 @@ def render(args, run_state: RunState, event_bus: EventBus): # noqa: C901
214214
def run_render():
215215
try:
216216
module_renderer.render_module()
217+
console.info(f"[#79FC96]Render {run_state.render_id} completed successfully.[/#79FC96]")
217218
except Exception as e:
218219
render_error.append(e)
219220
event_bus.publish(RenderFailed(error_message=str(e)))
220221

221222
if args.headless:
222-
print(f"Render started. Render ID: {run_state.render_id}")
223+
console.info(f"Render started. Render ID: {run_state.render_id}")
223224
module_renderer.render_module()
224225
return
225226
else:

plain2code_arguments.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import argparse
22
import os
3+
import sys
4+
from typing import Any
35

46
from plain2code_console import console
57
from plain2code_exceptions import AmbiguousConfigFileError
@@ -212,14 +214,14 @@ def create_parser(color: bool = False):
212214
"--render-range",
213215
type=frid_range_string,
214216
help="Specify a range of functionalities to render (e.g. `1` , `2`, `3`). "
215-
"Use comma to separate start and end IDs. If only one ID is provided, only that functionality is rendered. "
217+
"Use comma to separate start and end IDs. If only one functionality ID is provided, only that functionality is rendered. "
216218
"Range is inclusive of both start and end IDs.",
217219
)
218220
render_range_group.add_argument(
219221
"--render-from",
220222
type=frid_string,
221223
help="Continue generation starting from this specific functionality (e.g. `2`). "
222-
"The requirement with this ID will be included in the output. The ID must match one of the functionalities in your plain file.",
224+
"The functionality with this ID will be included in the output. The functionality ID must match one of the functionalities in your plain file.",
223225
)
224226

225227
parser.add_argument(

plain2code_console.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ def print_resources(self, resources_list, linked_resources):
123123
self.debug("Linked resources: None")
124124
return
125125

126-
self.input("Linked resources:")
126+
self.debug("Linked resources:")
127127
for resource_name in resources_list:
128128
if resource_name["target"] in linked_resources:
129129
file_tokens = self._count_tokens(linked_resources[resource_name["target"]])
130-
self.input(
130+
self.debug(
131131
f"- {resource_name['text']} [#4169E1]({resource_name['target']}, {file_tokens} tokens)[/#4169E1]"
132132
)
133133

plain2code_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def print_dry_run_output(plain_source_tree: dict, render_range: Optional[list[st
2323
functional_requirement_text = specifications[plain_spec.FUNCTIONAL_REQUIREMENTS][-1]
2424
console.info(
2525
"-------------------------------------\n"
26-
f"Rendering functionality {frid}\n"
26+
f"Rendering functionality {frid}:\n"
2727
f"{functional_requirement_text}\n"
2828
"-------------------------------------\n"
2929
)

render_machine/actions/analyze_specification_ambiguity.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,5 @@ def execute(self, render_context: RenderContext, _previous_action_payload: Any |
5050
)
5151
console.info(rendering_analysis["guidance"])
5252
else:
53-
console.warning(
54-
f"No specification ambiguity detected for functionality {render_context.frid_context.frid}."
55-
)
53+
console.debug(f"No specification ambiguity detected for functionality {render_context.frid_context.frid}.")
5654
return self.SUCCESSFUL_OUTCOME, None

0 commit comments

Comments
 (0)