Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions ide/deploy/watch.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

SKIPDIR = ["virtualenv", "node_modules", "__pycache__"]

import watchfiles
import asyncio
import os.path
import signal


from .deploy import deploy
from .client import serve, logs

def check_and_deploy(change):
cur_dir_len = len(os.getcwd())+1
change_type, path = change
path = os.path.abspath(path)
cur_dir_len = len(os.getcwd())+1
src = path[cur_dir_len:]
print(f"{change_type}: {src}")
# only modified
if change_type != watchfiles.Change.modified: return
# no directories
Expand All @@ -28,16 +46,15 @@ def check_and_deploy(change):
deploy(src)

async def redeploy():
print("redeploy")
print("> Watching:")
iterator = watchfiles.awatch("packages", recursive=True)
try:
async for changes in iterator:
for change in changes:
async for changes in iterator:
for change in changes:
try:
#print(change)
check_and_deploy(change)
except KeyboardInterrupt:
print("Keyboard Interrupt")
except:
print("Exception")
except Exception as e:
print(e)

def watch():
# start web server
Expand Down
35 changes: 24 additions & 11 deletions ide/nuvfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ tasks:
cmds:
- nuv activation poll

_info:
info:
silent: true
#desc: info
cmds:
Expand All @@ -96,6 +96,10 @@ tasks:
prereq:
silent: true
cmds:
- >
test "$(($NUVDEV_VERSION +0))" -gt 2404130000
|| die "Your .devcontainer.json is outdated - update it from here: https://raw.githubusercontent.com/mastrogpt/starter/main/.devcontainer.json"
- test -e "/.nuvolaris" || test -n "$NUVDEV_FORCE" || die "This command must be run in a Nuvolaris DevContainer"
- test "$(python3 -V | awk -F. '{print $2}')" -ge 10 || die "python 3.10 or greater not available"
- test "$(node -v | awk -F. '{print substr($1,2) }')" -ge 18 || die "nodejs 18 or greater not available"
- test -d "$NUV_PWD/packages" || die "no packages in current directory"
Expand All @@ -109,7 +113,12 @@ tasks:
fi
- |
if ! python3 -m pip list | grep watchfiles >/dev/null 2>/dev/null
then python3 -m pip install --user watchfiles asyncio
then
PIP_FLAG="--user"
if which python3 | grep $HOME >/dev/null
then PIP_FLAG=""
fi
python3 -m pip install $PIP_FLAG watchfiles asyncio
fi
- |
if ! which http-server >/dev/null 2>/dev/null
Expand All @@ -118,8 +127,8 @@ tasks:
- task: kill

kill:
silent: false
ignore: true
silent: true
ignore_errors: true
cmds:
- |
if test -e ~/.nuv/tmp/deploy.pgrp
Expand All @@ -130,11 +139,12 @@ tasks:
while $LOOP
do
LOOP=false
ps -a -o pgid,pid | while read GRP PID
ps -a -o pgid,pid,stat | grep -v 'Z' | while read GRP PID STAT
do
echo $GRP $PID
echo Terminating $PID in $GRP
if test "$GRP" = "$PGRP"
then kill -9 "$PID"
then #echo $GRP $PID
kill -9 "$PID"
LOOP=true
fi
done
Expand Down Expand Up @@ -172,7 +182,7 @@ tasks:

devel:
interactive: true
silent: false
silent: true
desc: start interactive development mode files
cmds:
- task: prereq
Expand All @@ -188,6 +198,9 @@ tasks:
then DRY="--dry-run" ; ECHO='echo'
else DRY="" ; ECHO=""
fi
if cat /proc/version | grep -i microsoft
then export WATCHFILES_FORCE_POLLING=1
fi
python3 -m deploy "$NUV_PWD" -w $DRY
#npm-run-all --parallel deploy serve
true
Expand All @@ -197,8 +210,7 @@ tasks:
prompt: "are you sure you want to remove all actions and packages?"
silent: true
cmds:
- test -e "/.nuvolaris" || die "nuv ide commands must be run in the ghrc.io/nuvolaris/devcontainer with VSCode"
- test -e ~/.wskprops || die "please 'nuv ide login' first"
- task: prereq
- >
nuv action list
| awk 'NR>1 { print $1}'
Expand All @@ -219,9 +231,10 @@ tasks:
done

clean:
silent: true
cmds:
- test -e "/.nuvolaris" || die "nuv ide commands must be run in the ghrc.io/nuvolaris/devcontainer with VSCode"
- test -e ~/.wskprops || die "please 'nuv ide login' first"
- task: kill
- |
if test -d "$NUV_PWD/packages"
then
Expand Down
18 changes: 14 additions & 4 deletions ide/python/init.ipy
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,22 @@

# invoked by ipython from the root folder
from pathlib import Path
from subprocess import run

args = {}
lines = []

try:
lines += Path(".env").read_text().splitlines()
except: pass
try:
lines += Path("packages/.env").read_text().splitlines()
except: pass
try:
lines = Path(".env").read_text().splitlines()
args = { line.split("=",1)[0]: line.split("=",1)[-1] for line in lines}
except:
args = {}
lines += run(["nuv", "-config", "-dump"], capture_output=True, text=True).stdout.splitlines()
except: pass

args = { line.split("=",1)[0]: line.split("=",1)[-1] for line in lines}

%load_ext autoreload
%autoreload 2
8 changes: 0 additions & 8 deletions ide/python/nuvfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,3 @@ tasks:
fi
ipython -i init.ipy


boh:
desc: boh
cmds:
- |
trap 'echo wakeup' EXIT
echo sleeping
sleep 100