Skip to content

Commit 55b6e90

Browse files
Improve console logging and rendering process
This commit brings improvements in developer experience by improving and cleaning console logs and putting the outputs of unit and conformance test runs in a separate files. Some of the logs I considered unnecessary I removed, some are moved to debug. What was added is printing of files that are sent and received from server (with line numbers and token size). The commit adds rich library (apparently the best in python world for this) that I found very usable for what we are planning to do on client side in the future. This commit also improves code rendering in case when unittest were not properly generated after functional requirement implementation.
1 parent 3bd6cce commit 55b6e90

File tree

7 files changed

+531
-197
lines changed

7 files changed

+531
-197
lines changed

examples/example_hello_world_python/run.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if [ $VERBOSE -eq 1 ]; then
2727
fi
2828

2929
# Construct the command with optional parameters
30-
CMD="python ../../plain2code.py hello_world_python.plain --unittests-script=../../test_scripts/run_unittests_python.sh --conformance-tests-script=../../test_scripts/run_conformance_tests_python.sh --debug"
30+
CMD="python ../../plain2code.py hello_world_python.plain --unittests-script=../../test_scripts/run_unittests_python.sh --conformance-tests-script=../../test_scripts/run_conformance_tests_python.sh"
3131
if [ $VERBOSE -eq 1 ]; then
3232
CMD="$CMD -v"
3333
fi

file_utils.py

+69-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import difflib
22
import os
3+
from pathlib import Path
34

45
from liquid2 import Environment, FileSystemLoader, StrictUndefined
56
from liquid2.exceptions import UndefinedError
@@ -8,6 +9,46 @@
89

910
BINARY_FILE_EXTENSIONS = [".pyc"]
1011

12+
# Dictionary mapping of file extensions to type names
13+
FILE_EXTENSION_MAPPING = {
14+
"": "plaintext",
15+
".py": "python",
16+
".txt": "plaintext",
17+
".md": "markdown",
18+
".ts": "typescript",
19+
".tsx": "typescript",
20+
".js": "javascript",
21+
".html": "HTML",
22+
".css": "CSS",
23+
".scss": "SASS/SCSS",
24+
".java": "java",
25+
".cpp": "C++",
26+
".c": "C",
27+
".cs": "C#",
28+
".php": "PHP",
29+
".rb": "Ruby",
30+
".go": "Go",
31+
".rs": "Rust",
32+
".swift": "Swift",
33+
".kt": "Kotlin",
34+
".sql": "SQL",
35+
".json": "JSON",
36+
".xml": "XML",
37+
".yaml": "YAML",
38+
".yml": "YAML", # YAML has two common extensions
39+
".sh": "Shell Script",
40+
".bat": "Batch File",
41+
}
42+
43+
44+
def get_file_type(file_name):
45+
46+
# Extract the file extension
47+
ext = Path(file_name).suffix.lower() # Convert to lowercase to handle case-insensitive matching
48+
49+
# Use the dictionary to get the file type, defaulting to 'unknown' if the extension is not found
50+
return FILE_EXTENSION_MAPPING.get(ext, "unknown")
51+
1152

1253
def list_all_text_files(directory):
1354
all_files = []
@@ -40,7 +81,7 @@ def list_folders_in_directory(directory):
4081
return folders
4182

4283

43-
def delete_files_and_subfolders(directory, verbose=False):
84+
def delete_files_and_subfolders(directory, debug=False):
4485
total_files_deleted = 0
4586
total_folders_deleted = 0
4687
items_deleted = []
@@ -52,19 +93,19 @@ def delete_files_and_subfolders(directory, verbose=False):
5293
file_path = os.path.join(root, file)
5394
os.remove(file_path)
5495
total_files_deleted += 1
55-
if verbose and len(items_deleted) < 10:
96+
if debug and len(items_deleted) < 10:
5697
items_deleted.append(f"Deleted file: {file_path}")
5798

5899
# Delete directories
59100
for dir_ in dirs:
60101
dir_path = os.path.join(root, dir_)
61102
os.rmdir(dir_path)
62103
total_folders_deleted += 1
63-
if verbose and len(items_deleted) < 10:
104+
if debug and len(items_deleted) < 10:
64105
items_deleted.append(f"Deleted folder: {dir_path}")
65106

66107
# Print the results
67-
if verbose:
108+
if debug:
68109
if total_files_deleted + total_folders_deleted > 10:
69110
print(f"Total files deleted: {total_files_deleted}")
70111
print(f"Total folders deleted: {total_folders_deleted}")
@@ -222,3 +263,27 @@ def get_loaded_templates(source_path, plain_source):
222263
raise Exception(f"Undefined liquid variable: {str(e)}")
223264

224265
return plain_source, liquid_loader.loaded_templates
266+
267+
268+
def copy_unchanged_files_from_previous_build(
269+
previous_build_folder, build_folder, existing_files, response_files, debug
270+
):
271+
for file_name in existing_files:
272+
if file_name not in response_files:
273+
if debug:
274+
print("Copying file: ", file_name)
275+
copy_file(os.path.join(previous_build_folder, file_name), os.path.join(build_folder, file_name))
276+
277+
278+
def update_build_folder_with_rendered_files(previous_build_folder, build_folder, existing_files, response_files, debug):
279+
if previous_build_folder:
280+
copy_unchanged_files_from_previous_build(
281+
previous_build_folder, build_folder, existing_files, response_files, debug
282+
)
283+
284+
changed_files = set()
285+
changed_files.update(response_files.keys())
286+
287+
existing_files = store_response_files(build_folder, response_files, existing_files)
288+
289+
return existing_files, changed_files

0 commit comments

Comments
 (0)