bpo-37064: add option -a to Tools/Scripts/pathfix.py#15717
Conversation
- this option enables to add single literal flag to kept flags
| self.assertEqual( | ||
| self.pathfix( | ||
| '#! /usr/bin/env python -s', | ||
| ['-i', '/usr/bin/python3', '-a', 's', ]), |
There was a problem hiding this comment.
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.
| flags = b'' | ||
| if keep_flags: | ||
| flags = parse_shebang(line) | ||
| if keep_flags or add_flags: |
There was a problem hiding this comment.
why not always calling this function? it would be simpler
| self.pathfix( | ||
| '#! /usr/bin/env python', | ||
| ['-i', '/usr/bin/python3',]), | ||
| ['-i', '/usr/bin/python3', ]), |
There was a problem hiding this comment.
i would prefer: ['-i', '/usr/bin/python3']
| '#! /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.
What if -a argument contains a space? Should we raise an error?
| '#! /usr/bin/env python', | ||
| ['-i', '/usr/bin/python3', '-a', 's']), | ||
| '#! /usr/bin/python3 -s', | ||
| ) |
There was a problem hiding this comment.
To make tests more compact you can put ")" on the previous line in all tests.
| self.pathfix( | ||
| '#! /usr/bin/env python -s', | ||
| ['-i', '/usr/bin/python3', '-a', 's']), | ||
| '#! /usr/bin/python3 -s', |
There was a problem hiding this comment.
I would prefer to use different flags, like -s and -a S. Otherwise, it's unclear to see which one wins.
| 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.
Ditto, I would prefer to use different flags like -s and -a S -k.
There was a problem hiding this comment.
PEP 8 prefers:
| '#! /usr/bin/python3',) | |
| '#! /usr/bin/python3') |
Same remark for changes below.
There was a problem hiding this comment.
I suggest to check for b' ' in add_flags (bytes) instead, since add_flags is used later, not a.
Co-Authored-By: Victor Stinner <vstinner@python.org> Co-Authored-By: Victor Stinner <vstinner@python.org>
| '#! /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.
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 <vstinner@python.org>
| proc = subprocess.run( | ||
| [sys.executable, self.script, | ||
| *pathfix_flags, '-n', self.temp_file], | ||
| capture_output=True) |
There was a problem hiding this comment.
please use text=1 instead of .decode() below, to use the proper encoding (locale encoding, rather than always using UTF-8).
| ['-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.
I suggest to rename the method to: test_pathfix_adding_errors().
| 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.
Would you mind to rename expected_returncode to just exitcode? (shorter)
| capture_output=True) | ||
| self.assertEqual(proc.returncode, 0, proc) | ||
|
|
||
| self.assertEqual(proc.returncode, expected_returncode, proc) |
There was a problem hiding this comment.
Maybe check also stdout, before stderr:
self.assertEqual(proc.stderr.decode(), "", proc)
vstinner
left a comment
There was a problem hiding this comment.
LGTM, but can you please fix the two remaining nitpicks before I can merge it? :-)
| '#! /usr/bin/python3 -Rs') | ||
| self.assertEqual( | ||
| self.pathfix( | ||
| '#! /usr/bin/env python -W something', |
There was a problem hiding this comment.
I would prefer to use working flags: " -W default" for example.
| 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.
I would prefer to use working flags: ..., '-a', 'W default', ... for example.
vstinner
left a comment
There was a problem hiding this comment.
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