From 340647cb220e9cebe75b850524436ec49d0aaced Mon Sep 17 00:00:00 2001 From: Robbie Walmsley <65429016+robbiebusinessacc@users.noreply.github.com> Date: Mon, 9 Oct 2023 10:53:03 +0100 Subject: [PATCH 1/4] Update ingest.py --- scripts/ingest.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/scripts/ingest.py b/scripts/ingest.py index 6ab9cce..e0d5ce1 100644 --- a/scripts/ingest.py +++ b/scripts/ingest.py @@ -78,14 +78,12 @@ def ingest(yes: bool = typer.Option(False, "-y", "--yes", prompt=False, # Here we check for command line arguments for bot calls. # If no argument exists or the yes is not True, then the # user permission is requested to call the API. - if len(sys.argv) > 1: - if yes: - call_openai_api(docs, folder_name) - else: - get_user_permission(docs, folder_name) + if len(sys.argv) > 1 and yes: + call_openai_api(docs, folder_name) else: get_user_permission(docs, folder_name) + folder_counts = defaultdict(int) folder_names = [] for dir_path in dir: From 57fb29b6008e38f6445f91066d3fbacd7eaf25b2 Mon Sep 17 00:00:00 2001 From: Robbie Walmsley <65429016+robbiebusinessacc@users.noreply.github.com> Date: Mon, 9 Oct 2023 10:55:34 +0100 Subject: [PATCH 2/4] Update worker.py --- application/worker.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/application/worker.py b/application/worker.py index 5c87c70..71fcd61 100644 --- a/application/worker.py +++ b/application/worker.py @@ -21,8 +21,7 @@ except FileExistsError: def metadata_from_filename(title): - store = title.split('/') - store = store[1] + '/' + store[2] + store = '/'.join(title.split('/')[1:3]) return {'title': title, 'store': store} From 2d0b6bcfcc0c852a65444594c2ed85d1d79f88e8 Mon Sep 17 00:00:00 2001 From: Robbie Walmsley <65429016+robbiebusinessacc@users.noreply.github.com> Date: Mon, 9 Oct 2023 11:04:55 +0100 Subject: [PATCH 3/4] Update ingest.py --- scripts/ingest.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/scripts/ingest.py b/scripts/ingest.py index e0d5ce1..4834844 100644 --- a/scripts/ingest.py +++ b/scripts/ingest.py @@ -108,14 +108,19 @@ def convert(dir: Optional[str] = typer.Option("inputs", Creates documentation linked to original functions from specified location. By default /inputs folder is used, .py is parsed. """ - if formats == 'py': - functions_dict, classes_dict = extract_py(dir) - elif formats == 'js': - functions_dict, classes_dict = extract_js(dir) - elif formats == 'java': - functions_dict, classes_dict = extract_java(dir) + # Using a dictionary to map between the formats and their respective extraction functions + # makes the code more scalable. When adding more formats in the future, + # you only need to update the extraction_functions dictionary. + extraction_functions = { + 'py': extract_py, + 'js': extract_js, + 'java': extract_java + } + + if formats in extraction_functions: + functions_dict, classes_dict = extraction_functions[formats](dir) else: - raise Exception("Sorry, language not supported yet") + raise Exception("Sorry, language not supported yet") transform_to_docs(functions_dict, classes_dict, formats, dir) From 4d92606562c3cb553ebf6b55210bce4e822b3193 Mon Sep 17 00:00:00 2001 From: Robbie Walmsley <65429016+robbiebusinessacc@users.noreply.github.com> Date: Mon, 9 Oct 2023 11:11:07 +0100 Subject: [PATCH 4/4] Update ingest.py --- scripts/ingest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ingest.py b/scripts/ingest.py index 4834844..8c74fd0 100644 --- a/scripts/ingest.py +++ b/scripts/ingest.py @@ -120,7 +120,7 @@ def convert(dir: Optional[str] = typer.Option("inputs", if formats in extraction_functions: functions_dict, classes_dict = extraction_functions[formats](dir) else: - raise Exception("Sorry, language not supported yet") + raise Exception("Sorry, language not supported yet") transform_to_docs(functions_dict, classes_dict, formats, dir)