1 Star 0 Fork 0

WaketZheng / aiopathlib

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
clear_requirements.py 799 Bytes
一键复制 编辑 原始数据 按行查看 历史
#!/usr/bin/env python3
import asyncio
from aiopathlib import AsyncPath
async def clear_it(filename):
p = AsyncPath(filename)
ss = (await p.read_text()).splitlines()
unique = {}
for i in ss:
package = i.split(";", 1)[0]
name, version = package.strip().split("==")
v = unique.get(name)
if not v or v[0] < version:
unique[name] = (version, package)
else:
print(name, "already exists! Ignore.")
lines_count = len(unique)
print(len(ss) - lines_count, "removed!")
await p.write_text("\n".join(i[1] for i in unique.values()))
print(p, "updated! Only", lines_count, "lines now.")
def main():
filename = "dev_requirements.txt"
asyncio.run(clear_it(filename))
if __name__ == "__main__":
main()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/waketzheng/aiopathlib.git
git@gitee.com:waketzheng/aiopathlib.git
waketzheng
aiopathlib
aiopathlib
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891