Skip to content

Commit 605af2d

Browse files
committed
[NO TESTS] WIP
1 parent be434dd commit 605af2d

File tree

5 files changed

+21
-189
lines changed

5 files changed

+21
-189
lines changed

py/private/py_venv/entrypoint.tmpl.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ set -o errexit -o nounset -o pipefail
1212

1313
source "$(rlocation "{{VENV}}")"/bin/activate
1414

15-
exec "$(rlocation "{{VENV}}")"/bin/python {{INTERPRETER_FLAGS}} "$@"
15+
exec "$(rlocation "{{VENV}}")"/bin/python3 {{INTERPRETER_FLAGS}} "$@"

py/tests/py-venv-standalone-interpreter/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -ex
44

55
ROOT="$(dirname $0)"
66

7-
"$ROOT"/.ex/bin/python --help >/dev/null 2>&1
7+
"$ROOT"/.ex/bin/python --help
88

99
if [ "Hello, world!" != "$($ROOT/.ex/bin/python -c 'from ex import hello; print(hello())')" ]; then
1010
exit 1

py/tools/venv_shim/src/main.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ fn find_actual_interpreter(executable: impl AsRef<Path>, cfg: &PyCfg) -> Result<
225225

226226
fn main() -> Result<()> {
227227
let all_args: Vec<_> = env::args().collect();
228-
let Some((exec_name, exec_args)) = all_args.split_first() else {
228+
let Some((exec_name, _exec_args)) = all_args.split_first() else {
229229
miette::bail!("could not discover an execution command-line");
230230
};
231231

@@ -324,7 +324,7 @@ fn main() -> Result<()> {
324324
eprintln!("[aspect] {:?}", venv_config);
325325

326326
// The logical path of the interpreter
327-
let venv_interpreter = venv_root.join("bin/python3");
327+
let venv_interpreter = venv_root.join("bin").join(executable.file_name().unwrap());
328328
#[cfg(feature = "debug")]
329329
eprintln!("[aspect] {:?}", venv_interpreter);
330330

@@ -342,6 +342,8 @@ fn main() -> Result<()> {
342342
// Lie about the value of argv0 to hoodwink the interpreter as to its
343343
// location on Linux-based platforms.
344344
reexec_args.remove(0);
345+
346+
#[cfg(feature = "debug")]
345347
eprintln!("Reexec args {:?}", reexec_args);
346348

347349
let mut cmd = Command::new(&actual_interpreter);
@@ -401,8 +403,7 @@ fn main() -> Result<()> {
401403
home.to_str().unwrap().hash(&mut hasher);
402404
cmd.env("ASPECT_PY_VALIDITY", format!("{}", hasher.finish()));
403405

404-
// 1
405-
406+
#[cfg(feature = "debug")]
406407
eprintln!("Punting to {:?}", cmd);
407408

408409
// And punt

py/tools/venv_shim/src/pyargs.rs

Lines changed: 7 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -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

9530
pub 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

11838
fn 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",

uv/private/sdist_build/build_helper.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from argparse import ArgumentParser
44
import shutil
55
import sys
6-
from os import getenv, listdir, path
6+
from os import getenv, listdir, path, execv
77
from subprocess import check_call, CalledProcessError
88

99
# Under Bazel, the source dir of a sdist to build is immutable. `build` and
@@ -27,19 +27,12 @@
2727
shutil.copystat = lambda x, y, **k: None
2828
shutil.copytree(opts.srcdir, t, dirs_exist_ok=True)
2929

30-
outdir = path.abspath(opts.outdir)
31-
args = [
32-
sys.executable,
30+
for e in sys.path:
31+
print(" -", e, file=sys.stderr)
32+
33+
execv(sys.executable, [
3334
"-m", "build",
3435
"--wheel",
3536
"--no-isolation",
36-
"--outdir", outdir,
37-
]
38-
print(args, file=sys.stderr)
39-
40-
try:
41-
check_call(args, cwd=t)
42-
except CalledProcessError:
43-
exit(1)
44-
45-
print(listdir(outdir), file=sys.stderr)
37+
"--outdir", opts.outdir,
38+
])

0 commit comments

Comments
 (0)