Skip to content

Commit

Permalink
Do not try installing requirements if there are none
Browse files Browse the repository at this point in the history
Do not try running pip install -r requirements.txt if the file does not
exist or is empty. It avoids seeing an error in the log.
  • Loading branch information
arnaudgelas committed Jan 18, 2024
1 parent 9b75a35 commit c5c6e09
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion metagpt/actions/run_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
5. Merged the `Config` class of send18:dev branch to take over the set/get operations of the Environment
class.
"""
import os
import subprocess
from typing import Tuple

Expand Down Expand Up @@ -152,11 +153,23 @@ def _install_via_subprocess(cmd, check, cwd, env):
return subprocess.run(cmd, check=check, cwd=cwd, env=env)

@staticmethod
def _install_dependencies(working_directory, env):
def _install_requirements(self, working_directory, env):
file_path = os.path.join(working_directory, "requirements.txt")
if not os.path.exists(file_path):
return
if os.stat(file_path).st_size == 0:
return
install_command = ["python", "-m", "pip", "install", "-r", "requirements.txt"]
logger.info(" ".join(install_command))
RunCode._install_via_subprocess(install_command, check=True, cwd=working_directory, env=env)

@staticmethod
def _install_pytest(self, working_directory, env):
install_pytest_command = ["python", "-m", "pip", "install", "pytest"]
logger.info(" ".join(install_pytest_command))
RunCode._install_via_subprocess(install_pytest_command, check=True, cwd=working_directory, env=env)

@staticmethod
def _install_dependencies(working_directory, env):
RunCode._install_requirements(working_directory, env)
RunCode._install_pytest(working_directory, env)

0 comments on commit c5c6e09

Please sign in to comment.