Source code for local_files_utils
import os
import nbformat
# Get the directory of the current script
[docs]
mypath = os.path.dirname(__file__)
# Define the relative path
[docs]
DIRECTORY_PATH = os.path.join(mypath, "../test_projects/RAG_examples/ANNDATA_examples/")
[docs]
def crawl_local_repo(
directory_path: str = DIRECTORY_PATH
):
"""
Crawls a local directory to retrieve file paths based on specified criteria.
Args:
directory_path (str): The path to the local project directory.
Returns:
list: List of file paths that match the criteria.
"""
# List of files to ignore
ignore_list = ["__init__.py", "example1.py", "example2.py", "example3.py", "example4.py", "example5.py", "example6.py", "example7.py",
"example8.py", "example9.py", "example10.py", "example11.py", "example12.py", "example13.py", "example14.py",
"example15.py", "example16.py", "example17.py", "example18.py", "example19.py", "example20.py", "example21.py",
"example22.py", "example23.py", "example24.py", "example25.py", "example26.py", "example27.py", "example28.py",
"example29.py", "example30.py", "example31.py", "example32.py", "example33.py", "example34.py", "example35.py"]
# Initialize an empty list to store file URLs
files = []
# Walk through the directory tree
for root, dirs, file_names in os.walk(os.path.abspath(directory_path)):
# Skip hidden directories (those starting with '.')
dirs[:] = [d for d in dirs if not d.startswith('.')]
for file_name in file_names:
# Check if the file meets the criteria for inclusion
if file_name not in ignore_list and (file_name.endswith('.py') or file_name.endswith('.ipynb')):
file_path = os.path.join(root, file_name)
files.append(file_path)
# Return the list of collected file paths
return files
# Extracts the Python code from a .py file from the local filesystem
# Extracts the Python code from a .ipynb (Jupyter Notebook) file from the local filesystem