mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-04 11:45:00 +00:00
style: Format watch.py with black and add newlines between functions
This commit is contained in:
parent
81903598a8
commit
21876e72fe
1 changed files with 33 additions and 7 deletions
|
@ -1,7 +1,9 @@
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Set
|
from typing import Set
|
||||||
|
|
||||||
from watchfiles import watch
|
from watchfiles import watch
|
||||||
|
|
||||||
|
|
||||||
def is_source_file(path: Path) -> bool:
|
def is_source_file(path: Path) -> bool:
|
||||||
"""
|
"""
|
||||||
Check if a file is a source file that uses # or // style comments.
|
Check if a file is a source file that uses # or // style comments.
|
||||||
|
@ -9,20 +11,42 @@ def is_source_file(path: Path) -> bool:
|
||||||
"""
|
"""
|
||||||
COMMENT_STYLE_EXTENSIONS = {
|
COMMENT_STYLE_EXTENSIONS = {
|
||||||
# # style comments
|
# # style comments
|
||||||
'.py', '.r', '.rb', '.pl', '.pm', '.sh', '.bash', '.yaml', '.yml',
|
".py",
|
||||||
|
".r",
|
||||||
|
".rb",
|
||||||
|
".pl",
|
||||||
|
".pm",
|
||||||
|
".sh",
|
||||||
|
".bash",
|
||||||
|
".yaml",
|
||||||
|
".yml",
|
||||||
# // style comments
|
# // style comments
|
||||||
'.js', '.ts', '.jsx', '.tsx', '.cpp', '.c', '.h', '.hpp', '.java',
|
".js",
|
||||||
'.swift', '.kt', '.cs', '.go', '.rs', '.php'
|
".ts",
|
||||||
|
".jsx",
|
||||||
|
".tsx",
|
||||||
|
".cpp",
|
||||||
|
".c",
|
||||||
|
".h",
|
||||||
|
".hpp",
|
||||||
|
".java",
|
||||||
|
".swift",
|
||||||
|
".kt",
|
||||||
|
".cs",
|
||||||
|
".go",
|
||||||
|
".rs",
|
||||||
|
".php",
|
||||||
}
|
}
|
||||||
return path.suffix.lower() in COMMENT_STYLE_EXTENSIONS
|
return path.suffix.lower() in COMMENT_STYLE_EXTENSIONS
|
||||||
|
|
||||||
|
|
||||||
def watch_source_files(directory: str) -> Set[str]:
|
def watch_source_files(directory: str) -> Set[str]:
|
||||||
"""
|
"""
|
||||||
Watch for changes to source files in the given directory and its subdirectories.
|
Watch for changes to source files in the given directory and its subdirectories.
|
||||||
Returns a set of changed file paths whenever changes are detected.
|
Returns a set of changed file paths whenever changes are detected.
|
||||||
"""
|
"""
|
||||||
root = Path(directory)
|
root = Path(directory)
|
||||||
|
|
||||||
# Create a filter function that only accepts source files
|
# Create a filter function that only accepts source files
|
||||||
def filter_func(change_type, path):
|
def filter_func(change_type, path):
|
||||||
return is_source_file(Path(path))
|
return is_source_file(Path(path))
|
||||||
|
@ -33,17 +57,18 @@ def watch_source_files(directory: str) -> Set[str]:
|
||||||
changed_files = {str(Path(change[1])) for change in changes}
|
changed_files = {str(Path(change[1])) for change in changes}
|
||||||
yield changed_files
|
yield changed_files
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Example usage of the file watcher"""
|
"""Example usage of the file watcher"""
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
if len(sys.argv) != 2:
|
if len(sys.argv) != 2:
|
||||||
print("Usage: python watch.py <directory>")
|
print("Usage: python watch.py <directory>")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
directory = sys.argv[1]
|
directory = sys.argv[1]
|
||||||
print(f"Watching source files in {directory}...")
|
print(f"Watching source files in {directory}...")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for changed_files in watch_source_files(directory):
|
for changed_files in watch_source_files(directory):
|
||||||
print("\nChanged files:")
|
print("\nChanged files:")
|
||||||
|
@ -52,5 +77,6 @@ def main():
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("\nStopped watching files")
|
print("\nStopped watching files")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue