MCPcopy Index your code
hub / github.com/modelscope/modelscope / pip_command

Method pip_command

modelscope/utils/plugins.py:838–875  ·  view source on GitHub ↗

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],
    )

Source from the content-addressed store, hash-verified

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]):

Callers 4

install_pluginsMethod · 0.80
uninstall_pluginsMethod · 0.80
tearDownMethod · 0.80

Calls 3

_parse_pip_argsMethod · 0.80
appendMethod · 0.45
runMethod · 0.45

Tested by 1

tearDownMethod · 0.64