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
31 changes: 28 additions & 3 deletions auto_dev/cli_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def __init__(self, command: Union[str, List[str]], cwd: Optional[str] = None):
"""Initialize the command executor."""
self.command = command
self.cwd = str(cwd) if cwd else '.'
self.stdout = []
self.stderr = []
self.return_code = None
self.exception = None

def execute(self, stream=False, verbose: bool = True, shell: bool = False):
"""Execute the command."""
Expand All @@ -45,13 +49,17 @@ def execute(self, stream=False, verbose: bool = True, shell: bool = False):
if len(result.stderr) > 0:
logger.error(result.stderr.decode("utf-8"))

self.stdout = result.stdout.decode("utf-8").splitlines()
self.stderr = result.stderr.decode("utf-8").splitlines()
self.return_code = result.returncode
if result.returncode != 0:
if verbose:
logger.error("Command failed with return code: %s", result.returncode)
return False
return True
except Exception as error: # pylint: disable=broad-except
logger.error("Command failed: %s", error)
self.exception = error
return False

def _execute_stream(self, verbose: bool = True, shell: bool = False):
Expand All @@ -67,15 +75,32 @@ def _execute_stream(self, verbose: bool = True, shell: bool = False):
shell=shell,
) as process:
for stdout_line in iter(process.stdout.readline, ""): # type: ignore
self.stdout.append(stdout_line.strip())
if verbose:
logger.info(stdout_line.strip())
for stderr_line in iter(process.stderr.readline, ""):
self.stderr.append(stderr_line.strip())
if verbose:
logger.error(stderr_line.strip())
process.stdout.close() # type: ignore
return_code = process.wait()
if return_code != 0:
self.return_code = process.wait()
if self.return_code != 0:
if verbose:
logger.error("Command failed with return code: %s", return_code)
logger.error("Command failed with return code: %s", self.return_code)
return False
return True
except Exception as error: # pylint: disable=broad-except
logger.error("Command failed: %s", error)
self.exception = error
return False

@property
def output(self):
"""Return the output."""
fmt = f"Command: {' '.join(self.command)}\n"
fmt += f"Return Code: {self.return_code}\n"
fmt += "Stdout:\n"
fmt += "\n\t".join(self.stdout)
fmt += "\nStderr:\n"
fmt += "\n\t".join(self.stderr)
return fmt
4 changes: 3 additions & 1 deletion auto_dev/commands/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ def execute_commands(*commands: str, verbose: bool, logger, shell: bool = False)
"""Execute commands."""
for command in commands:
cli_executor = CommandExecutor(command=command.split(" "))
result = cli_executor.execute(stream=True, verbose=verbose, shell=shell)
result = cli_executor.execute(stream=False, verbose=verbose, shell=shell)
if not result:
logger.error(f"Command failed: {command}")
logger.error(f"{cli_executor.stdout}")
logger.error(f"{cli_executor.stderr}")
sys.exit(1)


Expand Down
11 changes: 6 additions & 5 deletions auto_dev/commands/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"-p",
"--path",
help="Path to directory to test. If not provided will test all packages.",
type=click.Path(exists=True, file_okay=False),
type=click.Path(exists=True, file_okay=True),
default=None,
)
@click.option(
Expand All @@ -32,8 +32,9 @@ def test(ctx, path, watch):
Runs the test tooling
"""
verbose = ctx.obj["VERBOSE"]
logger = ctx.obj["LOGGER"]
logger.info(f"Testing path: `{path if path else 'All dev packages/packages.json'}` ⌛")
click.echo(
f"Testing path: `{path if path else 'All dev packages/packages.json'}` ⌛",
)
try:
packages = get_packages() if not path else [path]
except Exception as error:
Expand All @@ -42,15 +43,15 @@ def test(ctx, path, watch):
for package in track(range(len(packages)), description="Testing..."):
result = test_path(str(packages[package]), verbose=verbose, watch=watch)
results[packages[package]] = result
logger.info(f"{'👌' if result else '❗'} - {packages[package]}")
click.echo(f"{'👌' if result else '❗'} - {packages[package]}")

raises = []
for package, result in results.items():
if not result:
raises.append(package)
if raises:
for package in raises:
logger.error(f"❗ - {package}")
click.echo(f"❗ - {package}")
raise click.ClickException("Testing failed! ❌")
click.echo("Testing completed successfully! ✅")

Expand Down
11 changes: 9 additions & 2 deletions auto_dev/data/repo/templates/autonomy/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,16 @@ function install_poetry_deps() {
local os
local pip_executable
local poetry_executable


local host_poetry_executable
host_poetry_executable=$(echo -n $(poetry env info | grep Executable |head -n 1 | awk -F: '{ print $2 }') | xargs)
echo "Host poetry executable: $host_poetry_executable"
echo "Setting up new poetry environment..."

poetry env use $(which python)
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xiuxiuxar I FOUND IT!!!!

THIS THING HAS CAUSED US SO MUCH ERRORS!

poetry_executable=$(echo -n $(poetry env info | grep Executable |head -n 1 | awk -F: '{ print $2 }') | xargs)
echo "New poetry executable: $poetry_executable"
echo "Installing package dependencies via poetry..."
echo "Using poetry executable: $poetry_executable"
poetry install
echo checking if aea is installed
poetry run aea --version
Expand Down
Loading