[READ-ONLY] Mirror of https://github.com/mrgnw/scripts.
0

Configure Feed

Select the types of activity you want to include in your feed.

the python that pippy uses

+39
+39
getreqd
··· 1 + #!/usr/bin/env python3 2 + import ast 3 + import sys 4 + 5 + 6 + def is_standard_lib(module_name): 7 + return module_name in getattr(sys, 'stdlib_module_names', []) 8 + 9 + 10 + def get_module(name): 11 + return name.split('.')[0] 12 + 13 + 14 + def get_requirements(python_file): 15 + with open(python_file, 'r') as file: 16 + root = ast.parse(file.read(), filename='$python_file') 17 + 18 + imports = { 19 + get_module(alias.name) 20 + for node in ast.walk(root) 21 + if isinstance(node, ast.Import) 22 + for alias in node.names 23 + if not is_standard_lib(get_module(alias.name)) 24 + } 25 + 26 + from_imports = { 27 + get_module(node.module) 28 + for node in ast.walk(root) 29 + if isinstance(node, ast.ImportFrom) 30 + if not is_standard_lib(get_module(node.module)) 31 + } 32 + 33 + return imports.union(from_imports) 34 + 35 + 36 + if __name__ == '__main__': 37 + requirements = get_requirements(sys.argv[1]) 38 + for r in requirements: 39 + print(r)