olivia_finder.data_source.repository_scrapers.r

 1import re
 2from typing import Dict, List
 3
 4def parse_dependencies(dependencies_str: str) -> List[Dict[str, str]]:
 5    '''
 6    Parses the dependencies string and returns a list of dictionaries with the name and version of each dependency
 7    TODO: A fix is needed to target the version of the dependency, as it's not always well defined
 8
 9    Parameters
10    ----------
11    dependencies_str : str
12        The dependencies string
13
14    Returns
15    -------
16    List[Dict[str, str]]
17        A list of dictionaries with the name and version of each dependency    
18    '''
19
20    # Remove unnecessary line breaks, tabs, and spaces
21    pattern = r'\S+\s*(?:\(([^\)]*)\))?'
22
23    # Get names and versions of dependencies
24    versions = [re.findall(pattern, dep)[0] if re.findall(pattern, dep) else None for dep in dependencies_str.split(",")]
25    names = [re.sub(r'\s*\(.*\)', '', name.strip()) for name in dependencies_str.split(",")]
26
27    # Check if the lists have the same length and are not empty
28    if len(names) != len(versions) or not names:
29        return []
30
31    return [
32        {'name': names[i], 'version': versions[i]} for i in range(len(names))
33    ]
def parse_dependencies(dependencies_str: str) -> List[Dict[str, str]]:
 5def parse_dependencies(dependencies_str: str) -> List[Dict[str, str]]:
 6    '''
 7    Parses the dependencies string and returns a list of dictionaries with the name and version of each dependency
 8    TODO: A fix is needed to target the version of the dependency, as it's not always well defined
 9
10    Parameters
11    ----------
12    dependencies_str : str
13        The dependencies string
14
15    Returns
16    -------
17    List[Dict[str, str]]
18        A list of dictionaries with the name and version of each dependency    
19    '''
20
21    # Remove unnecessary line breaks, tabs, and spaces
22    pattern = r'\S+\s*(?:\(([^\)]*)\))?'
23
24    # Get names and versions of dependencies
25    versions = [re.findall(pattern, dep)[0] if re.findall(pattern, dep) else None for dep in dependencies_str.split(",")]
26    names = [re.sub(r'\s*\(.*\)', '', name.strip()) for name in dependencies_str.split(",")]
27
28    # Check if the lists have the same length and are not empty
29    if len(names) != len(versions) or not names:
30        return []
31
32    return [
33        {'name': names[i], 'version': versions[i]} for i in range(len(names))
34    ]

Parses the dependencies string and returns a list of dictionaries with the name and version of each dependency TODO: A fix is needed to target the version of the dependency, as it's not always well defined

Parameters
  • dependencies_str (str): The dependencies string
Returns
  • List[Dict[str, str]]: A list of dictionaries with the name and version of each dependency