Run a pip command via subprocess. Args: command: install, uninstall command command_args: the args to be used with command, should be in list such as ['-r', 'requirements'] Returns: status_code: The pip command status code,
(
command,
command_args: List[str],
)
| 836 | |
| 837 | @staticmethod |
| 838 | def pip_command( |
| 839 | command, |
| 840 | command_args: List[str], |
| 841 | ): |
| 842 | """ |
| 843 | Run a pip command via subprocess. |
| 844 | |
| 845 | Args: |
| 846 | command: install, uninstall command |
| 847 | command_args: the args to be used with command, should be in list |
| 848 | such as ['-r', 'requirements'] |
| 849 | |
| 850 | Returns: |
| 851 | status_code: The pip command status code, 0 if success, else is failed |
| 852 | options: parsed options extracted from command_args |
| 853 | args: positional arguments (package names) extracted from command_args |
| 854 | |
| 855 | """ |
| 856 | # Ensure import system can discover newly installed packages |
| 857 | importlib.invalidate_caches() |
| 858 | if command == 'install': |
| 859 | command_args.append('-f') |
| 860 | command_args.append( |
| 861 | 'https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html' |
| 862 | ) |
| 863 | |
| 864 | # Parse command_args to extract options and positional args, |
| 865 | # keeping backward compatibility with callers |
| 866 | options, args = PluginsManager._parse_pip_args(command_args) |
| 867 | |
| 868 | cmd = [sys.executable, '-m', 'pip', command] + command_args |
| 869 | result = subprocess.run(cmd) |
| 870 | status_code = result.returncode |
| 871 | |
| 872 | # Refresh caches so the latest packages are discoverable |
| 873 | importlib.invalidate_caches() |
| 874 | |
| 875 | return status_code, options, args |
| 876 | |
| 877 | @staticmethod |
| 878 | def _parse_pip_args(command_args: List[str]): |