Skip to content

Commit a4e5dc2

Browse files
authored
Merge pull request #7818 from nulano/bugreport
2 parents c5eb7c7 + 6b0a79c commit a4e5dc2

File tree

6 files changed

+65
-15
lines changed

6 files changed

+65
-15
lines changed

.github/ISSUE_TEMPLATE/ISSUE_REPORT.md

+15
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,21 @@ Thank you.
4848
* Python:
4949
* Pillow:
5050

51+
```text
52+
Please paste here the output of running:
53+
54+
python3 -m PIL.report
55+
or
56+
python3 -m PIL --report
57+
58+
Or the output of the following Python code:
59+
60+
from PIL import report
61+
# or
62+
from PIL import features
63+
features.pilinfo(supported_formats=False)
64+
```
65+
5166
<!--
5267
Please include **code** that reproduces the issue and whenever possible, an **image** that demonstrates the issue. Please upload images to GitHub, not to third-party file hosting sites. If necessary, add the image to a zip or tar archive.
5368

Tests/test_features.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,10 @@ def test_unsupported_module() -> None:
117117
features.version_module(module)
118118

119119

120-
def test_pilinfo() -> None:
120+
@pytest.mark.parametrize("supported_formats", (True, False))
121+
def test_pilinfo(supported_formats) -> None:
121122
buf = io.StringIO()
122-
features.pilinfo(buf)
123+
features.pilinfo(buf, supported_formats=supported_formats)
123124
out = buf.getvalue()
124125
lines = out.splitlines()
125126
assert lines[0] == "-" * 68
@@ -129,9 +130,15 @@ def test_pilinfo() -> None:
129130
while lines[0].startswith(" "):
130131
lines = lines[1:]
131132
assert lines[0] == "-" * 68
132-
assert lines[1].startswith("Python modules loaded from ")
133-
assert lines[2].startswith("Binary modules loaded from ")
134-
assert lines[3] == "-" * 68
133+
assert lines[1].startswith("Python executable is")
134+
lines = lines[2:]
135+
if lines[0].startswith("Environment Python files loaded from"):
136+
lines = lines[1:]
137+
assert lines[0].startswith("System Python files loaded from")
138+
assert lines[1] == "-" * 68
139+
assert lines[2].startswith("Python Pillow modules loaded from ")
140+
assert lines[3].startswith("Binary Pillow modules loaded from ")
141+
assert lines[4] == "-" * 68
135142
jpeg = (
136143
"\n"
137144
+ "-" * 68
@@ -142,4 +149,4 @@ def test_pilinfo() -> None:
142149
+ "-" * 68
143150
+ "\n"
144151
)
145-
assert jpeg in out
152+
assert supported_formats == (jpeg in out)

Tests/test_main.py

+19-6
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@
44
import subprocess
55
import sys
66

7+
import pytest
78

8-
def test_main() -> None:
9-
out = subprocess.check_output([sys.executable, "-m", "PIL"]).decode("utf-8")
9+
10+
@pytest.mark.parametrize(
11+
"args, report",
12+
((["PIL"], False), (["PIL", "--report"], True), (["PIL.report"], True)),
13+
)
14+
def test_main(args, report) -> None:
15+
args = [sys.executable, "-m"] + args
16+
out = subprocess.check_output(args).decode("utf-8")
1017
lines = out.splitlines()
1118
assert lines[0] == "-" * 68
1219
assert lines[1].startswith("Pillow ")
@@ -15,9 +22,15 @@ def test_main() -> None:
1522
while lines[0].startswith(" "):
1623
lines = lines[1:]
1724
assert lines[0] == "-" * 68
18-
assert lines[1].startswith("Python modules loaded from ")
19-
assert lines[2].startswith("Binary modules loaded from ")
20-
assert lines[3] == "-" * 68
25+
assert lines[1].startswith("Python executable is")
26+
lines = lines[2:]
27+
if lines[0].startswith("Environment Python files loaded from"):
28+
lines = lines[1:]
29+
assert lines[0].startswith("System Python files loaded from")
30+
assert lines[1] == "-" * 68
31+
assert lines[2].startswith("Python Pillow modules loaded from ")
32+
assert lines[3].startswith("Binary Pillow modules loaded from ")
33+
assert lines[4] == "-" * 68
2134
jpeg = (
2235
os.linesep
2336
+ "-" * 68
@@ -31,4 +44,4 @@ def test_main() -> None:
3144
+ "-" * 68
3245
+ os.linesep
3346
)
34-
assert jpeg in out
47+
assert report == (jpeg not in out)

src/PIL/__main__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
import sys
4+
35
from .features import pilinfo
46

5-
pilinfo()
7+
pilinfo(supported_formats="--report" not in sys.argv)

src/PIL/features.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ def pilinfo(out=None, supported_formats=True):
230230
"""
231231
Prints information about this installation of Pillow.
232232
This function can be called with ``python3 -m PIL``.
233+
It can also be called with ``python3 -m PIL.report`` or ``python3 -m PIL --report``
234+
to have "supported_formats" set to ``False``, omitting the list of all supported
235+
image file formats.
233236
234237
:param out:
235238
The output stream to print to. Defaults to ``sys.stdout`` if ``None``.
@@ -249,12 +252,17 @@ def pilinfo(out=None, supported_formats=True):
249252
for py_version in py_version[1:]:
250253
print(f" {py_version.strip()}", file=out)
251254
print("-" * 68, file=out)
255+
print(f"Python executable is {sys.executable or 'unknown'}", file=out)
256+
if sys.prefix != sys.base_prefix:
257+
print(f"Environment Python files loaded from {sys.prefix}", file=out)
258+
print(f"System Python files loaded from {sys.base_prefix}", file=out)
259+
print("-" * 68, file=out)
252260
print(
253-
f"Python modules loaded from {os.path.dirname(Image.__file__)}",
261+
f"Python Pillow modules loaded from {os.path.dirname(Image.__file__)}",
254262
file=out,
255263
)
256264
print(
257-
f"Binary modules loaded from {os.path.dirname(Image.core.__file__)}",
265+
f"Binary Pillow modules loaded from {os.path.dirname(Image.core.__file__)}",
258266
file=out,
259267
)
260268
print("-" * 68, file=out)

src/PIL/report.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from __future__ import annotations
2+
3+
from .features import pilinfo
4+
5+
pilinfo(supported_formats=False)

0 commit comments

Comments
 (0)