Skip to content

Commit

Permalink
Removed 'interactive' cli - that's all moving to ppg2-interactive
Browse files Browse the repository at this point in the history
  • Loading branch information
TyberiusPrime committed Oct 10, 2024
1 parent b5360ef commit 517904f
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 108 deletions.
2 changes: 2 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@
cython
filelock
pyzstd
watchfiles
lib_programname
'';
format = "pyproject";
};
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ dependencies = [
"networkx",
"filelock",
"pyzstd",
"watchfiles",
"lib_programname",
]

Expand Down
106 changes: 0 additions & 106 deletions python/pypipegraph2/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,110 +54,4 @@ def main_filter_constraint_violations(filename=None, pipegraph=None):
print("aborted")


def main_interactive():
"""Interactive mode.
Watch files (names passed on stdin or as arguments).
On change (and startup), exec the contents,
and call all functions starting with ppg_.
These function (re)define ppg-jobs,
and then a ppg is run.
Retain state and other non-changed stops between invocations.

Template:
```
import pypipegraph2 as ppg
if __name__ == '__main__':
ppg.new()
def ppg_jobs():
return ppg.FileGeneratingJob(...)
if __name__ == '__main__':
for symbol in globals():
if symbol.startswith("ppg_"):
globals()[symbol]()
ppg.run()
```
"""
from watchfiles import watch, Change
import rich.console
import rich.traceback

if len(sys.argv) > 1:
files = sys.argv[1:]
else:
files = sys.stdin.read().strip().split("\n")
files = [Path(x).absolute() for x in files]

console = rich.console.Console()
func_hashes = {}

logger.remove()
install_logger()

ppg.new(
run_mode=ppg.RunMode.CONSOLE_INTERACTIVE,
dir_config=ppg.DirConfig(".ppg/" + Path(files[0]).name),
)
last_times = {}

for changes in watch(".", recursive=False):
for change in changes:
# print(change)
if change[0] in (Change.modified, Change.added):
# print("changed file", change[1])
if Path(change[1]).absolute() in files:
try:
find_changed_funcs(change[1])
except:
print("error running found changes in ", change[1])
if Path(change[1]).absolute() == Path(__file__).absolute():
reload_iv()


def find_changed_funcs(filename):
logger.info(f"Change in {filename}")
try:
code = Path(filename).read_text()
except FileNotFoundError:
time.sleep(0.1)
code = Path(filename).read_text()
l = {}
compiled_code = compile(code, filename, "exec")
exec(compiled_code, l, l) # globals = locals, just like in a regular eval.
logger.info(f"Executed {filename}")
any_changed = False
for name, obj in l.items():
if name.startswith("ppg_") and callable(obj):
path = filename + "::" + name
dis = ppg.jobs._FunctionInvariant.get_dis(obj)
closure = ppg.jobs._FunctionInvariant.extract_closure(obj)
func_hash = (dis, closure)
if func_hash != func_hashes.get(path, None):
logger.warning(f"\t Change in {name}")
func_hashes[path] = func_hash
any_changed = True
try:
obj()
except Exception as e:
print("error evaluating", path)
console.print_exception(show_locals=True)
if any_changed:
logger.info("Run ppg")
ppg.run()
logger.info("Done ppg")
install_logger()


def reload_iv():
logger.error("reloading iv")
python_path = sys.executable
os.execv(python_path, [python_path] + sys.argv)
# and end of session for this prgorme.


def install_logger():
logger.add(
sink=sys.stderr,
format="<blue>{elapsed}s</blue> | <level>{level.icon}</level> <bold>|</bold><level>{message}</level>",
)
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ install_requires = networkx
filelock
psutil
pyzstd
watchfiles
lib_programname
python_requires = >=3.7

Expand Down

0 comments on commit 517904f

Please sign in to comment.