Skip to content

Commit e16a1f0

Browse files
committed
use watchdog instead of pyinotify
pyinotify is very old and does not work with python 3.12 due to asyncore.
1 parent a7b271c commit e16a1f0

3 files changed

Lines changed: 14 additions & 17 deletions

File tree

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def run(self):
3636
],
3737
},
3838
install_requires=[
39-
"pyinotify==0.9.6",
39+
"watchdog",
4040
"trimesh==4.4.*",
4141
"solidpython2==2.1.*",
4242
"cadquery==2.4.*",

solid_node/core/builder.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import sys
2-
import pyinotify
32
import asyncio
43
import traceback
54
import logging
65
import time
7-
from asgiref.sync import async_to_sync
86
from asyncio import Future
7+
from watchdog.observers import Observer
8+
from watchdog.events import FileSystemEventHandler
99
from .loader import load_node
1010
from .git import GitRepo
1111
from .broker import BrokerClient
@@ -16,23 +16,20 @@
1616
logger = logging.getLogger('core.builder')
1717

1818

19-
class Builder(pyinotify.ProcessEvent):
19+
class Builder(FileSystemEventHandler):
2020
"""Monitors .py files and generate STLs, and exit on any change"""
2121
def __init__(self, path):
2222
super().__init__()
2323
self.path = path
2424

2525
self.repo = GitRepo(path)
2626
self.file_changed = Future()
27-
self.wm = pyinotify.WatchManager()
28-
29-
loop = asyncio.get_event_loop()
30-
pyinotify.AsyncioNotifier(self.wm, loop, default_proc_fun=self)
27+
self.observer = Observer()
3128

3229
def start(self):
3330
task = self._start()
34-
loop = asyncio.get_event_loop()
35-
loop.run_until_complete(task)
31+
self.loop = asyncio.get_event_loop()
32+
self.loop.run_until_complete(task)
3633

3734
async def _start(self):
3835
logger.info('START')
@@ -58,8 +55,9 @@ async def _start(self):
5855
sys.exit(0)
5956

6057
for path in self.node.files:
61-
mask = pyinotify.IN_CLOSE_WRITE
62-
self.wm.add_watch(path, mask)
58+
self.observer.schedule(self, path, recursive=False)
59+
60+
self.observer.start()
6361

6462
try:
6563
await self.generate_stl()
@@ -101,8 +99,8 @@ async def rollback(self, error_message):
10199
self.repo.revert_last_commit()
102100
sys.exit(0)
103101

104-
def process_default(self, event):
105-
if not event.maskname == 'IN_CLOSE_WRITE':
102+
def on_modified(self, event):
103+
if event.is_directory:
106104
return
107-
logging.info(f'{event.pathname} changed, reloading')
108-
self.file_changed.set_result(True)
105+
logging.info(f'{event.src_path} changed, reloading')
106+
self.loop.call_soon_threadsafe(self.file_changed.set_result, True)

solid_node/node/base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import inspect
55
import logging
66
import importlib
7-
import pyinotify
87
import trimesh
98
import numpy as np
109
from decimal import Decimal

0 commit comments

Comments
 (0)