scripts/deps.py
def analyze_crate_dependencies(path, data=None):
    """
    Checks for unused externs and gives suggestions for both src and tests/benches directories.
    :param path: The path to the crate to analyze
    :param data: Optional crate data loaded from `load_cargo_toml`
    :return: A dict in the form:
    {
        'name': <crate name>,
        'remove': [<crate>, ...],
        'move-to-dev': [<crate>, ...],
    }
    """
    def get_dependencies(dependencies):
        deps = []
        renames = {}
        for dep in dependencies:
            deps.append(dep['local_name'])
            if dep['local_name'] != dep['name']:
                renames[dep['local_name']] = dep['name']
        return deps, renames

    data = load_cargo_toml(os.path.join(path, 'Cargo.toml'))
    local_dependencies, renames = get_dependencies(data['dependencies'])
    local_dev_dependencies, dev_renames = get_dependencies(data['dev-dependencies'])
    renames.update(dev_renames)

    unused_dependencies = find_unused_externs(os.path.join(path, 'src'), local_dependencies)
    unused_dev_dependencies = unused_dependencies
    if os.path.isdir(os.path.join(path, 'tests')):
        unused_dev_dependencies = find_unused_externs(os.path.join(path, 'tests'),
                                                      local_dependencies + local_dev_dependencies)
    if os.path.isdir(os.path.join(path, 'benches')):
        unused_dev_dependencies = unused_dev_dependencies.intersection(find_unused_externs(os.path.join(path, 'benches'),
                                                      local_dependencies + local_dev_dependencies))

    # We should move those dependencies that are unused in src but used in the tests path
    to_move = unused_dependencies.intersection(set(local_dependencies) - unused_dev_dependencies)
    to_remove = (unused_dependencies - to_move) | unused_dev_dependencies.intersection(set(local_dev_dependencies) - set(local_dependencies))

    to_move = [renames[crate] if crate in renames else crate for crate in to_move]
    to_remove = [renames[crate] if crate in renames else crate for crate in to_remove]
    return {
        'name': data['name'],
        'remove': to_remove,
        'move-to-dev': to_move,
    }

    Checks for unused externs and gives suggestions for both src and tests/benches directories.
    :param path: The path to the crate to analyze
    :param data: Optional crate data loaded from `load_cargo_toml`
    :return: A dict in the form:
    {
        'name': <crate name>,
        'remove': [<crate>, ...],
        'move-to-dev': [<crate>, ...],
    }
    
Checks for unused externs and gives suggestions for both src and tests/benches directories.
Checks for unused externs and gives suggestions for both src and tests / benches directories .
def analyze_crate_dependencies(path, data=None):
    def get_dependencies(dependencies):
        deps = []
        renames = {}
        for dep in dependencies:
            deps.append(dep['local_name'])
            if dep['local_name'] != dep['name']:
                renames[dep['local_name']] = dep['name']
        return deps, renames
    data = load_cargo_toml(os.path.join(path, 'Cargo.toml'))
    local_dependencies, renames = get_dependencies(data['dependencies'])
    local_dev_dependencies, dev_renames = get_dependencies(data['dev-dependencies'])
    renames.update(dev_renames)
    unused_dependencies = find_unused_externs(os.path.join(path, 'src'), local_dependencies)
    unused_dev_dependencies = unused_dependencies
    if os.path.isdir(os.path.join(path, 'tests')):
        unused_dev_dependencies = find_unused_externs(os.path.join(path, 'tests'),
                                                      local_dependencies + local_dev_dependencies)
    if os.path.isdir(os.path.join(path, 'benches')):
        unused_dev_dependencies = unused_dev_dependencies.intersection(find_unused_externs(os.path.join(path, 'benches'),
                                                      local_dependencies + local_dev_dependencies))
    to_move = unused_dependencies.intersection(set(local_dependencies) - unused_dev_dependencies)
    to_remove = (unused_dependencies - to_move) | unused_dev_dependencies.intersection(set(local_dev_dependencies) - set(local_dependencies))
    to_move = [renames[crate] if crate in renames else crate for crate in to_move]
    to_remove = [renames[crate] if crate in renames else crate for crate in to_remove]
    return {
        'name': data['name'],
        'remove': to_remove,
        'move-to-dev': to_move,
    }
def analyze_crate_dependencies ( path , data = None ) : def get_dependencies ( dependencies ) : deps = [ ] renames = { } for dep in dependencies : deps . append ( dep [ 'local_name' ] ) if dep [ 'local_name' ] != dep [ 'name' ] : renames [ dep [ 'local_name' ] ] = dep [ 'name' ] return deps , renames data = load_cargo_toml ( os . path . join ( path , 'Cargo.toml' ) ) local_dependencies , renames = get_dependencies ( data [ 'dependencies' ] ) local_dev_dependencies , dev_renames = get_dependencies ( data [ 'dev-dependencies' ] ) renames . update ( dev_renames ) unused_dependencies = find_unused_externs ( os . path . join ( path , 'src' ) , local_dependencies ) unused_dev_dependencies = unused_dependencies if os . path . isdir ( os . path . join ( path , 'tests' ) ) : unused_dev_dependencies = find_unused_externs ( os . path . join ( path , 'tests' ) , local_dependencies + local_dev_dependencies ) if os . path . isdir ( os . path . join ( path , 'benches' ) ) : unused_dev_dependencies = unused_dev_dependencies . intersection ( find_unused_externs ( os . path . join ( path , 'benches' ) , local_dependencies + local_dev_dependencies ) ) to_move = unused_dependencies . intersection ( set ( local_dependencies ) - unused_dev_dependencies ) to_remove = ( unused_dependencies - to_move ) | unused_dev_dependencies . intersection ( set ( local_dev_dependencies ) - set ( local_dependencies ) ) to_move = [ renames [ crate ] if crate in renames else crate for crate in to_move ] to_remove = [ renames [ crate ] if crate in renames else crate for crate in to_remove ] return { 'name' : data [ 'name' ] , 'remove' : to_remove , 'move-to-dev' : to_move , }
Checks for unused externs and gives suggestions for both src and tests/benches directories.
Checks for unused externs and gives suggestions for both src and tests / benches directories .
"""
    Checks for unused externs and gives suggestions for both src and tests/benches directories.
    :param path: The path to the crate to analyze
    :param data: Optional crate data loaded from `load_cargo_toml`
    :return: A dict in the form:
    {
        'name': <crate name>,
        'remove': [<crate>, ...],
        'move-to-dev': [<crate>, ...],
    }
    """ # We should move those dependencies that are unused in src but used in the tests path
None
path
The path to the crate to analyze
The path to the crate to analyze
data
Optional crate data loaded from `load_cargo_toml`
Optional crate data loaded from ` load_cargo_toml `