|
|
@ -439,34 +439,60 @@ def check_dict_alignment(base: Dict, custom: Dict, e=None): |
|
|
|
|
|
|
|
|
|
|
|
def merge_equals_args(args: List[str]) -> List[str]: |
|
|
|
def merge_equals_args(args: List[str]) -> List[str]: |
|
|
|
""" |
|
|
|
""" |
|
|
|
Merges arguments around isolated '=' in a list of strings, handling three cases: |
|
|
|
Merges arguments around isolated '=' in a list of strings and joins fragments with brackets. |
|
|
|
1. ['arg', '=', 'val'] becomes ['arg=val'], |
|
|
|
|
|
|
|
2. ['arg=', 'val'] becomes ['arg=val'], |
|
|
|
This function handles the following cases: |
|
|
|
3. ['arg', '=val'] becomes ['arg=val']. |
|
|
|
1. ['arg', '=', 'val'] becomes ['arg=val'] |
|
|
|
|
|
|
|
2. ['arg=', 'val'] becomes ['arg=val'] |
|
|
|
|
|
|
|
3. ['arg', '=val'] becomes ['arg=val'] |
|
|
|
|
|
|
|
4. Joins fragments with brackets, e.g., ['imgsz=[3,', '640,', '640]'] becomes ['imgsz=[3,640,640]'] |
|
|
|
|
|
|
|
|
|
|
|
Args: |
|
|
|
Args: |
|
|
|
args (List[str]): A list of strings where each element represents an argument. |
|
|
|
args (List[str]): A list of strings where each element represents an argument or fragment. |
|
|
|
|
|
|
|
|
|
|
|
Returns: |
|
|
|
Returns: |
|
|
|
(List[str]): A list of strings where the arguments around isolated '=' are merged. |
|
|
|
List[str]: A list of strings where the arguments around isolated '=' are merged and fragments with brackets are joined. |
|
|
|
|
|
|
|
|
|
|
|
Examples: |
|
|
|
Examples: |
|
|
|
>>> args = ["arg1", "=", "value", "arg2=", "value2", "arg3", "=value3"] |
|
|
|
>>> args = ["arg1", "=", "value", "arg2=", "value2", "arg3", "=value3", "imgsz=[3,", "640,", "640]"] |
|
|
|
>>> merge_equals_args(args) |
|
|
|
>>> merge_and_join_args(args) |
|
|
|
['arg1=value', 'arg2=value2', 'arg3=value3'] |
|
|
|
['arg1=value', 'arg2=value2', 'arg3=value3', 'imgsz=[3,640,640]'] |
|
|
|
""" |
|
|
|
""" |
|
|
|
new_args = [] |
|
|
|
new_args = [] |
|
|
|
for i, arg in enumerate(args): |
|
|
|
current = "" |
|
|
|
|
|
|
|
depth = 0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
i = 0 |
|
|
|
|
|
|
|
while i < len(args): |
|
|
|
|
|
|
|
arg = args[i] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Handle equals sign merging |
|
|
|
if arg == "=" and 0 < i < len(args) - 1: # merge ['arg', '=', 'val'] |
|
|
|
if arg == "=" and 0 < i < len(args) - 1: # merge ['arg', '=', 'val'] |
|
|
|
new_args[-1] += f"={args[i + 1]}" |
|
|
|
new_args[-1] += f"={args[i + 1]}" |
|
|
|
del args[i + 1] |
|
|
|
i += 2 |
|
|
|
|
|
|
|
continue |
|
|
|
elif arg.endswith("=") and i < len(args) - 1 and "=" not in args[i + 1]: # merge ['arg=', 'val'] |
|
|
|
elif arg.endswith("=") and i < len(args) - 1 and "=" not in args[i + 1]: # merge ['arg=', 'val'] |
|
|
|
new_args.append(f"{arg}{args[i + 1]}") |
|
|
|
new_args.append(f"{arg}{args[i + 1]}") |
|
|
|
del args[i + 1] |
|
|
|
i += 2 |
|
|
|
|
|
|
|
continue |
|
|
|
elif arg.startswith("=") and i > 0: # merge ['arg', '=val'] |
|
|
|
elif arg.startswith("=") and i > 0: # merge ['arg', '=val'] |
|
|
|
new_args[-1] += arg |
|
|
|
new_args[-1] += arg |
|
|
|
else: |
|
|
|
i += 1 |
|
|
|
new_args.append(arg) |
|
|
|
continue |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Handle bracket joining |
|
|
|
|
|
|
|
depth += arg.count("[") - arg.count("]") |
|
|
|
|
|
|
|
current += arg |
|
|
|
|
|
|
|
if depth == 0: |
|
|
|
|
|
|
|
new_args.append(current) |
|
|
|
|
|
|
|
current = "" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
i += 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Append any remaining current string |
|
|
|
|
|
|
|
if current: |
|
|
|
|
|
|
|
new_args.append(current) |
|
|
|
|
|
|
|
|
|
|
|
return new_args |
|
|
|
return new_args |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -483,7 +509,7 @@ def handle_yolo_hub(args: List[str]) -> None: |
|
|
|
|
|
|
|
|
|
|
|
Examples: |
|
|
|
Examples: |
|
|
|
```bash |
|
|
|
```bash |
|
|
|
yolo hub login YOUR_API_KEY |
|
|
|
yolo login YOUR_API_KEY |
|
|
|
``` |
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
Notes: |
|
|
|
Notes: |
|
|
|