Skip to content

Conversation

@PatrikKopkan
Copy link
Contributor

@PatrikKopkan PatrikKopkan commented Sep 6, 2019

  • this option enables to add single literal
    flag to kept flags

https://bugs.python.org/issue37064

- this option enables to add single literal
flag to kept flags
@PatrikKopkan PatrikKopkan changed the title bpo-37064: add -a to Tools/Scripts/pathfix.py bpo-37064: add option -a to Tools/Scripts/pathfix.py Sep 6, 2019
self.assertEqual(
self.pathfix(
'#! /usr/bin/env python -s',
['-i', '/usr/bin/python3', '-a', 's', ]),
Copy link
Member

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.

flags = b''
if keep_flags:
flags = parse_shebang(line)
if keep_flags or add_flags:
Copy link
Member

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

self.pathfix(
'#! /usr/bin/env python',
['-i', '/usr/bin/python3',]),
['-i', '/usr/bin/python3', ]),
Copy link
Member

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']

'#! /usr/bin/env python -W something',
['-i', '/usr/bin/python3', '-a', 's', '-k']),
'#! /usr/bin/python3 -sW something',
)
Copy link
Member

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?

'#! /usr/bin/env python',
['-i', '/usr/bin/python3', '-a', 's']),
'#! /usr/bin/python3 -s',
)
Copy link
Member

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.

self.pathfix(
'#! /usr/bin/env python -s',
['-i', '/usr/bin/python3', '-a', 's']),
'#! /usr/bin/python3 -s',
Copy link
Member

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.

self.pathfix(
'#! /usr/bin/env python -v',
['-i', '/usr/bin/python3', '-a', 'v', '-k']),
'#! /usr/bin/python3 -vv',
Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP 8 prefers:

Suggested change
'#! /usr/bin/python3',)
'#! /usr/bin/python3')

Same remark for changes below.

Copy link
Member

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.

Patrik Kopkan and others added 2 commits September 12, 2019 16:31
Co-Authored-By: Victor Stinner <[email protected]>

Co-Authored-By: Victor Stinner <[email protected]>
'#! /usr/bin/env python -W something',
['-i', '/usr/bin/python3', '-a', 's', '-k']),
'#! /usr/bin/python3 -sW something')
self.assertEqual(
Copy link
Member

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)

@bedevere-bot
Copy link

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 I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

proc = subprocess.run(
[sys.executable, self.script,
*pathfix_flags, '-n', self.temp_file],
capture_output=True)
Copy link
Member

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).

['-i', '/usr/bin/python3', '-a', 's', '-k']),
'#! /usr/bin/python3 -sW something')

def test_pathfix_adding_whitespaces(self):
Copy link
Member

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().

self.addCleanup(support.unlink, support.TESTFN)

def pathfix(self, shebang, pathfix_flags):
def pathfix(self, shebang, pathfix_flags, expected_returncode=0, stderr=''):
Copy link
Member

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)

capture_output=True)
self.assertEqual(proc.returncode, 0, proc)

self.assertEqual(proc.returncode, expected_returncode, proc)
Copy link
Member

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) 

Copy link
Member

@vstinner vstinner left a 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? :-)

'#! /usr/bin/python3 -Rs')
self.assertEqual(
self.pathfix(
'#! /usr/bin/env python -W something',
Copy link
Member

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.

def test_pathfix_adding_errors(self):
self.pathfix(
'#! /usr/bin/env python -W something',
['-i', '/usr/bin/python3', '-a', ' af', '-k'],
Copy link
Member

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.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @PatrikKopkan ;-)

@vstinner vstinner merged commit 1dc1acb into python:master Sep 25, 2019
vstinner added a commit that referenced this pull request Sep 25, 2019
* 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)
jacobneiltaylor pushed a commit to jacobneiltaylor/cpython that referenced this pull request Dec 5, 2019
Add option -a to Tools/Scripts/pathfix.py script: add flags.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants