Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/make env script: raise error if process failed #556

Merged
merged 4 commits into from
Oct 14, 2024
Merged
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
24 changes: 18 additions & 6 deletions environment/make_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import subprocess
import sys
from pathlib import Path
from typing import Optional

try:
import yaml # noQA
Expand Down Expand Up @@ -84,7 +85,7 @@ def write_env_yml(env_name: str):
print(f"Temporary environment file created at: {PROJECT_ROOT / '_environment.yml'}")


def check_and_delete_conda_env(env_name, prefix=None):
def check_and_delete_conda_env(env_name: str, prefix: Optional[str] = None):
result = subprocess.run("conda env list", **SUBPROCESS_KWARGS)

if env_name in result.stdout:
Expand All @@ -97,9 +98,9 @@ def check_and_delete_conda_env(env_name, prefix=None):

def create_env(
env_name: str,
prefix: str = None,
prefix: Optional[str] = None,
editable: bool = False,
optional_deps: str = None,
optional_deps: Optional[str] = None,
):
if not BACKEND_ROOT.exists():
raise FileNotFoundError(
Expand Down Expand Up @@ -139,11 +140,22 @@ def create_env(
universal_newlines=True,
)

while process.poll() is None:
print(process.stdout.readline())
print(process.stdout.read())
while process.poll() is None and process.stdout:
print(process.stdout.readline(), end="")

os.remove("_environment.yml")

if process.returncode != 0:
if process.stderr:
print(process.stderr.read())

raise subprocess.CalledProcessError(
process.returncode,
command,
process.stdout.read() if process.stdout else None,
process.stderr.read() if process.stderr else None,
)

print(f"Environment {env_name} created successfully!")
print(f"Activate it with:\n\n\t{activate_command}\n")

Expand Down
Loading