-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from sirosen/detect-script-shebangs
Add detection for scripts by shebang line
- Loading branch information
Showing
5 changed files
with
68 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Presence of Python script parameters now honors files with a shebang even if no Python extension is present. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import pytest | ||
|
||
from pip_run import commands | ||
|
||
|
||
valid_shebangs = [ | ||
'#!/usr/bin/env python', | ||
'#!/usr/bin/env -S pip-run', | ||
'#!/usr/bin/python -W error', | ||
# with BOM | ||
'#!/usr/bin/env -S python'.encode('utf-8-sig').decode('utf-8'), | ||
] | ||
|
||
invalid_shebangs = [ | ||
'#/usr/bin/env python', | ||
'!/usr/bin/env python', | ||
] | ||
|
||
|
||
@pytest.mark.parametrize('shebang', valid_shebangs) | ||
def test_shebang_detected(tmp_path, shebang): | ||
script = tmp_path / 'script' | ||
script.write_text(f'{shebang}\nprint("Hello world!")', encoding='utf-8') | ||
assert commands._has_shebang(script) | ||
|
||
|
||
@pytest.mark.parametrize('shebang', invalid_shebangs) | ||
def test_shebang_not_detected(tmp_path, shebang): | ||
script = tmp_path / 'script' | ||
script.write_text(f'{shebang}\nprint("Hello world!")', encoding='utf-8') | ||
assert not commands._has_shebang(script) | ||
|
||
|
||
def test_shebang_invalid_encoding(tmp_path): | ||
""" | ||
If the script cannot be decoded in UTF-8, value should be false. | ||
""" | ||
script = tmp_path / 'script' | ||
shebang = '\xf1#!/usr/bin/env -S python' | ||
script.write_text(f'{shebang}\nprint("Hello world!")', encoding='latin-1') | ||
assert not commands._has_shebang(script) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters