-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
bpo-37064: add option -a to Tools/Scripts/pathfix.py #15717
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
- this option enables to add single literal flag to kept flags
Lib/test/test_tools/test_pathfix.py
Outdated
| self.assertEqual( | ||
| self.pathfix( | ||
| '#! /usr/bin/env python -s', | ||
| ['-i', '/usr/bin/python3', '-a', 's', ]), |
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.
I would prefer to use a different flag in the old shebang or in the -a argument. Ex: '#! /usr/bin/env python -s' and -a S.
Tools/scripts/pathfix.py
Outdated
| flags = b'' | ||
| if keep_flags: | ||
| flags = parse_shebang(line) | ||
| if keep_flags or add_flags: |
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.
why not always calling this function? it would be simpler
Lib/test/test_tools/test_pathfix.py
Outdated
| self.pathfix( | ||
| '#! /usr/bin/env python', | ||
| ['-i', '/usr/bin/python3',]), | ||
| ['-i', '/usr/bin/python3', ]), |
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.
i would prefer: ['-i', '/usr/bin/python3']
Lib/test/test_tools/test_pathfix.py
Outdated
| '#! /usr/bin/env python -W something', | ||
| ['-i', '/usr/bin/python3', '-a', 's', '-k']), | ||
| '#! /usr/bin/python3 -sW something', | ||
| ) |
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.
What if -a argument contains a space? Should we raise an error?
Lib/test/test_tools/test_pathfix.py
Outdated
| '#! /usr/bin/env python', | ||
| ['-i', '/usr/bin/python3', '-a', 's']), | ||
| '#! /usr/bin/python3 -s', | ||
| ) |
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.
To make tests more compact you can put ")" on the previous line in all tests.
Lib/test/test_tools/test_pathfix.py
Outdated
| self.pathfix( | ||
| '#! /usr/bin/env python -s', | ||
| ['-i', '/usr/bin/python3', '-a', 's']), | ||
| '#! /usr/bin/python3 -s', |
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.
I would prefer to use different flags, like -s and -a S. Otherwise, it's unclear to see which one wins.
Lib/test/test_tools/test_pathfix.py
Outdated
| self.pathfix( | ||
| '#! /usr/bin/env python -v', | ||
| ['-i', '/usr/bin/python3', '-a', 'v', '-k']), | ||
| '#! /usr/bin/python3 -vv', |
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.
Ditto, I would prefer to use different flags like -s and -a S -k.
Misc/NEWS.d/next/Tools-Demos/2019-05-27-15-26-12.bpo-37064.k_SPW2.rst
Outdated
Show resolved
Hide resolved
Misc/NEWS.d/next/Tools-Demos/2019-05-27-15-26-12.bpo-37064.k_SPW2.rst
Outdated
Show resolved
Hide resolved
Lib/test/test_tools/test_pathfix.py
Outdated
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.
PEP 8 prefers:
| '#! /usr/bin/python3',) | |
| '#! /usr/bin/python3') |
Same remark for changes below.
Tools/scripts/pathfix.py
Outdated
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.
I suggest to check for b' ' in add_flags (bytes) instead, since add_flags is used later, not a.
Co-Authored-By: Victor Stinner <[email protected]> Co-Authored-By: Victor Stinner <[email protected]>
Lib/test/test_tools/test_pathfix.py
Outdated
| '#! /usr/bin/env python -W something', | ||
| ['-i', '/usr/bin/python3', '-a', 's', '-k']), | ||
| '#! /usr/bin/python3 -sW something') | ||
| self.assertEqual( |
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.
I suggest to move this check in a separated test_xxx() method. I would prefer to check stderr to ensure that stderr contains "-a option doesn't support whitespaces".
Something like:
def check_pathfix_error(self, shebang, pathfix_flags, expected_stderr, expected_exitcode): ..
self.check_pathfix_error(
'#! /usr/bin/env python -W something',
['-i', '/usr/bin/python3', '-a', 's', '-k']),),
"-a option doesn't support whitespaces", 2)
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Co-Authored-By: Victor Stinner <[email protected]>
Lib/test/test_tools/test_pathfix.py
Outdated
| proc = subprocess.run( | ||
| [sys.executable, self.script, | ||
| *pathfix_flags, '-n', self.temp_file], | ||
| capture_output=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.
please use text=1 instead of .decode() below, to use the proper encoding (locale encoding, rather than always using UTF-8).
Lib/test/test_tools/test_pathfix.py
Outdated
| ['-i', '/usr/bin/python3', '-a', 's', '-k']), | ||
| '#! /usr/bin/python3 -sW something') | ||
|
|
||
| def test_pathfix_adding_whitespaces(self): |
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.
I suggest to rename the method to: test_pathfix_adding_errors().
Lib/test/test_tools/test_pathfix.py
Outdated
| self.addCleanup(support.unlink, support.TESTFN) | ||
|
|
||
| def pathfix(self, shebang, pathfix_flags): | ||
| def pathfix(self, shebang, pathfix_flags, expected_returncode=0, stderr=''): |
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.
Would you mind to rename expected_returncode to just exitcode? (shorter)
Lib/test/test_tools/test_pathfix.py
Outdated
| capture_output=True) | ||
| self.assertEqual(proc.returncode, 0, proc) | ||
|
|
||
| self.assertEqual(proc.returncode, expected_returncode, 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.
Maybe check also stdout, before stderr:
self.assertEqual(proc.stderr.decode(), "", proc)
vstinner
left a comment
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.
LGTM, but can you please fix the two remaining nitpicks before I can merge it? :-)
Lib/test/test_tools/test_pathfix.py
Outdated
| '#! /usr/bin/python3 -Rs') | ||
| self.assertEqual( | ||
| self.pathfix( | ||
| '#! /usr/bin/env python -W something', |
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.
I would prefer to use working flags: " -W default" for example.
Lib/test/test_tools/test_pathfix.py
Outdated
| def test_pathfix_adding_errors(self): | ||
| self.pathfix( | ||
| '#! /usr/bin/env python -W something', | ||
| ['-i', '/usr/bin/python3', '-a', ' af', '-k'], |
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.
I would prefer to use working flags: ..., '-a', 'W default', ... for example.
vstinner
left a comment
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.
LGTM, thanks @PatrikKopkan ;-)
* bpo-37064: Add option -k to Tools/scripts/pathfix.py (GH-15548) Add flag -k to pathscript.py script: preserve shebang flags. (cherry picked from commit 50254ac) * bpo-37064: Add option -a to pathfix.py tool (GH-15717) Add option -a to Tools/Scripts/pathfix.py script: add flags. (cherry picked from commit 1dc1acb)
Add option -a to Tools/Scripts/pathfix.py script: add flags.
flag to kept flags
https://bugs.python.org/issue37064