diff --git a/ide/deploy/watch.py b/ide/deploy/watch.py index b5dcee3..99d4234 100644 --- a/ide/deploy/watch.py +++ b/ide/deploy/watch.py @@ -1,3 +1,20 @@ +# 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 @@ -5,14 +22,15 @@ 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 @@ -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 diff --git a/ide/nuvfile.yml b/ide/nuvfile.yml index 7ac5ee7..499d7e8 100644 --- a/ide/nuvfile.yml +++ b/ide/nuvfile.yml @@ -86,7 +86,7 @@ tasks: cmds: - nuv activation poll - _info: + info: silent: true #desc: info cmds: @@ -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" @@ -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 @@ -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 @@ -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 @@ -172,7 +182,7 @@ tasks: devel: interactive: true - silent: false + silent: true desc: start interactive development mode files cmds: - task: prereq @@ -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 @@ -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}' @@ -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 diff --git a/ide/python/init.ipy b/ide/python/init.ipy index cf6387e..7b33412 100644 --- a/ide/python/init.ipy +++ b/ide/python/init.ipy @@ -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 diff --git a/ide/python/nuvfile.yml b/ide/python/nuvfile.yml index e2280f6..6301bb4 100644 --- a/ide/python/nuvfile.yml +++ b/ide/python/nuvfile.yml @@ -63,11 +63,3 @@ tasks: fi ipython -i init.ipy - - boh: - desc: boh - cmds: - - | - trap 'echo wakeup' EXIT - echo sleeping - sleep 100 \ No newline at end of file