MCPcopy Create free account
hub / github.com/modelscope/modelscope / _parse_pip_args

Method _parse_pip_args

modelscope/utils/plugins.py:878–936  ·  view source on GitHub ↗

Parse pip command arguments into options and positional args. Extracts commonly used pip options and separates positional arguments (package names) from flag arguments, maintaining backward compatibility with callers that depend on the parsed structure. Args:

(command_args: List[str])

Source from the content-addressed store, hash-verified

876
877 @staticmethod
878 def _parse_pip_args(command_args: List[str]):
879 """Parse pip command arguments into options and positional args.
880
881 Extracts commonly used pip options and separates positional arguments
882 (package names) from flag arguments, maintaining backward compatibility
883 with callers that depend on the parsed structure.
884
885 Args:
886 command_args: list of arguments passed to pip command
887
888 Returns:
889 options: SimpleNamespace with index_url, src_dir, and requirements
890 args: list of positional arguments (package names)
891
892 """
893 from types import SimpleNamespace
894
895 options = SimpleNamespace(
896 index_url=None,
897 src_dir=None,
898 requirements=[],
899 )
900 args = []
901
902 # Flags that consume the next token as their value
903 flags_with_value = {
904 '-i': 'index_url',
905 '--index-url': 'index_url',
906 '-r': 'requirements',
907 '--requirement': 'requirements',
908 '--src': 'src_dir',
909 '-f': None,
910 '--find-links': None,
911 }
912
913 i = 0
914 while i < len(command_args):
915 arg = command_args[i]
916 if arg in flags_with_value:
917 attr = flags_with_value[arg]
918 if i + 1 < len(command_args):
919 if attr is not None:
920 value = command_args[i + 1]
921 current = getattr(options, attr)
922 if isinstance(current, list):
923 current.append(value)
924 else:
925 setattr(options, attr, value)
926 i += 2
927 continue
928 elif arg.startswith('-'):
929 # Bool flags like -y, --yes; skip without consuming next token
930 i += 1
931 continue
932 else:
933 args.append(arg)
934 i += 1
935

Callers 1

pip_commandMethod · 0.80

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected