Stabilize python default version lookup by scop · Pull Request #1117 · pre-commit/pre-commit · GitHub
Skip to content

Stabilize python default version lookup - #1117

Merged
asottile merged 5 commits into
pre-commit:masterfrom
scop:py3-default-version
Aug 15, 2019
Merged

asottile merged 5 commits into
pre-commit:masterfrom
scop:py3-default-version

Conversation

@scop

@scop scop commented Aug 15, 2019

Copy link
Copy Markdown
Contributor

For example, for sys.executable:

/usr/bin/python3 -> python3.7

...the default lookup may return either python3 or python3.7. Make the order deterministic by iterating over tuple, not set, of candidates.

@scop

scop commented Aug 15, 2019

Copy link
Copy Markdown
Contributor Author

For example, for sys.executable:
    /usr/bin/python3 -> python3.7
...the default lookup may return either python3 or python3.7. Make the
order deterministic by iterating over tuple, not set, of candidates.
@scop

scop commented Aug 15, 2019

Copy link
Copy Markdown
Contributor Author

Don't know what's up with the tests, they pass for me in local tox on Linux.

@asottile

Copy link
Copy Markdown
Member

as written, those tests require everything to be on PATH which won't be true when we test individual pythons

they pass locally for you because you have all of those pythons available

patch looks fine -- even a patch which just changes the brackets would probably be fine to merge if this is difficult to test

Comment thread tests/languages/python_test.py Outdated
with mock.patch.object(sys, 'executable', exe):
with mock.patch('os.path.realpath', return_value=realpath):
assert python._find_by_sys_executable() == expected
with mock.patch('pre_commit.parse_shebang.find_executable',

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 mock.patch.object instead, mock.patch has import side-effects and can lead to some nasty patch leaking issues. mock.patch.object is also more explicit about the target

also, that feel when you don't run the pre-commit hooks while contributing to pre-commit 😆

Comment thread tests/languages/python_test.py Outdated


@pytest.mark.parametrize(
'exe,realpath,expected', (

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 prefer a tuple of strings here instead of stringly typed parametrize as well

@asottile asottile 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.

realized I can do a few of the nitpicks as suggestions

Comment thread pre_commit/languages/python.py Outdated


def _get_default_version(): # pragma: no cover (platform dependent)

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.

Suggested change

Comment thread tests/languages/python_test.py Outdated


@pytest.mark.parametrize(
'exe,realpath,expected', (

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.

Suggested change
'exe,realpath,expected', (
('exe', 'realpath', 'expected'), (

@scop

scop commented Aug 15, 2019

Copy link
Copy Markdown
Contributor Author

Thanks, learned something new :) And I hope I caught all of it now.

Comment thread pre_commit/languages/python.py
Comment thread tests/languages/python_test.py Outdated
import mock
import pytest

import pre_commit.parse_shebang

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.

Suggested change
import pre_commit.parse_shebang
from pre_commit import parse_shebang

Comment thread tests/languages/python_test.py Outdated
with mock.patch.object(sys, 'executable', exe):
with mock.patch.object(os.path, 'realpath', return_value=realpath):
with mock.patch.object(
pre_commit.parse_shebang, 'find_executable',

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.

Suggested change
pre_commit.parse_shebang, 'find_executable',
parse_shebang, 'find_executable',

@scop

scop commented Aug 15, 2019

Copy link
Copy Markdown
Contributor Author

@asottile asottile 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants