-
Notifications
You must be signed in to change notification settings - Fork 3
/
requirements.py
executable file
·44 lines (33 loc) · 1.11 KB
/
requirements.py
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
40
41
42
43
44
#! /usr/bin/env python
import argparse
import os
def _find_tomllib():
try:
import tomllib
except ModuleNotFoundError:
import tomli as tomllib
return tomllib
def requirements(extras):
tomllib = _find_tomllib()
with open("pyproject.toml", "rb") as fp:
project = tomllib.load(fp)["project"]
dependencies = {}
if extras:
optional_dependencies = project.get("optional-dependencies", {})
for extra in extras:
dependencies[f"[project.optional-dependencies.{extra}]"] = (
optional_dependencies[extra]
)
else:
dependencies["[project.dependencies]"] = project["dependencies"]
print("# Requirements extracted from pyproject.toml")
for section, packages in dependencies.items():
print(f"# {section}")
print(os.linesep.join(packages))
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Extract requirements information from pyproject.toml"
)
parser.add_argument("extras", type=str, nargs="*")
args = parser.parse_args()
requirements(args.extras)