Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdff75e7

Browse files
all watchdog to be missing, require new curtsies
1 parent8c41de0 commitdff75e7

File tree

3 files changed

+77
-69
lines changed

3 files changed

+77
-69
lines changed

‎bpython/curtsiesfrontend/filewatch.py‎

Lines changed: 51 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,59 +4,63 @@
44

55
frombpythonimportimportcompletion
66

7-
fromwatchdog.observersimportObserver
8-
fromwatchdog.eventsimportFileSystemEventHandler
7+
try:
8+
fromwatchdog.observersimportObserver
9+
fromwatchdog.eventsimportFileSystemEventHandler
10+
exceptImportError:
11+
defModuleChangedEventHandler(*args):
12+
returnNone
13+
else:
14+
classModuleChangedEventHandler(FileSystemEventHandler):
15+
def__init__(self,paths,on_change):
16+
self.dirs=defaultdict(set)
17+
self.on_change=on_change
18+
self.modules_to_add_later= []
19+
self.observer=Observer()
20+
self.old_dirs=defaultdict(set)
21+
forpathinpaths:
22+
self.add_module(path)
23+
self.observer.start()
924

10-
classModuleChangedEventHandler(FileSystemEventHandler):
11-
def__init__(self,paths,on_change):
12-
self.dirs=defaultdict(set)
13-
self.on_change=on_change
14-
self.modules_to_add_later= []
15-
self.observer=Observer()
16-
self.old_dirs=defaultdict(set)
17-
forpathinpaths:
18-
self.add_module(path)
19-
self.observer.start()
25+
defreset(self):
26+
self.dirs=defaultdict(set)
27+
delself.modules_to_add_later[:]
28+
self.old_dirs=defaultdict(set)
29+
self.observer.unschedule_all()
2030

21-
defreset(self):
22-
self.dirs=defaultdict(set)
23-
delself.modules_to_add_later[:]
24-
self.old_dirs=defaultdict(set)
25-
self.observer.unschedule_all()
31+
defadd_module(self,path):
32+
"""Add a python module to track changes to"""
33+
path=os.path.abspath(path)
34+
forsuffinimportcompletion.SUFFIXES:
35+
ifpath.endswith(suff):
36+
path=path[:-len(suff)]
37+
break
38+
dirname=os.path.dirname(path)
39+
ifdirnamenotinself.dirs:
40+
self.observer.schedule(self,dirname,recursive=False)
41+
self.dirs[os.path.dirname(path)].add(path)
2642

27-
defadd_module(self,path):
28-
"""Add a python module to track changes to"""
29-
path=os.path.abspath(path)
30-
forsuffinimportcompletion.SUFFIXES:
31-
ifpath.endswith(suff):
32-
path=path[:-len(suff)]
33-
break
34-
dirname=os.path.dirname(path)
35-
ifdirnamenotinself.dirs:
36-
self.observer.schedule(self,dirname,recursive=False)
37-
self.dirs[os.path.dirname(path)].add(path)
43+
defadd_module_later(self,path):
44+
self.modules_to_add_later.append(path)
3845

39-
defadd_module_later(self,path):
40-
self.modules_to_add_later.append(path)
46+
defactivate(self):
47+
self.dirs=self.old_dirs
48+
fordirnameinself.dirs:
49+
self.observer.schedule(self,dirname,recursive=False)
50+
formoduleinself.modules_to_add_later:
51+
self.add_module(module)
52+
delself.modules_to_add_later[:]
4153

42-
defactivate(self):
43-
self.dirs=self.old_dirs
44-
fordirnameinself.dirs:
45-
self.observer.schedule(self,dirname,recursive=False)
46-
formoduleinself.modules_to_add_later:
47-
self.add_module(module)
48-
delself.modules_to_add_later[:]
54+
defdeactivate(self):
55+
self.observer.unschedule_all()
56+
self.old_dirs=self.dirs
57+
self.dirs=defaultdict(set)
4958

50-
defdeactivate(self):
51-
self.observer.unschedule_all()
52-
self.old_dirs=self.dirs
53-
self.dirs=defaultdict(set)
54-
55-
defon_any_event(self,event):
56-
dirpath=os.path.dirname(event.src_path)
57-
paths= [path+'.py'forpathinself.dirs[dirpath]]
58-
ifevent.src_pathinpaths:
59-
self.on_change(event.src_path)
59+
defon_any_event(self,event):
60+
dirpath=os.path.dirname(event.src_path)
61+
paths= [path+'.py'forpathinself.dirs[dirpath]]
62+
ifevent.src_pathinpaths:
63+
self.on_change(event.src_path)
6064

6165
if__name__=='__main__':
6266
m=ModuleChangedEventHandler([])

‎bpython/curtsiesfrontend/repl.py‎

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
fromcurtsiesimportfmtfuncs
3535
fromcurtsiesimportevents
3636
importcurtsies
37+
importblessings
3738

3839
frombpython.curtsiesfrontend.manual_readlineimportchar_sequencesasrl_char_sequences
3940
frombpython.curtsiesfrontend.manual_readlineimportget_updated_char_sequences
@@ -314,16 +315,17 @@ def __enter__(self):
314315
signal.signal(signal.SIGWINCH,self.sigwinch_handler)
315316

316317
self.orig_import=__builtins__['__import__']
317-
@functools.wraps(self.orig_import)
318-
defnew_import(name,globals={},locals={},fromlist=[],level=-1):
319-
m=self.orig_import(name,globals=globals,locals=locals,fromlist=fromlist)
320-
ifhasattr(m,"__file__"):
321-
ifself.watching_files:
322-
self.watcher.add_module(m.__file__)
323-
else:
324-
self.watcher.add_module_later(m.__file__)
325-
returnm
326-
__builtins__['__import__']=new_import
318+
ifself.watcher:
319+
@functools.wraps(self.orig_import)
320+
defnew_import(name,globals={},locals={},fromlist=[],level=-1):
321+
m=self.orig_import(name,globals=globals,locals=locals,fromlist=fromlist)
322+
ifhasattr(m,"__file__"):
323+
ifself.watching_files:
324+
self.watcher.add_module(m.__file__)
325+
else:
326+
self.watcher.add_module_later(m.__file__)
327+
returnm
328+
__builtins__['__import__']=new_import
327329

328330
returnself
329331

@@ -417,15 +419,18 @@ def process_event(self, e):
417419
self.status_bar.message('Reloaded at '+time.strftime('%H:%M:%S')+' because '+' & '.join(e.files_modified)+' modified')
418420

419421
elifeinkey_dispatch[self.config.toggle_file_watch_key]:
420-
msg="Auto-reloading active, watching for file changes..."
421-
ifself.watching_files:
422-
self.watcher.deactivate()
423-
self.watching_files=False
424-
self.status_bar.pop_permanent_message(msg)
422+
ifself.watcher:
423+
msg="Auto-reloading active, watching for file changes..."
424+
ifself.watching_files:
425+
self.watcher.deactivate()
426+
self.watching_files=False
427+
self.status_bar.pop_permanent_message(msg)
428+
else:
429+
self.watching_files=True
430+
self.status_bar.push_permanent_message(msg)
431+
self.watcher.activate()
425432
else:
426-
self.watching_files=True
427-
self.status_bar.push_permanent_message(msg)
428-
self.watcher.activate()
433+
self.status_bar.message('Autoreloading not available because watchdog not installed')
429434

430435
elifeinkey_dispatch[self.config.reimport_key]:
431436
self.clear_modules_and_reevaluate()
@@ -606,7 +611,7 @@ def send_session_to_external_editor(self, filename=None):
606611
self.cursor_offset=len(self.current_line)
607612

608613
defclear_modules_and_reevaluate(self):
609-
self.watcher.reset()
614+
ifself.watcher:self.watcher.reset()
610615
cursor,line=self.cursor_offset,self.current_line
611616
formodnameinsys.modules.keys():
612617
ifmodnamenotinself.original_modules:
@@ -1045,7 +1050,7 @@ def reprint_line(self, lineno, tokens):
10451050
self.display_buffer[lineno]=bpythonparse(format(tokens,self.formatter))
10461051
defreevaluate(self,insert_into_history=False):
10471052
"""bpython.Repl.undo calls this"""
1048-
self.watcher.reset()
1053+
ifself.watcher:self.watcher.reset()
10491054
old_logical_lines=self.history
10501055
self.history= []
10511056
self.display_lines= []
@@ -1079,7 +1084,6 @@ def getstdout(self):
10791084
returns
10801085

10811086
deffocus_on_subprocess(self,args):
1082-
importblessings
10831087
prev_sigwinch_handler=signal.getsignal(signal.SIGWINCH)
10841088
try:
10851089
signal.signal(signal.SIGWINCH,self.orig_sigwinch_handler)

‎setup.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def initialize_options(self):
151151

152152
ifsys.version_info[:2]>= (2,6):
153153
# curtsies only supports 2.6 and onwards
154-
extras_require['curtsies']= ['curtsies >=0.1.6, <0.2.0','greenlet']
154+
extras_require['curtsies']= ['curtsies >=0.1.7, <0.2.0','greenlet']
155155
packages.append("bpython.curtsiesfrontend")
156156
entry_points['console_scripts'].append(
157157
'bpython-curtsies = bpython.curtsies:main [curtsies]')

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp