nautobot / cookiecutter-nautobot-app

Cookiecutter template for creating new Nautobot Apps.
https://docs.nautobot.com/projects/cookiecutter-nautobot-app/en/latest/
Apache License 2.0
16 stars 5 forks source link

(tasks.py) Shell redirection from the local shell to docker-compose is not working in my dev environment #104

Open gsnider2195 opened 7 months ago

gsnider2195 commented 7 months ago

Environment

Steps to reproduce

  1. Be running fedora and/or podman?
  2. Try to use one of the invoke commands that redirects a file into docker-compose exec

Observed Behavior

invoke generate_app_config_schema and invoke validate_app_config_schema are not working for me because when the shell tries to redirect that file from the local shell to the spawned shell it gets out of sync and the code isn't properly loaded.

Expected Behavior

I expected it to work. Running the shell redirection entirely in the spawned shell fixed it for me:

diff --git a/tasks.py b/tasks.py
index 6c08350..4823705 100644
--- a/tasks.py
+++ b/tasks.py
@@ -352,8 +352,9 @@ def nbshell(context, file="", env={}, plain=False):
         "nautobot-server",
         "nbshell",
         "--plain" if plain else "",
-        f"< '{file}'" if file else "",
     ]
+    if file:
+        command = ["sh", "-c", f"\"{' '.join(command)} < '{file}'\""]
     run_command(context, " ".join(command), pty=not bool(file), command_env=env)