Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Lib/test/test_cmd_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,6 @@ def test_isolatedmode(self):
cwd=tmpdir)
self.assertEqual(out.strip(), b"ok")

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_sys_flags_set(self):
# Issue 31845: a startup refactoring broke reading flags from env vars
for value, expected in (("", 0), ("1", 1), ("text", 1), ("2", 2)):
Expand All @@ -750,7 +749,6 @@ def test_sys_flags_set(self):
with self.subTest(envar_value=value):
assert_python_ok('-c', code, **env_vars)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_set_pycache_prefix(self):
# sys.pycache_prefix can be set from either -X pycache_prefix or
# PYTHONPYCACHEPREFIX env var, with the former taking precedence.
Expand Down
2 changes: 0 additions & 2 deletions Lib/test/test_compileall.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,6 @@ def assertNotCompiled(self, fn):
path = importlib.util.cache_from_source(fn)
self.assertFalse(os.path.exists(path))

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_no_args_compiles_path(self):
# Note that -l is implied for the no args case.
bazfn = script_helper.make_script(self.directory, 'baz', '')
Expand All @@ -608,7 +607,6 @@ def test_no_args_compiles_path(self):
self.assertNotCompiled(self.initfn)
self.assertNotCompiled(self.barfn)

@unittest.expectedFailure # TODO: RUSTPYTHON
@without_source_date_epoch # timestamp invalidation test
@support.requires_resource('cpu')
def test_no_args_respects_force_flag(self):
Expand Down
9 changes: 7 additions & 2 deletions crates/vm/src/stdlib/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -733,8 +733,13 @@ pub mod sys {
}

#[pyattr]
fn pycache_prefix(vm: &VirtualMachine) -> PyObjectRef {
vm.ctx.none()
fn pycache_prefix(vm: &VirtualMachine) -> Option<PyStrRef> {
vm.state
.config
.settings
.pycache_prefix
.clone()
.map(|value| vm.fsdecode(value))
}

#[pyattr(name = "version")]
Expand Down
5 changes: 3 additions & 2 deletions crates/vm/src/vm/setting.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use core::num::NonZeroI32;
#[cfg(feature = "flame-it")]
use std::ffi::OsString;

/// Path configuration computed at runtime (like PyConfig path outputs)
Expand Down Expand Up @@ -74,7 +73,8 @@ pub struct Settings {
// int malloc_stats;
// wchar_t *filesystem_encoding;
// wchar_t *filesystem_errors;
// wchar_t *pycache_prefix;
/// -X pycache_prefix, PYTHONPYCACHEPREFIX
pub pycache_prefix: Option<OsString>,
// int parse_argv;
// PyWideStringList orig_argv;
/// sys.argv
Expand Down Expand Up @@ -230,6 +230,7 @@ impl Default for Settings {
hash_seed: None,
faulthandler: false,
import_time: 0,
pycache_prefix: None,
code_debug_ranges: true,
buffered_stdio: true,
check_hash_pycs_mode: CheckHashPycsMode::Default,
Expand Down
8 changes: 7 additions & 1 deletion src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ pub fn parse_opts() -> Result<(Settings, RunMode), lexopt::Error> {

settings.optimize = cmp::max(args.optimize, env_count("PYTHONOPTIMIZE"));
settings.verbose = cmp::max(args.verbose, env_count("PYTHONVERBOSE"));
settings.debug = cmp::max(args.debug, env_count("PYTHONDEBUG"));
settings.debug = u8::from(cmp::max(args.debug, env_count("PYTHONDEBUG")) != 0);

let env_bool = |env| get_env(env).is_some_and(|v| !v.is_empty());
settings.dev_mode = env_bool("PYTHONDEVMODE");
Expand Down Expand Up @@ -295,6 +295,7 @@ pub fn parse_opts() -> Result<(Settings, RunMode), lexopt::Error> {
}

settings.check_hash_pycs_mode = args.check_hash_based_pycs;
settings.pycache_prefix = get_env("PYTHONPYCACHEPREFIX").filter(|value| !value.is_empty());

if let Some(val) = get_env("PYTHON_LAZY_IMPORTS").filter(|val| !val.is_empty()) {
settings.lazy_imports = parse_lazy_imports(val.to_str(), "PYTHON_LAZY_IMPORTS");
Expand All @@ -314,13 +315,18 @@ pub fn parse_opts() -> Result<(Settings, RunMode), lexopt::Error> {
let mut import_time_option_seen = false;
let mut frozen_modules_option_seen = false;
let mut utf8_option_seen = false;
let mut pycache_prefix_option_seen = false;
let xopts = args.implementation_option.into_iter().map(|s| {
let (name, value) = match s.split_once('=') {
Some((name, value)) => (name.to_owned(), Some(value)),
None => (s, None),
};
match &*name {
"dev" => settings.dev_mode = true,
"pycache_prefix" if !pycache_prefix_option_seen => {
settings.pycache_prefix = value.filter(|value| !value.is_empty()).map(Into::into);
pycache_prefix_option_seen = true;
}
"importtime" if !import_time_option_seen => {
settings.import_time = parse_import_time(value, "-X importtime");
import_time_option_seen = true;
Expand Down
Loading