Skip to content
This repository was archived by the owner on Apr 30, 2020. It is now read-only.

Commit bdd7c87

Browse files
author
Michal Cyprian
committed
Add more debugging messages to shebangs check
1 parent 90a1b43 commit bdd7c87

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

taskotron_python_versions/unversioned_shebangs.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,15 @@ def get_problematic_files(archive, query):
3838
return problematic
3939

4040

41-
def shebang_to_require(shebang):
42-
"""Convert shebang to the format of requirement."""
43-
return shebang.split()[0][2:].encode()
41+
def shebang_to_require(shebang, use_bytes=True):
42+
"""Convert shebang to the format of requirement.
43+
If the use_bytes argument is set to False, executable path
44+
is returned as a string instead of the default bytes type."""
45+
executable_path = shebang.split()[0][2:]
46+
if use_bytes:
47+
return executable_path.encode()
48+
else:
49+
return executable_path
4450

4551

4652
def get_scripts_summary(package):
@@ -52,8 +58,13 @@ def get_scripts_summary(package):
5258

5359
for shebang in FORBIDDEN_SHEBANGS:
5460
if shebang_to_require(shebang) in package.require_names:
61+
log.debug('Package {} requires {}'.format(
62+
package.filename, shebang_to_require(
63+
shebang, use_bytes=False)))
5564
problematic = get_problematic_files(package.path, shebang)
5665
if problematic:
66+
log.debug('{} shebang was found in scripts: {}'.format(
67+
shebang, ', '.join(problematic)))
5768
scripts_summary[shebang] = problematic
5869
return scripts_summary
5970

test/functional/test_unversioned_shebangs.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ def test_get_problematic_files(archive, query, expected):
4040
assert get_problematic_files(gpkg_path(archive), query) == expected
4141

4242

43-
@pytest.mark.parametrize(('shebang', 'expected'), (
44-
("#!/foo", b"/foo"),
45-
("#!/usr/bin/python", b"/usr/bin/python"),
46-
("#!/usr/bin/env python", b"/usr/bin/env"),
43+
@pytest.mark.parametrize(('shebang', 'use_bytes', 'expected'), (
44+
("#!/foo", True, b"/foo"),
45+
("#!/usr/bin/python", True, b"/usr/bin/python"),
46+
("#!/usr/bin/env python", True, b"/usr/bin/env"),
47+
("#!/usr/bin/python", False, "/usr/bin/python"),
48+
("#!/usr/bin/env python", False, "/usr/bin/env"),
4749
))
48-
def test_shebang_to_require(shebang, expected):
49-
assert shebang_to_require(shebang) == expected
50+
def test_shebang_to_require(shebang, use_bytes, expected):
51+
assert shebang_to_require(shebang, use_bytes) == expected
5052

5153

5254
@pytest.mark.parametrize(('glob', 'expected'), (

0 commit comments

Comments
 (0)