-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add command line parameter -P #4611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -730,7 +730,7 @@ mod sys { | |||
dev_mode: settings.dev_mode, | |||
utf8_mode: 1, | |||
int_max_str_digits: -1, | |||
safe_path: false, | |||
safe_path: settings.safe_path, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified safe_path to be set from parameter
Lib/test/test_cmd_line.py
Outdated
# TODO: RUSTPYTHON | ||
@unittest.expectedFailure | ||
def test_pythonsafepath_env(self): | ||
# Test the PYTHONSAFEPATH environment variable | ||
code = "import sys; print(sys.flags.safe_path)" | ||
env = dict(os.environ) | ||
env.pop('PYTHONSAFEPATH', None) | ||
args = (sys.executable, '-P', code) | ||
|
||
proc = subprocess.run(args, stdout=subprocess.PIPE, | ||
universal_newlines=True, env=env) | ||
self.assertEqual(proc.stdout.rstrip(), 'False') | ||
self.assertEqual(proc.returncode, 0, proc) | ||
|
||
env['PYTHONSAFEPATH'] = '1' | ||
proc = subprocess.run(args, stdout=subprocess.PIPE, | ||
universal_newlines=True, env=env) | ||
self.assertEqual(proc.stdout.rstrip(), 'True') | ||
self.assertEqual(proc.returncode, 0, proc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this from CPython?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I just added it. I'll check CPython.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is not existed in CPython. Is it better deleting this code ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes here, but moving to other place is good if the case is not yet covered by cpython unittest, .
Because Lib
is copy of cpython repository, we usually put our own test under extra_tests/snippets
.
Lib/subprocess.py
Outdated
@@ -288,6 +288,7 @@ def _args_from_interpreter_flags(): | |||
'verbose': 'v', | |||
'bytes_warning': 'b', | |||
'quiet': 'q', | |||
'safe_path': 'P' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if subprocess.py is too old, rather than editing it yourself, could you try to update it by following the library update guideline on #4564?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in #4981. We can now try and rebase after its merged and push this through too.
Lib/test/test_support.py
Outdated
@@ -516,7 +516,7 @@ def check_options(self, args, func, expected=None): | |||
self.assertEqual(proc.returncode, 0) | |||
|
|||
# TODO: RUSTPYTHON | |||
@unittest.expectedFailure | |||
# @unittest.expectedFailure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remember to completely remove these comments
hey @naonus do you have time to follow along with this PR? If not, we can pick it up. |
Lib/test/test_cmd_line.py
Outdated
code = "import sys; print(sys.flags.safe_path)" | ||
env = dict(os.environ) | ||
env.pop('PYTHONSAFEPATH', None) | ||
args = (sys.executable, '-P', code) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
args = (sys.executable, '-P', code) | |
args = (sys.executable, '-P', '-c', code) |
Lib/test/test_cmd_line.py
Outdated
|
||
proc = subprocess.run(args, stdout=subprocess.PIPE, | ||
universal_newlines=True, env=env) | ||
self.assertEqual(proc.stdout.rstrip(), 'False') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.assertEqual(proc.stdout.rstrip(), 'False') | |
self.assertEqual(proc.stdout.rstrip(), 'True') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for contributing!
It's not passed test case with errors below
AssertionError: '[]' != "['-P']"
#4541