Skip to content

Instantly share code, notes, and snippets.

@synodriver
Last active July 28, 2022 08:33
Show Gist options
  • Save synodriver/fbfbc301135c12a1aebb92374d6a2760 to your computer and use it in GitHub Desktop.
Save synodriver/fbfbc301135c12a1aebb92374d6a2760 to your computer and use it in GitHub Desktop.
自动格式化
"""
Copyright (c) 2008-2022 synodriver <[email protected]>
"""
import asyncio
from pathlib import Path
from watchfiles import Change, awatch
async def main():
async for changes in awatch("."):
for change in changes:
# print(change[0] == Change.modified, Path(change[1]).suffix)
if change[0] == Change.modified:
if Path(change[1]).suffix == ".py":
print("detected")
p = await asyncio.create_subprocess_exec("isort", ".")
await p.wait()
p = await asyncio.create_subprocess_exec("black", ".")
await p.wait()
elif Path(change[1]).name == "go.mod":
p = await asyncio.create_subprocess_exec("go", "mod", "tidy")
await p.wait()
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
print("stopped via KeyboardInterrupt")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment