#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author : qichun tang
# @Contact : tqichun@gmail.com
from pathlib import Path
Makefile = "Makefile"
lines = Path(Makefile).read_text().split("\n")
packages = Path("requirements.txt").read_text().split("\n")
packages = [package for package in packages if package and (not package.startswith("#"))]
deleted_lines = []
found = False
token = "install_all"
mark = f"{token}:"
for line in lines:
if line == mark:
found = True
elif found and line.startswith("\t"):
pass
elif found and not line.startswith("\t"):
found = False
deleted_lines.append(line)
else:
deleted_lines.append(line)
final_lines = deleted_lines + [''] + [mark] + \
[f"\tpip install {package}" for package in packages]
Path(Makefile).write_text("\n".join(final_lines))
根据requirements.txt生成Makefile
原创wx61090d1892228 ©著作权
©著作权归作者所有:来自51CTO博客作者wx61090d1892228的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:瞎写的ChoiceKDE
下一篇:SMAC源码分析
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
根据Excel生成Insert或Update语句
根据Excel生成SQL
EXCEL SQL -
Python生成requirements.txt方法
Python生成requirements.txt方法
python 开发语言 虚拟环境 依赖包