File: extract_dependency.py

package info (click to toggle)
rpy2 3.6.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,412 kB
  • sloc: python: 18,448; ansic: 492; makefile: 197; sh: 166
file content (39 lines) | stat: -rw-r--r-- 899 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import argparse
import tomllib


def read_pyproject(path):
    with open(path, 'rb') as fh:
        pyproject = tomllib.load(fh)
    return pyproject


def extract_dependency(pyproject, dependency):
    res = []
    for item in pyproject['project']['dependencies']:
        if item.startswith(dependency):
            res.append(item)
    if len(res) == 0:
        raise ValueError('No dependency found.')
    elif len(res) > 1:
        raise ValueError(f'More than one matching dependency found: {res}')
    return res


def build_parser():
    parser = argparse.ArgumentParser()
    parser.add_argument('path')
    parser.add_argument('dependency')
    return parser


def main():
    parser = build_parser()
    args = parser.parse_args()
    pyproject = read_pyproject(args.path)
    res = extract_dependency(pyproject, args.dependency)
    print(res[0])


if __name__ == '__main__':
    main()