Skip to content

Commit 3d2acbf

Browse files
committed
ide fixed
1 parent 7a2fec9 commit 3d2acbf

File tree

7 files changed

+73
-81
lines changed

7 files changed

+73
-81
lines changed

ide/deploy/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from .deploy import set_dry_run, deploy
77
from .client import build
88

9+
910
def signal_handler(sig, frame):
1011
print('Termination requested.')
1112
os.remove(expanduser("~/.nuv/tmp/deploy.pid"))
@@ -24,6 +25,7 @@ def main():
2425
# Register the signal handler for SIGTERM
2526
os.setpgrp()
2627
signal.signal(signal.SIGTERM, signal_handler)
28+
2729
os.makedirs(expanduser("~/.nuv/tmp"), exist_ok=True)
2830
with open(expanduser("~/.nuv/tmp/deploy.pid"), "w") as f:
2931
f.write(str(os.getpid())+"\n")

ide/deploy/awatch.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

ide/deploy/client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,16 @@ def get_nuvolaris_config(key):
2727
return info.get("nuvolaris", {}).get(key)
2828
except:
2929
return None
30-
30+
3131
# serve web area
3232
def serve():
3333
devel = get_nuvolaris_config("devel")
3434
if devel is None:
3535
devel = "nuv ide serve"
3636
print(devel)
37-
Popen(devel, shell=True, cwd=os.environ.get("NUV_PWD"), env=os.environ).communicate()
37+
Popen(devel, shell=True, cwd=os.environ.get("NUV_PWD"), env=os.environ)
3838

39+
# build
3940
def build():
4041
deploy = get_nuvolaris_config("deploy")
4142
if deploy is not None:

ide/deploy/deploy.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,13 @@ def build_action(package, action):
6868
return f"packages/{package}/{action}.zip"
6969

7070
def deploy_action(artifact):
71-
sp = artifact.split("/")
72-
[name, typ] = sp[-1].rsplit(".", 1)
73-
package = sp[1]
71+
try:
72+
sp = artifact.split("/")
73+
[name, typ] = sp[-1].rsplit(".", 1)
74+
package = sp[1]
75+
except:
76+
print("! cannot deploy", artifact)
77+
return
7478

7579
deploy_package(package)
7680

ide/deploy/watch.py

Lines changed: 48 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,57 @@
1-
# Licensed to the Apache Software Foundation (ASF) under one
2-
# or more contributor license agreements. See the NOTICE file
3-
# distributed with this work for additional information
4-
# regarding copyright ownership. The ASF licenses this file
5-
# to you under the Apache License, Version 2.0 (the
6-
# "License"); you may not use this file except in compliance
7-
# with the License. You may obtain a copy of the License at
8-
#
9-
# http://www.apache.org/licenses/LICENSE-2.0
10-
#
11-
# Unless required by applicable law or agreed to in writing,
12-
# software distributed under the License is distributed on an
13-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14-
# KIND, either express or implied. See the License for the
15-
# specific language governing permissions and limitations
16-
# under the License.
17-
181
SKIPDIR = ["virtualenv", "node_modules", "__pycache__"]
192

20-
import os, sys, signal, os.path
21-
from subprocess import Popen
22-
from watchdog.observers import Observer
23-
from watchdog.events import FileSystemEventHandler
3+
import watchfiles
4+
import asyncio
5+
import os.path
6+
import signal
247

258
from .deploy import deploy
269
from .client import serve
2710

28-
class ChangeHandler(FileSystemEventHandler):
29-
"""Logs all the events captured."""
30-
31-
last_modified = {}
32-
33-
def on_any_event(self, event):
34-
## filter what is needed
35-
# only modified
36-
if event.event_type != "modified": return
37-
# no directories
38-
if event.is_directory: return
39-
src = event.src_path
40-
# no missing files
41-
if not os.path.exists(src): return
42-
# no generated directories
43-
for dir in src.split("/")[:-1]:
44-
if dir in SKIPDIR: return
45-
# no generated files
46-
if src.endswith(".zip"): return
47-
48-
# cache last modified to do only once
49-
cur = os.path.getmtime(src)
50-
if self.last_modified.get(src, 0) == cur:
51-
return
52-
self.last_modified[src] = cur
53-
deploy(src)
54-
55-
def watch():
56-
observer = Observer()
57-
event_handler = ChangeHandler()
58-
observer.schedule(event_handler, "packages", recursive=True)
59-
#observer.schedule(event_handler, "web", recursive=True)
60-
observer.start()
11+
def check_and_deploy(change):
12+
cur_dir_len = len(os.getcwd())+1
13+
change_type, path = change
14+
src = path[cur_dir_len:]
15+
print(f"{change_type}: {src}")
16+
# only modified
17+
if change_type != watchfiles.Change.modified: return
18+
# no directories
19+
if os.path.isdir(src): return
20+
# no missing files
21+
if not os.path.exists(src): return
22+
# no generated directories
23+
for dir in src.split("/")[:-1]:
24+
if dir in SKIPDIR: return
25+
# no generated files
26+
if src.endswith(".zip"): return
27+
# now you can deploy
28+
deploy(src)
29+
30+
async def redeploy():
31+
print("redeploy")
32+
iterator = watchfiles.awatch("packages", recursive=True)
6133
try:
62-
serve()
34+
async for changes in iterator:
35+
for change in changes:
36+
check_and_deploy(change)
6337
except KeyboardInterrupt:
64-
observer.stop()
65-
observer.join()
38+
print("Keyboard Interrupt")
39+
except:
40+
print("Exception")
41+
42+
def watch():
43+
loop = asyncio.get_event_loop()
44+
#task = loop.create_task(redeploy())
45+
task = asyncio.ensure_future(redeploy())
46+
def end_loop():
47+
print("Ending task.")
48+
task.cancel()
49+
loop.add_signal_handler(signal.SIGTERM, end_loop)
6650

51+
try:
52+
loop.run_until_complete(task)
53+
except asyncio.CancelledError:
54+
pass
55+
finally:
56+
loop.stop()
57+
loop.close()

ide/nuvfile.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ tasks:
132132
python3 -m deploy "$NUV_PWD" -s "{{._action_}}" $DRY
133133
fi
134134
135+
135136
devel:
136137
silent: true
137138
desc: start interactive development mode files
@@ -162,6 +163,9 @@ tasks:
162163
then DRY="--dry-run" ; ECHO='echo'
163164
else DRY="" ; ECHO=""
164165
fi
166+
if ! pip list | grep watchfiles >/dev/null
167+
then pip install watchfiles asyncio
168+
fi
165169
python3 -m deploy "$NUV_PWD" -w $DRY
166170
true
167171

ide/python/nuvfile.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,12 @@ tasks:
6262
then set -a ; source "$NUV_PWD/.env"
6363
fi
6464
ipython -i init.ipy
65+
66+
67+
boh:
68+
desc: boh
69+
cmds:
70+
- |
71+
trap 'echo wakeup' EXIT
72+
echo sleeping
73+
sleep 100

0 commit comments

Comments
 (0)