initial commit
This commit is contained in:
31
pythonapp/Decider/misc.py
Normal file
31
pythonapp/Decider/misc.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from pathlib import Path
|
||||
|
||||
from pythonapp.Decider.Loader import RequirementInfo
|
||||
|
||||
|
||||
def requirements_separator(req_file: Path | str):
|
||||
try:
|
||||
with open(req_file, 'r') as file:
|
||||
lines = [line.strip() for line in file]
|
||||
req = []
|
||||
opt = []
|
||||
req_bool = True
|
||||
for line in lines:
|
||||
if line.startswith("#"): req_bool = False
|
||||
if req_bool: req.append(line)
|
||||
else: opt.append(line)
|
||||
except FileNotFoundError:
|
||||
raise RuntimeError(f"File {req_file} not exists")
|
||||
|
||||
return req, opt
|
||||
|
||||
def requirements_converter(req: list[str], opt: list[str]) -> list[RequirementInfo]:
|
||||
res: list[RequirementInfo] = []
|
||||
for line in req:
|
||||
if line.startswith("#") or line == '': continue
|
||||
res.append(RequirementInfo.from_requirement_string(line.split(" ")[0].strip(), 'required', 'requested'))
|
||||
for line in opt:
|
||||
if line.startswith("#") or line == '': continue
|
||||
res.append(RequirementInfo.from_requirement_string(line.split(" ")[0].strip(), 'optional', 'requested'))
|
||||
|
||||
return res
|
||||
Reference in New Issue
Block a user