ara-cli 0.1.9.51__py3-none-any.whl → 0.1.9.53__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of ara-cli might be problematic. Click here for more details.
- ara_cli/ara_command_action.py +34 -34
- ara_cli/ara_config.py +2 -7
- ara_cli/artefact_creator.py +3 -4
- ara_cli/artefact_lister.py +11 -13
- ara_cli/artefact_models/artefact_model.py +20 -8
- ara_cli/artefact_reader.py +10 -16
- ara_cli/artefact_renamer.py +8 -8
- ara_cli/chat.py +2 -1
- ara_cli/file_classifier.py +3 -33
- ara_cli/tests/test_ara_command_action.py +6 -6
- ara_cli/tests/test_artefact_lister.py +149 -91
- ara_cli/tests/test_artefact_reader.py +2 -43
- ara_cli/tests/test_chat.py +18 -13
- ara_cli/tests/test_file_classifier.py +2 -2
- ara_cli/version.py +1 -1
- {ara_cli-0.1.9.51.dist-info → ara_cli-0.1.9.53.dist-info}/METADATA +1 -1
- {ara_cli-0.1.9.51.dist-info → ara_cli-0.1.9.53.dist-info}/RECORD +20 -22
- ara_cli/artefact.py +0 -172
- ara_cli/tests/test_artefact.py +0 -304
- {ara_cli-0.1.9.51.dist-info → ara_cli-0.1.9.53.dist-info}/WHEEL +0 -0
- {ara_cli-0.1.9.51.dist-info → ara_cli-0.1.9.53.dist-info}/entry_points.txt +0 -0
- {ara_cli-0.1.9.51.dist-info → ara_cli-0.1.9.53.dist-info}/top_level.txt +0 -0
ara_cli/ara_command_action.py
CHANGED
|
@@ -266,6 +266,12 @@ def fetch_templates_action(args):
|
|
|
266
266
|
target = join(target_dir, item)
|
|
267
267
|
shutil.copy2(source, target)
|
|
268
268
|
|
|
269
|
+
custom_prompt_templates_subdir = config.custom_prompt_templates_subdir
|
|
270
|
+
local_prompt_modules_dir = join(prompt_templates_dir, custom_prompt_templates_subdir)
|
|
271
|
+
os.makedirs(local_prompt_modules_dir, exist_ok=True)
|
|
272
|
+
for subdir in subdirs:
|
|
273
|
+
os.makedirs(join(local_prompt_modules_dir, subdir), exist_ok=True)
|
|
274
|
+
|
|
269
275
|
|
|
270
276
|
def read_action(args):
|
|
271
277
|
from ara_cli.artefact_reader import ArtefactReader
|
|
@@ -318,55 +324,49 @@ def read_action(args):
|
|
|
318
324
|
|
|
319
325
|
|
|
320
326
|
def reconnect_action(args):
|
|
321
|
-
from ara_cli.
|
|
327
|
+
from ara_cli.artefact_models.artefact_load import artefact_from_content
|
|
328
|
+
from ara_cli.artefact_models.artefact_model import Contribution
|
|
322
329
|
from ara_cli.artefact_reader import ArtefactReader
|
|
323
|
-
from ara_cli.file_classifier import FileClassifier
|
|
324
|
-
from ara_cli.directory_navigator import DirectoryNavigator
|
|
325
330
|
|
|
326
331
|
classifier = args.classifier
|
|
327
332
|
artefact_name = args.parameter
|
|
328
333
|
parent_classifier = args.parent_classifier
|
|
329
334
|
parent_name = args.parent_name
|
|
330
335
|
|
|
331
|
-
|
|
332
|
-
classified_artefacts_info = file_classifier.classify_files_new()
|
|
333
|
-
|
|
334
|
-
all_artefact_names = [info["title"] for info in classified_artefacts_info.get(classifier, [])]
|
|
335
|
-
if artefact_name not in all_artefact_names:
|
|
336
|
-
suggest_close_name_matches(artefact_name, all_artefact_names)
|
|
337
|
-
return
|
|
336
|
+
read_error_message = f"Could not connect {classifier} '{artefact_name}' to {parent_classifier} '{parent_name}'"
|
|
338
337
|
|
|
339
|
-
|
|
340
|
-
if parent_name not in all_artefact_names:
|
|
341
|
-
suggest_close_name_matches(parent_name, all_artefact_names)
|
|
342
|
-
return
|
|
343
|
-
|
|
344
|
-
directory_navigator = DirectoryNavigator()
|
|
345
|
-
original_directory = directory_navigator.navigate_to_target()
|
|
346
|
-
|
|
347
|
-
content, file_path = ArtefactReader.read_artefact(
|
|
338
|
+
content, artefact_info = ArtefactReader.read_artefact(
|
|
348
339
|
artefact_name=artefact_name,
|
|
349
340
|
classifier=classifier
|
|
350
341
|
)
|
|
342
|
+
if not content:
|
|
343
|
+
print(read_error_message)
|
|
344
|
+
return
|
|
351
345
|
|
|
352
|
-
parent_content,
|
|
346
|
+
parent_content, parent_info = ArtefactReader.read_artefact(
|
|
353
347
|
artefact_name=parent_name,
|
|
354
348
|
classifier=parent_classifier
|
|
355
349
|
)
|
|
350
|
+
if not parent_content:
|
|
351
|
+
print(read_error_message)
|
|
352
|
+
return
|
|
356
353
|
|
|
357
|
-
artefact =
|
|
354
|
+
artefact = artefact_from_content(
|
|
358
355
|
content=content,
|
|
359
|
-
file_path=file_path
|
|
360
|
-
)
|
|
361
|
-
parent = Artefact.from_content(
|
|
362
|
-
content=parent_content,
|
|
363
|
-
file_path=parent_path
|
|
364
356
|
)
|
|
357
|
+
artefact._file_path = artefact_info["file_path"]
|
|
365
358
|
|
|
366
|
-
|
|
367
|
-
|
|
359
|
+
parent = artefact_from_content(
|
|
360
|
+
content=parent_content
|
|
361
|
+
)
|
|
368
362
|
|
|
369
|
-
|
|
363
|
+
artefact.contribution = Contribution(
|
|
364
|
+
artefact_name=parent.title,
|
|
365
|
+
classifier=parent.artefact_type
|
|
366
|
+
)
|
|
367
|
+
with open(artefact.file_path, 'w') as file:
|
|
368
|
+
artefact_content = artefact.serialize()
|
|
369
|
+
file.write(artefact_content)
|
|
370
370
|
|
|
371
371
|
|
|
372
372
|
def read_status_action(args):
|
|
@@ -377,7 +377,7 @@ def read_status_action(args):
|
|
|
377
377
|
artefact_name = args.parameter
|
|
378
378
|
|
|
379
379
|
file_classifier = FileClassifier(os)
|
|
380
|
-
artefact_info = file_classifier.
|
|
380
|
+
artefact_info = file_classifier.classify_files()
|
|
381
381
|
artefact_info_dicts = artefact_info.get(classifier, [])
|
|
382
382
|
|
|
383
383
|
all_artefact_names = [artefact_info["title"] for artefact_info in artefact_info_dicts]
|
|
@@ -409,7 +409,7 @@ def read_user_action(args):
|
|
|
409
409
|
artefact_name = args.parameter
|
|
410
410
|
|
|
411
411
|
file_classifier = FileClassifier(os)
|
|
412
|
-
artefact_info = file_classifier.
|
|
412
|
+
artefact_info = file_classifier.classify_files()
|
|
413
413
|
artefact_info_dicts = artefact_info.get(classifier, [])
|
|
414
414
|
|
|
415
415
|
all_artefact_names = [artefact_info["title"] for artefact_info in artefact_info_dicts]
|
|
@@ -451,7 +451,7 @@ def set_status_action(args):
|
|
|
451
451
|
check_validity(new_status in status_tags, "Invalid status provided. Please provide a valid status.")
|
|
452
452
|
|
|
453
453
|
file_classifier = FileClassifier(os)
|
|
454
|
-
classified_artefacts_info = file_classifier.
|
|
454
|
+
classified_artefacts_info = file_classifier.classify_files()
|
|
455
455
|
classified_artefact_dict = classified_artefacts_info.get(classifier, [])
|
|
456
456
|
all_artefact_names = [artefact_info["title"] for artefact_info in classified_artefact_dict]
|
|
457
457
|
|
|
@@ -488,7 +488,7 @@ def set_user_action(args):
|
|
|
488
488
|
new_user = new_user.lstrip('@')
|
|
489
489
|
|
|
490
490
|
file_classifier = FileClassifier(os)
|
|
491
|
-
classified_artefacts_info = file_classifier.
|
|
491
|
+
classified_artefacts_info = file_classifier.classify_files()
|
|
492
492
|
classified_artefact_dict = classified_artefacts_info.get(classifier, [])
|
|
493
493
|
all_artefact_names = [artefact_info["title"] for artefact_info in classified_artefact_dict]
|
|
494
494
|
|
|
@@ -527,7 +527,7 @@ def scan_action(args):
|
|
|
527
527
|
from ara_cli.artefact_scan import find_invalid_files, show_results
|
|
528
528
|
import os
|
|
529
529
|
|
|
530
|
-
classified_artefact_info = FileClassifier(os).
|
|
530
|
+
classified_artefact_info = FileClassifier(os).classify_files()
|
|
531
531
|
invalid_artefacts = {}
|
|
532
532
|
for classifier in classified_artefact_info:
|
|
533
533
|
invalid = find_invalid_files(classified_artefact_info, classifier)
|
ara_cli/ara_config.py
CHANGED
|
@@ -2,7 +2,7 @@ from typing import List, Dict, Union, Optional
|
|
|
2
2
|
from pydantic import BaseModel
|
|
3
3
|
import json
|
|
4
4
|
import os
|
|
5
|
-
from os.path import exists,
|
|
5
|
+
from os.path import exists, dirname
|
|
6
6
|
from os import makedirs
|
|
7
7
|
from functools import lru_cache
|
|
8
8
|
|
|
@@ -18,6 +18,7 @@ class ARAconfig(BaseModel):
|
|
|
18
18
|
glossary_dir: str = "./glossary"
|
|
19
19
|
doc_dir: str = "./docs"
|
|
20
20
|
local_prompt_templates_dir: str = "./ara/.araconfig"
|
|
21
|
+
custom_prompt_templates_subdir: Optional[str] = "custom-prompt-modules"
|
|
21
22
|
local_ara_templates_dir: str = "./ara/.araconfig/templates/"
|
|
22
23
|
ara_prompt_given_list_includes: List[str] = [
|
|
23
24
|
"*.businessgoal",
|
|
@@ -136,12 +137,6 @@ class ConfigManager:
|
|
|
136
137
|
|
|
137
138
|
if not exists(config_dir):
|
|
138
139
|
makedirs(config_dir)
|
|
139
|
-
# create defined default path structure for custom prompts
|
|
140
|
-
makedirs(join(config_dir, "custom-prompt-modules"))
|
|
141
|
-
makedirs(join(config_dir, "custom-prompt-modules", "commands"))
|
|
142
|
-
makedirs(join(config_dir, "custom-prompt-modules", "rule"))
|
|
143
|
-
makedirs(join(config_dir, "custom-prompt-modules", "intentions"))
|
|
144
|
-
makedirs(join(config_dir, "custom-prompt-modules", "blueprints"))
|
|
145
140
|
|
|
146
141
|
cls._config_instance = read_data(filepath)
|
|
147
142
|
return cls._config_instance
|
ara_cli/artefact_creator.py
CHANGED
|
@@ -2,9 +2,9 @@ import os
|
|
|
2
2
|
from functools import lru_cache
|
|
3
3
|
from ara_cli.classifier import Classifier
|
|
4
4
|
from ara_cli.template_manager import DirectoryNavigator
|
|
5
|
-
from ara_cli.
|
|
5
|
+
from ara_cli.artefact_reader import ArtefactReader
|
|
6
|
+
from ara_cli.artefact_models.artefact_model import Artefact
|
|
6
7
|
from ara_cli.artefact_models.artefact_templates import template_artefact_of_type
|
|
7
|
-
from ara_cli.file_classifier import FileClassifier
|
|
8
8
|
from ara_cli.artefact_fuzzy_search import suggest_close_name_matches
|
|
9
9
|
from pathlib import Path
|
|
10
10
|
from shutil import copyfile
|
|
@@ -75,8 +75,7 @@ class ArtefactCreator:
|
|
|
75
75
|
return True
|
|
76
76
|
|
|
77
77
|
def set_artefact_parent(self, artefact, parent_classifier, parent_file_name) -> Artefact:
|
|
78
|
-
|
|
79
|
-
classified_artefacts = file_classifier.classify_files()
|
|
78
|
+
classified_artefacts = ArtefactReader.read_artefacts()
|
|
80
79
|
if parent_classifier not in classified_artefacts:
|
|
81
80
|
return artefact
|
|
82
81
|
artefact_list = classified_artefacts[parent_classifier]
|
ara_cli/artefact_lister.py
CHANGED
|
@@ -66,7 +66,7 @@ class ArtefactLister:
|
|
|
66
66
|
list_filter: ListFilter | None = None
|
|
67
67
|
):
|
|
68
68
|
file_classifier = FileClassifier(os)
|
|
69
|
-
classified_artefacts = file_classifier.
|
|
69
|
+
classified_artefacts = file_classifier.classify_files()
|
|
70
70
|
artefact_info = classified_artefacts.get(classifier, [])
|
|
71
71
|
matching_artefact_info = [p for p in artefact_info if p["title"] == artefact_name]
|
|
72
72
|
|
|
@@ -92,7 +92,7 @@ class ArtefactLister:
|
|
|
92
92
|
list_filter: ListFilter | None = None
|
|
93
93
|
):
|
|
94
94
|
file_classifier = FileClassifier(os)
|
|
95
|
-
classified_artefacts = file_classifier.
|
|
95
|
+
classified_artefacts = file_classifier.classify_files()
|
|
96
96
|
artefact_info = classified_artefacts.get(classifier, [])
|
|
97
97
|
matching_artefact_info = [p for p in artefact_info if p["title"] == artefact_name]
|
|
98
98
|
|
|
@@ -118,21 +118,19 @@ class ArtefactLister:
|
|
|
118
118
|
list_filter: ListFilter | None = None
|
|
119
119
|
):
|
|
120
120
|
file_classifier = FileClassifier(os)
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
matching_paths = [p for p in artefact_paths if os.path.basename(p).startswith(artefact_name + '.')]
|
|
121
|
+
classified_artefact_info = file_classifier.classify_files()
|
|
122
|
+
artefact_info_dict = classified_artefact_info.get(classifier, [])
|
|
124
123
|
|
|
125
|
-
if
|
|
124
|
+
matching_info = [info for info in artefact_info_dict if info["title"] == artefact_name]
|
|
125
|
+
|
|
126
|
+
if not matching_info:
|
|
126
127
|
suggest_close_name_matches(
|
|
127
128
|
artefact_name,
|
|
128
|
-
[
|
|
129
|
+
[info["title"] for info in artefact_info_dict]
|
|
129
130
|
)
|
|
130
|
-
artefact_paths = classified_artefacts.get(classifier, [])
|
|
131
|
-
matching_paths = [p for p in artefact_paths if os.path.basename(p).startswith(artefact_name + '.')]
|
|
132
|
-
|
|
133
|
-
if len(matching_paths) == 0:
|
|
134
131
|
return
|
|
135
|
-
|
|
136
|
-
|
|
132
|
+
|
|
133
|
+
artefact_info = matching_info[0]
|
|
134
|
+
data_dir = os.path.splitext(artefact_info["file_path"])[0] + '.data'
|
|
137
135
|
if os.path.exists(data_dir):
|
|
138
136
|
list_files_in_directory(data_dir, list_filter)
|
|
@@ -11,6 +11,14 @@ import string
|
|
|
11
11
|
ALLOWED_STATUS_VALUES = ("to-do", "in-progress", "review", "done", "closed")
|
|
12
12
|
|
|
13
13
|
|
|
14
|
+
def replace_space_with_underscore(input: string):
|
|
15
|
+
return input.replace(' ', '_')
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def replace_underscore_with_space(input: string):
|
|
19
|
+
return input.replace('_', ' ')
|
|
20
|
+
|
|
21
|
+
|
|
14
22
|
class ArtefactType(str, Enum):
|
|
15
23
|
vision = "vision"
|
|
16
24
|
businessgoal = "businessgoal"
|
|
@@ -44,6 +52,12 @@ class Contribution(BaseModel):
|
|
|
44
52
|
classifier = self.classifier
|
|
45
53
|
rule = self.rule
|
|
46
54
|
|
|
55
|
+
if artefact_name:
|
|
56
|
+
artefact_name = replace_space_with_underscore(artefact_name)
|
|
57
|
+
if artefact_name and classifier:
|
|
58
|
+
artefact_name = artefact_name.removesuffix(f"_{classifier}")
|
|
59
|
+
artefact_name = artefact_name.removesuffix(f"_{classifier.capitalize()}")
|
|
60
|
+
self.artefact_name = artefact_name
|
|
47
61
|
if not artefact_name or not classifier:
|
|
48
62
|
self.artefact_name = None
|
|
49
63
|
self.classifier = None
|
|
@@ -60,7 +74,7 @@ class Contribution(BaseModel):
|
|
|
60
74
|
return value
|
|
61
75
|
if ' ' in value:
|
|
62
76
|
warnings.warn(message="artefact_name can not contain spaces. Replacing spaces with '_'")
|
|
63
|
-
value = value
|
|
77
|
+
value = replace_space_with_underscore(value)
|
|
64
78
|
return value
|
|
65
79
|
|
|
66
80
|
@field_validator('classifier', mode='after')
|
|
@@ -102,7 +116,7 @@ class Contribution(BaseModel):
|
|
|
102
116
|
if not self.classifier or not self.artefact_name:
|
|
103
117
|
return ""
|
|
104
118
|
artefact_type = Classifier.get_artefact_title(self.classifier)
|
|
105
|
-
artefact_name = self.artefact_name
|
|
119
|
+
artefact_name = replace_underscore_with_space(self.artefact_name)
|
|
106
120
|
contribution = f"{artefact_name} {artefact_type}"
|
|
107
121
|
if self.rule:
|
|
108
122
|
contribution = f"{contribution} using rule {self.rule}"
|
|
@@ -136,6 +150,7 @@ class Artefact(BaseModel, ABC):
|
|
|
136
150
|
"validate_assignment": True
|
|
137
151
|
}
|
|
138
152
|
|
|
153
|
+
_file_path: Optional[str] = None
|
|
139
154
|
artefact_type: ArtefactType = Field(
|
|
140
155
|
...,
|
|
141
156
|
description=f"Artefact classifier (mandatory). Allowed classifiers are {', '.join(ArtefactType)}"
|
|
@@ -165,7 +180,6 @@ class Artefact(BaseModel, ABC):
|
|
|
165
180
|
default=None,
|
|
166
181
|
description="Optional further description to understand the artefact. It is strongly recommended to add a description to every artefact."
|
|
167
182
|
)
|
|
168
|
-
_file_path: Optional[str] = None
|
|
169
183
|
|
|
170
184
|
@property
|
|
171
185
|
def file_path(self) -> str:
|
|
@@ -207,9 +221,7 @@ class Artefact(BaseModel, ABC):
|
|
|
207
221
|
def validate_title(cls, v):
|
|
208
222
|
if not v.strip():
|
|
209
223
|
raise ValueError("artefact_title must not be empty")
|
|
210
|
-
|
|
211
|
-
warnings.warn(message="artefact_name can not contain spaces. Replacing spaces with '_'")
|
|
212
|
-
v = v.replace(' ', '_')
|
|
224
|
+
v = replace_space_with_underscore(v)
|
|
213
225
|
|
|
214
226
|
letters = list(string.ascii_letters)
|
|
215
227
|
digits = list(string.digits)
|
|
@@ -281,7 +293,7 @@ class Artefact(BaseModel, ABC):
|
|
|
281
293
|
raise ValueError(
|
|
282
294
|
f"No title found in {cls._artefact_type()}. Expected '{title_prefix}' as start of the title in line '{title_line}'")
|
|
283
295
|
title = title_line[len(title_prefix):].strip()
|
|
284
|
-
title = title
|
|
296
|
+
title = replace_space_with_underscore(title)
|
|
285
297
|
return title, lines
|
|
286
298
|
|
|
287
299
|
@classmethod
|
|
@@ -351,7 +363,7 @@ class Artefact(BaseModel, ABC):
|
|
|
351
363
|
pass
|
|
352
364
|
|
|
353
365
|
def _serialize_title(self) -> str:
|
|
354
|
-
title = self.title
|
|
366
|
+
title = replace_underscore_with_space(self.title)
|
|
355
367
|
return f"{self._title_prefix()} {title}"
|
|
356
368
|
|
|
357
369
|
def _serialize_tags(self) -> (Optional[str]):
|
ara_cli/artefact_reader.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
from ara_cli.directory_navigator import DirectoryNavigator
|
|
2
1
|
from ara_cli.classifier import Classifier
|
|
3
2
|
from ara_cli.file_classifier import FileClassifier
|
|
4
3
|
from ara_cli.artefact_models.artefact_model import Artefact
|
|
@@ -11,33 +10,28 @@ import re
|
|
|
11
10
|
class ArtefactReader:
|
|
12
11
|
@staticmethod
|
|
13
12
|
def read_artefact(artefact_name, classifier):
|
|
14
|
-
original_directory = os.getcwd()
|
|
15
|
-
navigator = DirectoryNavigator()
|
|
16
|
-
navigator.navigate_to_target()
|
|
17
|
-
|
|
18
13
|
if not Classifier.is_valid_classifier(classifier):
|
|
19
14
|
print("Invalid classifier provided. Please provide a valid classifier.")
|
|
20
|
-
os.chdir(original_directory)
|
|
21
15
|
return None, None
|
|
22
16
|
|
|
23
17
|
file_classifier = FileClassifier(os)
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
classified_file_info = file_classifier.classify_files()
|
|
19
|
+
artefact_info_of_classifier = classified_file_info.get(classifier, [])
|
|
26
20
|
|
|
27
|
-
for
|
|
28
|
-
|
|
21
|
+
for artefact_info in artefact_info_of_classifier:
|
|
22
|
+
file_path = artefact_info["file_path"]
|
|
23
|
+
artefact_title = artefact_info["title"]
|
|
24
|
+
if artefact_title == artefact_name:
|
|
29
25
|
with open(file_path, 'r') as file:
|
|
30
26
|
content = file.read()
|
|
31
|
-
|
|
32
|
-
return content, file_path
|
|
27
|
+
return content, artefact_info
|
|
33
28
|
|
|
34
|
-
|
|
29
|
+
all_artefact_names = [info["title"] for info in artefact_info_of_classifier]
|
|
35
30
|
suggest_close_name_matches(
|
|
36
31
|
artefact_name,
|
|
37
|
-
|
|
32
|
+
all_artefact_names
|
|
38
33
|
)
|
|
39
34
|
|
|
40
|
-
os.chdir(original_directory)
|
|
41
35
|
return None, None
|
|
42
36
|
|
|
43
37
|
@staticmethod
|
|
@@ -72,7 +66,7 @@ class ArtefactReader:
|
|
|
72
66
|
|
|
73
67
|
if classified_artefacts is None:
|
|
74
68
|
file_classifier = FileClassifier(file_system)
|
|
75
|
-
classified_artefacts = file_classifier.
|
|
69
|
+
classified_artefacts = file_classifier.classify_files()
|
|
76
70
|
|
|
77
71
|
artefacts = {artefact_type: []
|
|
78
72
|
for artefact_type in classified_artefacts.keys()}
|
ara_cli/artefact_renamer.py
CHANGED
|
@@ -12,16 +12,17 @@ class ArtefactRenamer:
|
|
|
12
12
|
self.link_updater = ArtefactLinkUpdater()
|
|
13
13
|
|
|
14
14
|
@lru_cache(maxsize=None)
|
|
15
|
-
def navigate_to_target(self):
|
|
15
|
+
def navigate_to_target(self) -> str:
|
|
16
16
|
navigator = DirectoryNavigator()
|
|
17
|
-
navigator.navigate_to_target()
|
|
17
|
+
original_directory = navigator.navigate_to_target()
|
|
18
|
+
return original_directory
|
|
18
19
|
|
|
19
20
|
@lru_cache(maxsize=None)
|
|
20
21
|
def compile_pattern(self, pattern):
|
|
21
22
|
return re.compile(pattern)
|
|
22
23
|
|
|
23
24
|
def rename(self, old_name, new_name, classifier):
|
|
24
|
-
self.navigate_to_target()
|
|
25
|
+
original_directory = self.navigate_to_target()
|
|
25
26
|
|
|
26
27
|
if not new_name:
|
|
27
28
|
raise ValueError("New name must be provided for renaming.")
|
|
@@ -50,13 +51,10 @@ class ArtefactRenamer:
|
|
|
50
51
|
|
|
51
52
|
# Perform the renaming of the file and directory
|
|
52
53
|
self.file_system.rename(old_file_path, new_file_path)
|
|
54
|
+
print(f"Renamed file: {old_file_path} to {new_file_path}")
|
|
53
55
|
if old_dir_exists:
|
|
54
56
|
self.file_system.rename(old_dir_path, new_dir_path)
|
|
55
|
-
|
|
56
|
-
os.makedirs(new_dir_path, exist_ok=True)
|
|
57
|
-
|
|
58
|
-
print(f"Renamed file: {old_file_path} to {new_file_path}")
|
|
59
|
-
print(f"Renamed directory: {old_dir_path} to {new_dir_path}")
|
|
57
|
+
print(f"Renamed directory: {old_dir_path} to {new_dir_path}")
|
|
60
58
|
|
|
61
59
|
# Update the title within the artefact file
|
|
62
60
|
self._update_title_in_artefact(new_file_path, new_name, classifier)
|
|
@@ -64,6 +62,8 @@ class ArtefactRenamer:
|
|
|
64
62
|
# Update links in related artefact files
|
|
65
63
|
self.link_updater.update_links_in_related_artefacts(old_name, new_name)
|
|
66
64
|
|
|
65
|
+
os.chdir(original_directory)
|
|
66
|
+
|
|
67
67
|
def _update_title_in_artefact(self, artefact_path, new_title, classifier):
|
|
68
68
|
# Format the new title: replace underscores with spaces
|
|
69
69
|
formatted_new_title = new_title.replace('_', ' ')
|
ara_cli/chat.py
CHANGED
|
@@ -662,7 +662,8 @@ Start chatting (type 'HELP'/'h' for available commands, 'QUIT'/'q' to exit chat
|
|
|
662
662
|
local_templates_path = os.path.join(os.getcwd(), local_templates_path)
|
|
663
663
|
os.chdir(original_directory)
|
|
664
664
|
|
|
665
|
-
|
|
665
|
+
custom_prompt_templates_subdir = self.config.custom_prompt_templates_subdir
|
|
666
|
+
template_directory = f"{local_templates_path}/{custom_prompt_templates_subdir}/{plural}"
|
|
666
667
|
self._load_helper(template_directory, template_name, template_type)
|
|
667
668
|
|
|
668
669
|
def _load_template_helper(self, template_name, template_type, default_pattern):
|
ara_cli/file_classifier.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from ara_cli.classifier import Classifier
|
|
2
|
-
from ara_cli.
|
|
2
|
+
from ara_cli.artefact_models.artefact_model import Artefact
|
|
3
3
|
from ara_cli.artefact_fuzzy_search import find_closest_name_match
|
|
4
4
|
from functools import lru_cache
|
|
5
5
|
from typing import Optional
|
|
@@ -14,7 +14,7 @@ class FileClassifier:
|
|
|
14
14
|
def find_closest_artefact_name_match(self, name, classifier) -> Optional[str]:
|
|
15
15
|
classified_artefacts = self.classify_files()
|
|
16
16
|
all_artefact_names = [
|
|
17
|
-
|
|
17
|
+
info["title"] for info in classified_artefacts.get(classifier, [])]
|
|
18
18
|
if name in all_artefact_names:
|
|
19
19
|
return name
|
|
20
20
|
return find_closest_name_match(name, all_artefact_names)
|
|
@@ -64,37 +64,7 @@ class FileClassifier:
|
|
|
64
64
|
return classifier
|
|
65
65
|
return None
|
|
66
66
|
|
|
67
|
-
def classify_files(self, tags=None
|
|
68
|
-
from ara_cli.artefact_models.artefact_load import artefact_from_content
|
|
69
|
-
|
|
70
|
-
files_by_classifier = {classifier: []
|
|
71
|
-
for classifier in Classifier.ordered_classifiers()}
|
|
72
|
-
|
|
73
|
-
# TODO: file location information inside the artefact.
|
|
74
|
-
for root, _, files in self.file_system.walk("."):
|
|
75
|
-
for file in files:
|
|
76
|
-
file_path = self.file_system.path.join(root, file)
|
|
77
|
-
classifier = self.classify_file(file_path, tags)
|
|
78
|
-
if not classifier:
|
|
79
|
-
continue
|
|
80
|
-
|
|
81
|
-
if not read_content:
|
|
82
|
-
files_by_classifier[classifier].append(file_path)
|
|
83
|
-
continue
|
|
84
|
-
|
|
85
|
-
with open(file_path, 'r') as f:
|
|
86
|
-
content = f.read()
|
|
87
|
-
try:
|
|
88
|
-
artefact = artefact_from_content(content)
|
|
89
|
-
if artefact:
|
|
90
|
-
artefact._file_path = file_path
|
|
91
|
-
files_by_classifier[classifier].append(artefact)
|
|
92
|
-
except ValueError:
|
|
93
|
-
continue
|
|
94
|
-
|
|
95
|
-
return files_by_classifier
|
|
96
|
-
|
|
97
|
-
def classify_files_new(self, tags=None) -> dict[str, list[dict]]:
|
|
67
|
+
def classify_files(self, tags=None) -> dict[str, list[dict]]:
|
|
98
68
|
files_by_classifier = {classifier: [] for classifier in Classifier.ordered_classifiers()}
|
|
99
69
|
|
|
100
70
|
for root, _, files in self.file_system.walk("."):
|
|
@@ -385,7 +385,7 @@ def test_read_status_action(classifier, artefact_name, artefact_exists, status,
|
|
|
385
385
|
|
|
386
386
|
# Configure file classifier mock
|
|
387
387
|
mock_classifier_instance = MockFileClassifier.return_value
|
|
388
|
-
mock_classifier_instance.
|
|
388
|
+
mock_classifier_instance.classify_files.return_value = {classifier: artefact_info_dicts}
|
|
389
389
|
|
|
390
390
|
# Configure file open mock
|
|
391
391
|
mock_file_handle = MagicMock()
|
|
@@ -422,7 +422,7 @@ def read_user_action(args):
|
|
|
422
422
|
artefact_name = args.parameter
|
|
423
423
|
|
|
424
424
|
file_classifier = FileClassifier(os)
|
|
425
|
-
artefact_info = file_classifier.
|
|
425
|
+
artefact_info = file_classifier.classify_files()
|
|
426
426
|
artefact_info_dicts = artefact_info.get(classifier, [])
|
|
427
427
|
|
|
428
428
|
all_artefact_names = [artefact_info["title"] for artefact_info in artefact_info_dicts]
|
|
@@ -489,7 +489,7 @@ def test_set_status_action(classifier, artefact_name, artefact_names, new_status
|
|
|
489
489
|
|
|
490
490
|
# Configure mock file classifier
|
|
491
491
|
mock_classifier_instance = MockFileClassifier.return_value
|
|
492
|
-
mock_classifier_instance.
|
|
492
|
+
mock_classifier_instance.classify_files.return_value = {classifier: artefact_info_dicts}
|
|
493
493
|
|
|
494
494
|
# Configure mock file handling
|
|
495
495
|
mock_file_handle = MagicMock()
|
|
@@ -569,7 +569,7 @@ def test_set_user_action(
|
|
|
569
569
|
|
|
570
570
|
# Configure mocks
|
|
571
571
|
mock_file_classifier_instance = MockFileClassifier.return_value
|
|
572
|
-
mock_file_classifier_instance.
|
|
572
|
+
mock_file_classifier_instance.classify_files.return_value = {classifier: artefact_info_dicts}
|
|
573
573
|
|
|
574
574
|
mock_file_handle = MagicMock()
|
|
575
575
|
mock_file_handle.__enter__.return_value.read.return_value = mock_file_content
|
|
@@ -628,7 +628,7 @@ def test_scan_action_with_issues(capsys):
|
|
|
628
628
|
patch("builtins.open", mock_open()) as m:
|
|
629
629
|
|
|
630
630
|
mock_classifier = MockFileClassifier.return_value
|
|
631
|
-
mock_classifier.
|
|
631
|
+
mock_classifier.classify_files.return_value = {
|
|
632
632
|
"classifier1": ["file1.txt"],
|
|
633
633
|
"classifier2": ["file2.txt"]
|
|
634
634
|
}
|
|
@@ -667,7 +667,7 @@ def test_scan_action_all_good(capsys):
|
|
|
667
667
|
patch("builtins.open", mock_open()) as m:
|
|
668
668
|
|
|
669
669
|
mock_classifier = MockFileClassifier.return_value
|
|
670
|
-
mock_classifier.
|
|
670
|
+
mock_classifier.classify_files.return_value = {
|
|
671
671
|
"classifier1": ["file1.txt"],
|
|
672
672
|
"classifier2": ["file2.txt"]
|
|
673
673
|
}
|