Skip to content

Commit f213ee5

Browse files
naonusyouknowone
authored andcommitted
Add command line parameter -P
1 parent e2f7d5b commit f213ee5

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

Lib/test/test_support.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ def check_options(self, args, func, expected=None):
514514
self.assertEqual(proc.returncode, 0)
515515

516516
# TODO: RUSTPYTHON
517-
@unittest.expectedFailure
517+
# @unittest.expectedFailure
518518
def test_args_from_interpreter_flags(self):
519519
# Test test.support.args_from_interpreter_flags()
520520
for opts in (

src/settings.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ fn parse_arguments<'a>(app: App<'a, '_>) -> ArgMatches<'a> {
100100
.short("B")
101101
.help("don't write .pyc files on import"),
102102
)
103+
.arg(
104+
Arg::with_name("safe-path")
105+
.short("P")
106+
.help("don’t prepend a potentially unsafe path to sys.path"),
107+
)
103108
.arg(
104109
Arg::with_name("ignore-environment")
105110
.short("E")
@@ -237,6 +242,12 @@ fn settings_from(matches: &ArgMatches) -> (Settings, RunMode) {
237242
};
238243
}
239244

245+
if matches.is_present("safe-path")
246+
|| (!ignore_environment && env::var_os("PYTHONSAFEPATH").is_some())
247+
{
248+
settings.safe_path = true;
249+
}
250+
240251
settings.check_hash_based_pycs = matches
241252
.value_of("check-hash-based-pycs")
242253
.unwrap_or("default")

vm/src/vm/setting.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ pub struct Settings {
3737
/// -B
3838
pub dont_write_bytecode: bool,
3939

40+
/// -P
41+
pub safe_path: bool,
42+
4043
/// -b
4144
pub bytes_warning: u64,
4245

@@ -108,6 +111,7 @@ impl Default for Settings {
108111
verbose: 0,
109112
quiet: false,
110113
dont_write_bytecode: false,
114+
safe_path: false,
111115
bytes_warning: 0,
112116
xopts: vec![],
113117
isolated: false,

0 commit comments

Comments
 (0)