File tree Expand file tree Collapse file tree
StabilityMatrix.Tests/Core Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -651,8 +651,15 @@ public static Task<ProcessResult> RunBashCommand(
651651 /// </summary>
652652 public static string Quote ( string argument )
653653 {
654- var inner = argument . Trim ( '"' ) ;
655- return inner . Contains ( ' ' ) ? $ "\" { inner } \" " : argument ;
654+ var inner = argument . Length >= 2 && argument . StartsWith ( '"' ) && argument . EndsWith ( '"' )
655+ ? argument [ 1 ..^ 1 ]
656+ : argument ;
657+
658+ if ( ! inner . Contains ( ' ' ) && ! inner . Contains ( '"' ) )
659+ return argument ;
660+
661+ var escaped = inner . Replace ( "\" " , "\\ \" " ) ;
662+ return $ "\" { escaped } \" ";
656663 }
657664
658665 /// <summary>
Original file line number Diff line number Diff line change @@ -54,7 +54,15 @@ public PipInstallArgs WithParsedFromRequirementsTxt(
5454 requirementsEntries = requirementsEntries . Where ( s => ! excludeRegex . IsMatch ( s ) ) ;
5555 }
5656
57- return this . AddArgs ( requirementsEntries . Select ( Argument . Quoted ) . ToArray ( ) ) ;
57+ return this . AddArgs ( requirementsEntries . Select ( ToRequirementArgument ) . ToArray ( ) ) ;
58+ }
59+
60+ private static Argument ToRequirementArgument ( string requirementEntry )
61+ {
62+ if ( requirementEntry . StartsWith ( '-' ) )
63+ return Argument . Quoted ( requirementEntry ) ;
64+
65+ return new Argument ( requirementEntry ) ;
5866 }
5967
6068 /// <summary>
Original file line number Diff line number Diff line change @@ -81,6 +81,26 @@ public void TestParsedFromRequirementsTxt()
8181 Assert . AreEqual ( "torch~=2.0.0 torchvision --extra-index-url https://example.org" , args . ToString ( ) ) ;
8282 }
8383
84+ [ TestMethod ]
85+ public void TestParsedFromRequirementsTxt_KeepsEnvironmentMarkerRequirementAsSingleArgument ( )
86+ {
87+ const string requirements = """
88+ onnxruntime-gpu==1.22.0; python_version < "3.11"
89+ """ ;
90+
91+ var args = new PipInstallArgs ( ) . WithParsedFromRequirementsTxt ( requirements ) . ToProcessArgs ( ) ;
92+
93+ Assert . AreEqual ( 1 , args . Count ( ) ) ;
94+ Assert . AreEqual (
95+ "\" onnxruntime-gpu==1.22.0; python_version < \\ \" 3.11\\ \" \" " ,
96+ args . Single ( ) . GetQuotedValue ( )
97+ ) ;
98+ Assert . AreEqual (
99+ "\" onnxruntime-gpu==1.22.0; python_version < \\ \" 3.11\\ \" \" " ,
100+ args . ToString ( )
101+ ) ;
102+ }
103+
84104 [ TestMethod ]
85105 public void TestWithUserOverrides ( )
86106 {
You can’t perform that action at this time.
0 commit comments