ultralytics 8.0.239 Ultralytics Actions and hub-sdk adoption (#7431)
Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com> Co-authored-by: UltralyticsAssistant <web@ultralytics.com> Co-authored-by: Burhan <62214284+Burhan-Q@users.noreply.github.com> Co-authored-by: Kayzwer <68285002+Kayzwer@users.noreply.github.com>
This commit is contained in:
parent
e795277391
commit
fe27db2f6e
139 changed files with 6870 additions and 5125 deletions
|
|
@ -14,14 +14,14 @@ from ultralytics.utils import ROOT
|
|||
|
||||
NEW_YAML_DIR = ROOT.parent
|
||||
CODE_DIR = ROOT
|
||||
REFERENCE_DIR = ROOT.parent / 'docs/en/reference'
|
||||
REFERENCE_DIR = ROOT.parent / "docs/en/reference"
|
||||
|
||||
|
||||
def extract_classes_and_functions(filepath: Path) -> tuple:
|
||||
"""Extracts class and function names from a given Python file."""
|
||||
content = filepath.read_text()
|
||||
class_pattern = r'(?:^|\n)class\s(\w+)(?:\(|:)'
|
||||
func_pattern = r'(?:^|\n)def\s(\w+)\('
|
||||
class_pattern = r"(?:^|\n)class\s(\w+)(?:\(|:)"
|
||||
func_pattern = r"(?:^|\n)def\s(\w+)\("
|
||||
|
||||
classes = re.findall(class_pattern, content)
|
||||
functions = re.findall(func_pattern, content)
|
||||
|
|
@ -31,31 +31,31 @@ def extract_classes_and_functions(filepath: Path) -> tuple:
|
|||
|
||||
def create_markdown(py_filepath: Path, module_path: str, classes: list, functions: list):
|
||||
"""Creates a Markdown file containing the API reference for the given Python module."""
|
||||
md_filepath = py_filepath.with_suffix('.md')
|
||||
md_filepath = py_filepath.with_suffix(".md")
|
||||
|
||||
# Read existing content and keep header content between first two ---
|
||||
header_content = ''
|
||||
header_content = ""
|
||||
if md_filepath.exists():
|
||||
existing_content = md_filepath.read_text()
|
||||
header_parts = existing_content.split('---')
|
||||
header_parts = existing_content.split("---")
|
||||
for part in header_parts:
|
||||
if 'description:' in part or 'comments:' in part:
|
||||
header_content += f'---{part}---\n\n'
|
||||
if "description:" in part or "comments:" in part:
|
||||
header_content += f"---{part}---\n\n"
|
||||
|
||||
module_name = module_path.replace('.__init__', '')
|
||||
module_path = module_path.replace('.', '/')
|
||||
url = f'https://github.com/ultralytics/ultralytics/blob/main/{module_path}.py'
|
||||
edit = f'https://github.com/ultralytics/ultralytics/edit/main/{module_path}.py'
|
||||
module_name = module_path.replace(".__init__", "")
|
||||
module_path = module_path.replace(".", "/")
|
||||
url = f"https://github.com/ultralytics/ultralytics/blob/main/{module_path}.py"
|
||||
edit = f"https://github.com/ultralytics/ultralytics/edit/main/{module_path}.py"
|
||||
title_content = (
|
||||
f'# Reference for `{module_path}.py`\n\n'
|
||||
f'!!! Note\n\n'
|
||||
f' This file is available at [{url}]({url}). If you spot a problem please help fix it by [contributing](https://docs.ultralytics.com/help/contributing/) a [Pull Request]({edit}) 🛠️. Thank you 🙏!\n\n'
|
||||
f"# Reference for `{module_path}.py`\n\n"
|
||||
f"!!! Note\n\n"
|
||||
f" This file is available at [{url}]({url}). If you spot a problem please help fix it by [contributing](https://docs.ultralytics.com/help/contributing/) a [Pull Request]({edit}) 🛠️. Thank you 🙏!\n\n"
|
||||
)
|
||||
md_content = ['<br><br>\n'] + [f'## ::: {module_name}.{class_name}\n\n<br><br>\n' for class_name in classes]
|
||||
md_content.extend(f'## ::: {module_name}.{func_name}\n\n<br><br>\n' for func_name in functions)
|
||||
md_content = header_content + title_content + '\n'.join(md_content)
|
||||
if not md_content.endswith('\n'):
|
||||
md_content += '\n'
|
||||
md_content = ["<br><br>\n"] + [f"## ::: {module_name}.{class_name}\n\n<br><br>\n" for class_name in classes]
|
||||
md_content.extend(f"## ::: {module_name}.{func_name}\n\n<br><br>\n" for func_name in functions)
|
||||
md_content = header_content + title_content + "\n".join(md_content)
|
||||
if not md_content.endswith("\n"):
|
||||
md_content += "\n"
|
||||
|
||||
md_filepath.parent.mkdir(parents=True, exist_ok=True)
|
||||
md_filepath.write_text(md_content)
|
||||
|
|
@ -80,28 +80,28 @@ def create_nav_menu_yaml(nav_items: list):
|
|||
for item_str in nav_items:
|
||||
item = Path(item_str)
|
||||
parts = item.parts
|
||||
current_level = nav_tree['reference']
|
||||
current_level = nav_tree["reference"]
|
||||
for part in parts[2:-1]: # skip the first two parts (docs and reference) and the last part (filename)
|
||||
current_level = current_level[part]
|
||||
|
||||
md_file_name = parts[-1].replace('.md', '')
|
||||
md_file_name = parts[-1].replace(".md", "")
|
||||
current_level[md_file_name] = item
|
||||
|
||||
nav_tree_sorted = sort_nested_dict(nav_tree)
|
||||
|
||||
def _dict_to_yaml(d, level=0):
|
||||
"""Converts a nested dictionary to a YAML-formatted string with indentation."""
|
||||
yaml_str = ''
|
||||
indent = ' ' * level
|
||||
yaml_str = ""
|
||||
indent = " " * level
|
||||
for k, v in d.items():
|
||||
if isinstance(v, dict):
|
||||
yaml_str += f'{indent}- {k}:\n{_dict_to_yaml(v, level + 1)}'
|
||||
yaml_str += f"{indent}- {k}:\n{_dict_to_yaml(v, level + 1)}"
|
||||
else:
|
||||
yaml_str += f"{indent}- {k}: {str(v).replace('docs/en/', '')}\n"
|
||||
return yaml_str
|
||||
|
||||
# Print updated YAML reference section
|
||||
print('Scan complete, new mkdocs.yaml reference section is:\n\n', _dict_to_yaml(nav_tree_sorted))
|
||||
print("Scan complete, new mkdocs.yaml reference section is:\n\n", _dict_to_yaml(nav_tree_sorted))
|
||||
|
||||
# Save new YAML reference section
|
||||
# (NEW_YAML_DIR / 'nav_menu_updated.yml').write_text(_dict_to_yaml(nav_tree_sorted))
|
||||
|
|
@ -111,7 +111,7 @@ def main():
|
|||
"""Main function to extract class and function names, create Markdown files, and generate a YAML navigation menu."""
|
||||
nav_items = []
|
||||
|
||||
for py_filepath in CODE_DIR.rglob('*.py'):
|
||||
for py_filepath in CODE_DIR.rglob("*.py"):
|
||||
classes, functions = extract_classes_and_functions(py_filepath)
|
||||
|
||||
if classes or functions:
|
||||
|
|
@ -124,5 +124,5 @@ def main():
|
|||
create_nav_menu_yaml(nav_items)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue