packagelister.whouses API documentation

# packagelister.whouses

View Source

     1import argparse
     2
     3from pathier import Pathier
     4
     5from packagelister import scan
     6
     7
     8def get_args() -> argparse.Namespace:
     9    parser = argparse.ArgumentParser()
    10
    11    parser.add_argument(
    12        "package",
    13        type=str,
    14        help=""" Scan the current working directory for project folders that use this package.""",
    15    )
    16
    17    parser.add_argument(
    18        "-i",
    19        "--ignore",
    20        nargs="*",
    21        default=["pkgs", "envs"],
    22        type=str,
    23        help=""" Ignore these folders. """,
    24    )
    25    args = parser.parse_args()
    26
    27    return args
    28
    29
    30def find(root: Pathier, package: str, ignore: list[str] = []) -> list[str]:
    31    """Find what sub-folders of `root`, excluding those in `ignore`, have files that use `package`."""
    32    package_users = []
    33    for project in root.iterdir():
    34        if project.is_dir() and project.stem not in ignore:
    35            if package in scan(project):
    36                package_users.append(project.stem)
    37    return package_users
    38
    39
    40def main(args: argparse.Namespace = None):
    41    if not args:
    42        args = get_args()
    43    package_users = find(Pathier.cwd(), args.package, args.ignore)
    44    print(f"The following folders have files that use {args.package}:")
    45    print(*package_users, sep="\n")
    46
    47
    48if __name__ == "__main__":
    49    main(get_args())

def get_args() -> argparse.Namespace: View Source

     9def get_args() -> argparse.Namespace:
    10    parser = argparse.ArgumentParser()
    11
    12    parser.add_argument(
    13        "package",
    14        type=str,
    15        help=""" Scan the current working directory for project folders that use this package.""",
    16    )
    17
    18    parser.add_argument(
    19        "-i",
    20        "--ignore",
    21        nargs="*",
    22        default=["pkgs", "envs"],
    23        type=str,
    24        help=""" Ignore these folders. """,
    25    )
    26    args = parser.parse_args()
    27
    28    return args

def find( root: pathier.pathier.Pathier, package: str, ignore: list[str] = []) -> list[str]: View Source

    31def find(root: Pathier, package: str, ignore: list[str] = []) -> list[str]:
    32    """Find what sub-folders of `root`, excluding those in `ignore`, have files that use `package`."""
    33    package_users = []
    34    for project in root.iterdir():
    35        if project.is_dir() and project.stem not in ignore:
    36            if package in scan(project):
    37                package_users.append(project.stem)
    38    return package_users

Find what sub-folders of `root`, excluding those in `ignore`, have files that use `package`.

def main(args: argparse.Namespace = None): View Source

    41def main(args: argparse.Namespace = None):
    42    if not args:
    43        args = get_args()
    44    package_users = find(Pathier.cwd(), args.package, args.ignore)
    45    print(f"The following folders have files that use {args.package}:")
    46    print(*package_users, sep="\n")