@@ -7,48 +7,8 @@ fn build_parser() -> Command {
77 . disable_help_flag ( true )
88 . dont_delimit_trailing_values ( true )
99 . allow_hyphen_values ( true )
10- . arg (
11- Arg :: new ( "bytes_warning_level" )
12- . short ( 'b' )
13- . action ( ArgAction :: Count ) ,
14- )
15- . arg (
16- Arg :: new ( "dont_write_bytecode" )
17- . short ( 'B' )
18- . action ( ArgAction :: SetTrue ) ,
19- )
20- . arg (
21- Arg :: new ( "command" )
22- . short ( 'c' )
23- . value_name ( "cmd" )
24- . conflicts_with ( "module" ) ,
25- )
26- . arg (
27- Arg :: new ( "debug_parser" )
28- . short ( 'd' )
29- . action ( ArgAction :: SetTrue ) ,
30- )
3110 . arg ( Arg :: new ( "ignore_env" ) . short ( 'E' ) . action ( ArgAction :: SetTrue ) )
32- . arg (
33- Arg :: new ( "help" )
34- . short ( 'h' )
35- . long ( "help" )
36- . action ( ArgAction :: Help ) ,
37- )
38- . arg ( Arg :: new ( "inspect" ) . short ( 'i' ) . action ( ArgAction :: SetTrue ) )
3911 . arg ( Arg :: new ( "isolate" ) . short ( 'I' ) . action ( ArgAction :: SetTrue ) )
40- . arg (
41- Arg :: new ( "module" )
42- . short ( 'm' )
43- . value_name ( "mod" )
44- . conflicts_with ( "command" ) ,
45- )
46- . arg (
47- Arg :: new ( "optimize_level" )
48- . short ( 'O' )
49- . action ( ArgAction :: Count ) ,
50- )
51- . arg ( Arg :: new ( "quiet" ) . short ( 'q' ) . action ( ArgAction :: SetTrue ) )
5212 . arg (
5313 Arg :: new ( "no_user_site" )
5414 . short ( 's' )
@@ -59,31 +19,6 @@ fn build_parser() -> Command {
5919 . short ( 'S' )
6020 . action ( ArgAction :: SetTrue ) ,
6121 )
62- . arg ( Arg :: new ( "unbuffered" ) . short ( 'u' ) . action ( ArgAction :: SetTrue ) )
63- . arg ( Arg :: new ( "verbosity" ) . short ( 'v' ) . action ( ArgAction :: Count ) )
64- . arg (
65- Arg :: new ( "version" )
66- . short ( 'V' )
67- . long ( "version" )
68- . action ( ArgAction :: Count ) ,
69- )
70- . arg (
71- Arg :: new ( "warnings" )
72- . short ( 'W' )
73- . value_name ( "arg" )
74- . action ( ArgAction :: Append ) ,
75- )
76- . arg (
77- Arg :: new ( "skip_first_line" )
78- . short ( 'x' )
79- . action ( ArgAction :: SetTrue ) ,
80- )
81- . arg (
82- Arg :: new ( "extended_options" )
83- . short ( 'X' )
84- . value_name ( "opt" )
85- . action ( ArgAction :: Append ) ,
86- )
8722 . arg (
8823 arg ! ( <args> ...)
8924 . trailing_var_arg ( true )
@@ -93,66 +28,23 @@ fn build_parser() -> Command {
9328}
9429
9530pub struct ArgState {
96- pub bytes_warning_level : u8 ,
97- pub dont_write_bytecode : bool ,
98- pub command : Option < String > ,
99- pub debug_parser : bool ,
10031 pub ignore_env : bool ,
101- pub help : bool ,
102- pub inspect : bool ,
10332 pub isolate : bool ,
104- pub module : Option < String > ,
105- pub optimize_level : u8 ,
106- pub quiet : bool ,
107- pub no_user_site : bool ,
10833 pub no_import_site : bool ,
109- pub unbuffered : bool ,
110- pub verbosity : u8 ,
111- pub version : u8 ,
112- pub warnings : Vec < String > ,
113- pub skip_first_line : bool ,
114- pub extended_options : Vec < String > ,
34+ pub no_user_site : bool ,
11535 pub remaining_args : Vec < String > ,
11636}
11737
11838fn extract_state ( matches : & ArgMatches ) -> ArgState {
11939 ArgState {
120- bytes_warning_level : * matches. get_one :: < u8 > ( "bytes_warning_level" ) . unwrap_or ( & 0 ) ,
121- dont_write_bytecode : * matches
122- . get_one :: < bool > ( "dont_write_bytecode" )
123- . unwrap_or ( & false ) ,
124- command : matches. get_one :: < String > ( "command" ) . cloned ( ) ,
125- debug_parser : * matches. get_one :: < bool > ( "debug_parser" ) . unwrap_or ( & false ) ,
12640 // E and I are crucial for transformation
12741 ignore_env : * matches. get_one :: < bool > ( "ignore_env" ) . unwrap_or ( & false ) ,
12842 isolate : * matches. get_one :: < bool > ( "isolate" ) . unwrap_or ( & false ) ,
12943
130- help : * matches. get_one :: < bool > ( "help" ) . unwrap_or ( & false ) ,
131- inspect : * matches. get_one :: < bool > ( "inspect" ) . unwrap_or ( & false ) ,
132- module : matches. get_one :: < String > ( "module" ) . cloned ( ) ,
133- optimize_level : * matches. get_one :: < u8 > ( "optimize_level" ) . unwrap_or ( & 0 ) ,
134- quiet : * matches. get_one :: < bool > ( "quiet" ) . unwrap_or ( & false ) ,
135-
13644 // s is crucial for transformation
13745 no_user_site : * matches. get_one :: < bool > ( "no_user_site" ) . unwrap_or ( & false ) ,
13846
13947 no_import_site : * matches. get_one :: < bool > ( "no_import_site" ) . unwrap_or ( & false ) ,
140- unbuffered : * matches. get_one :: < bool > ( "unbuffered" ) . unwrap_or ( & false ) ,
141- verbosity : * matches. get_one :: < u8 > ( "verbosity" ) . unwrap_or ( & 0 ) ,
142- version : * matches. get_one :: < u8 > ( "version" ) . unwrap_or ( & 0 ) ,
143- skip_first_line : * matches. get_one :: < bool > ( "skip_first_line" ) . unwrap_or ( & false ) ,
144-
145- // For multiple values, clone the Vec
146- warnings : matches
147- . get_many :: < String > ( "warnings" )
148- . unwrap_or_default ( )
149- . cloned ( )
150- . collect ( ) ,
151- extended_options : matches
152- . get_many :: < String > ( "extended_options" )
153- . unwrap_or_default ( )
154- . cloned ( )
155- . collect ( ) ,
15648
15749 remaining_args : matches
15850 . get_many :: < String > ( "args" )
@@ -179,58 +71,16 @@ pub fn reparse_args(original_argv: &Vec<&str>) -> Result<Vec<String>> {
17971 // Retain the original argv binary
18072 argv. push ( original_argv[ 0 ] . to_string ( ) ) ;
18173
182- if parsed_args. bytes_warning_level == 1 {
183- argv. push ( String :: from ( "-b" ) ) ;
184- } else if parsed_args. bytes_warning_level >= 2 {
185- argv. push ( String :: from ( "-bb" ) ) ;
186- }
187-
188- push_flag ( & mut argv, 'B' , parsed_args. dont_write_bytecode ) ;
189- push_flag ( & mut argv, 'd' , parsed_args. debug_parser ) ;
190- push_flag ( & mut argv, 'h' , parsed_args. help ) ;
191- push_flag ( & mut argv, 'i' , parsed_args. inspect ) ;
192-
19374 // -I replacement logic: -I is never pushed, its effects (-E and -s) are handled separately.
19475 // -E removal: -E is never pushd
19576 // -s inclusion logic: we ALWAYS push -s
196- push_flag ( & mut argv, 's' , true ) ;
77+ push_flag (
78+ & mut argv,
79+ 's' ,
80+ parsed_args. no_user_site | parsed_args. isolate ,
81+ ) ;
19782
19883 push_flag ( & mut argv, 'S' , parsed_args. no_import_site ) ;
199- push_flag ( & mut argv, 'u' , parsed_args. unbuffered ) ;
200- push_flag ( & mut argv, 'q' , parsed_args. quiet ) ;
201- push_flag ( & mut argv, 'x' , parsed_args. skip_first_line ) ;
202-
203- if let Some ( cmd) = & parsed_args. command {
204- argv. push ( String :: from ( "-c" ) ) ;
205- argv. push ( cmd. clone ( ) ) ;
206- }
207- if let Some ( module) = & parsed_args. module {
208- argv. push ( String :: from ( "-m" ) ) ;
209- argv. push ( module. clone ( ) ) ;
210- }
211- if parsed_args. optimize_level == 1 {
212- argv. push ( String :: from ( "-O" ) ) ;
213- } else if parsed_args. optimize_level >= 2 {
214- argv. push ( String :: from ( "-OO" ) ) ;
215- }
216-
217- for _ in 0 ..parsed_args. verbosity {
218- argv. push ( String :: from ( "-v" ) ) ;
219- }
220- if parsed_args. version == 1 {
221- argv. push ( String :: from ( "-V" ) ) ;
222- } else if parsed_args. version >= 2 {
223- argv. push ( String :: from ( "-VV" ) ) ;
224- }
225-
226- for warning in & parsed_args. warnings {
227- argv. push ( String :: from ( "-W" ) ) ;
228- argv. push ( warning. clone ( ) ) ;
229- }
230- for opt in & parsed_args. extended_options {
231- argv. push ( String :: from ( "-X" ) ) ;
232- argv. push ( opt. clone ( ) ) ;
233- }
23484
23585 argv. extend ( parsed_args. remaining_args . iter ( ) . cloned ( ) ) ;
23686
@@ -315,21 +165,11 @@ mod test {
315165 assert ! ( expected == reparsed. unwrap( ) , "Didn't translate -I to -s" ) ;
316166 }
317167
318- #[ test]
319- fn basic_add_s ( ) {
320- // We expect to ADD the -s flag
321- let orig = vec ! [ "python" , "-c" , "exit(0)" , "arg1" ] ;
322- let expected = vec ! [ "python" , "-s" , "-c" , "exit(0)" , "arg1" ] ;
323- let reparsed = reparse_args ( & orig) ;
324- assert ! ( reparsed. is_ok( ) , "Args failed to parse {:?}" , reparsed) ;
325- assert ! ( expected == reparsed. unwrap( ) , "Didn't add -s" ) ;
326- }
327-
328168 #[ test]
329169 fn basic_m_preserved ( ) {
330170 // We expect to ADD the -s flag
331171 let orig = vec ! [ "python" , "-m" , "build" , "--unknown" , "arg1" ] ;
332- let expected = vec ! [ "python" , "-s" , "- m", "build" , "--unknown" , "arg1" ] ;
172+ let expected = vec ! [ "python" , "-m" , "build" , "--unknown" , "arg1" ] ;
333173 let reparsed = reparse_args ( & orig) ;
334174 assert ! ( reparsed. is_ok( ) , "Args failed to parse {:?}" , reparsed) ;
335175 assert ! ( expected == reparsed. unwrap( ) , "Didn't add -s" ) ;
@@ -345,7 +185,6 @@ mod test {
345185 ] ;
346186 let expected = vec ! [
347187 "python3" ,
348- "-s" ,
349188 "uv/private/sdist_build/build_helper.py" ,
350189 "bazel-out/darwin_arm64-fastbuild/bin/external/+uv+sbuild__pypi__default__bravado_core/src" ,
351190 "bazel-out/darwin_arm64-fastbuild/bin/external/+uv+sbuild__pypi__default__bravado_core/build"
@@ -373,7 +212,6 @@ mod test {
373212 ] ;
374213 let expected = vec ! [
375214 "python3" ,
376- "-s" ,
377215 "-m" ,
378216 "build" ,
379217 "--no-isolation" ,
0 commit comments