Skip to content

bpo-37064: add option -a to Tools/Scripts/pathfix.py#15717

Merged
vstinner merged 11 commits into
python:masterfrom
PatrikKopkan:a-option
Sep 25, 2019
Merged

bpo-37064: add option -a to Tools/Scripts/pathfix.py#15717
vstinner merged 11 commits into
python:masterfrom
PatrikKopkan:a-option

Conversation

@PatrikKopkan

@PatrikKopkan PatrikKopkan commented Sep 6, 2019

Copy link
Copy Markdown
Contributor
  • 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
Comment thread Lib/test/test_tools/test_pathfix.py Outdated
self.assertEqual(
self.pathfix(
'#! /usr/bin/env python -s',
['-i', '/usr/bin/python3', '-a', 's', ]),

Copy link
Copy Markdown
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.

Comment thread Tools/scripts/pathfix.py Outdated
flags = b''
if keep_flags:
flags = parse_shebang(line)
if keep_flags or add_flags:

Copy link
Copy Markdown
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

Comment thread Lib/test/test_tools/test_pathfix.py Outdated
self.pathfix(
'#! /usr/bin/env python',
['-i', '/usr/bin/python3',]),
['-i', '/usr/bin/python3', ]),

Copy link
Copy Markdown
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']

Comment thread Tools/scripts/pathfix.py
Comment thread 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',
)

Copy link
Copy Markdown
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?

Comment thread Lib/test/test_tools/test_pathfix.py Outdated
'#! /usr/bin/env python',
['-i', '/usr/bin/python3', '-a', 's']),
'#! /usr/bin/python3 -s',
)

Copy link
Copy Markdown
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.

Comment thread 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',

Copy link
Copy Markdown
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.

Comment thread 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',

Copy link
Copy Markdown
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.

Comment thread Misc/NEWS.d/next/Tools-Demos/2019-05-27-15-26-12.bpo-37064.k_SPW2.rst Outdated
Comment thread Misc/NEWS.d/next/Tools-Demos/2019-05-27-15-26-12.bpo-37064.k_SPW2.rst Outdated
Comment thread Lib/test/test_tools/test_pathfix.py Outdated

Copy link
Copy Markdown
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.

Comment thread Tools/scripts/pathfix.py Outdated

Copy link
Copy Markdown
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.

Comment thread Tools/scripts/pathfix.py Outdated
Comment thread Tools/scripts/pathfix.py
Patrik Kopkan and others added 2 commits September 12, 2019 16:31
Co-Authored-By: Victor Stinner <vstinner@python.org>

Co-Authored-By: Victor Stinner <vstinner@python.org>
Comment thread Tools/scripts/pathfix.py Outdated
Comment thread 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(

Copy link
Copy Markdown
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
Copy Markdown

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.

PatrikKopkan and others added 2 commits September 16, 2019 14:35
Co-Authored-By: Victor Stinner <vstinner@python.org>
Comment thread Lib/test/test_tools/test_pathfix.py Outdated
proc = subprocess.run(
[sys.executable, self.script,
*pathfix_flags, '-n', self.temp_file],
capture_output=True)

Copy link
Copy Markdown
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).

Comment thread Lib/test/test_tools/test_pathfix.py
Comment thread 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):

Copy link
Copy Markdown
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().

Comment thread 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=''):

Copy link
Copy Markdown
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)

Comment thread Lib/test/test_tools/test_pathfix.py Outdated
capture_output=True)
self.assertEqual(proc.returncode, 0, proc)

self.assertEqual(proc.returncode, expected_returncode, proc)

Copy link
Copy Markdown
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) 

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

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? :-)

Comment thread Lib/test/test_tools/test_pathfix.py Outdated
'#! /usr/bin/python3 -Rs')
self.assertEqual(
self.pathfix(
'#! /usr/bin/env python -W something',

Copy link
Copy Markdown
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.

Comment thread 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'],

Copy link
Copy Markdown
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.

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

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