Merge pull request #7818 from nulano/bugreport

This commit is contained in:
Hugo van Kemenade 2024-03-30 11:13:02 +02:00 committed by GitHub
commit a4e5dc219c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 65 additions and 15 deletions

View File

@ -48,6 +48,21 @@ Thank you.
* Python:
* Pillow:
```text
Please paste here the output of running:
python3 -m PIL.report
or
python3 -m PIL --report
Or the output of the following Python code:
from PIL import report
# or
from PIL import features
features.pilinfo(supported_formats=False)
```
<!--
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.

View File

@ -117,9 +117,10 @@ def test_unsupported_module() -> None:
features.version_module(module)
def test_pilinfo() -> None:
@pytest.mark.parametrize("supported_formats", (True, False))
def test_pilinfo(supported_formats) -> None:
buf = io.StringIO()
features.pilinfo(buf)
features.pilinfo(buf, supported_formats=supported_formats)
out = buf.getvalue()
lines = out.splitlines()
assert lines[0] == "-" * 68
@ -129,9 +130,15 @@ def test_pilinfo() -> None:
while lines[0].startswith(" "):
lines = lines[1:]
assert lines[0] == "-" * 68
assert lines[1].startswith("Python modules loaded from ")
assert lines[2].startswith("Binary modules loaded from ")
assert lines[3] == "-" * 68
assert lines[1].startswith("Python executable is")
lines = lines[2:]
if lines[0].startswith("Environment Python files loaded from"):
lines = lines[1:]
assert lines[0].startswith("System Python files loaded from")
assert lines[1] == "-" * 68
assert lines[2].startswith("Python Pillow modules loaded from ")
assert lines[3].startswith("Binary Pillow modules loaded from ")
assert lines[4] == "-" * 68
jpeg = (
"\n"
+ "-" * 68
@ -142,4 +149,4 @@ def test_pilinfo() -> None:
+ "-" * 68
+ "\n"
)
assert jpeg in out
assert supported_formats == (jpeg in out)

View File

@ -4,9 +4,16 @@ import os
import subprocess
import sys
import pytest
def test_main() -> None:
out = subprocess.check_output([sys.executable, "-m", "PIL"]).decode("utf-8")
@pytest.mark.parametrize(
"args, report",
((["PIL"], False), (["PIL", "--report"], True), (["PIL.report"], True)),
)
def test_main(args, report) -> None:
args = [sys.executable, "-m"] + args
out = subprocess.check_output(args).decode("utf-8")
lines = out.splitlines()
assert lines[0] == "-" * 68
assert lines[1].startswith("Pillow ")
@ -15,9 +22,15 @@ def test_main() -> None:
while lines[0].startswith(" "):
lines = lines[1:]
assert lines[0] == "-" * 68
assert lines[1].startswith("Python modules loaded from ")
assert lines[2].startswith("Binary modules loaded from ")
assert lines[3] == "-" * 68
assert lines[1].startswith("Python executable is")
lines = lines[2:]
if lines[0].startswith("Environment Python files loaded from"):
lines = lines[1:]
assert lines[0].startswith("System Python files loaded from")
assert lines[1] == "-" * 68
assert lines[2].startswith("Python Pillow modules loaded from ")
assert lines[3].startswith("Binary Pillow modules loaded from ")
assert lines[4] == "-" * 68
jpeg = (
os.linesep
+ "-" * 68
@ -31,4 +44,4 @@ def test_main() -> None:
+ "-" * 68
+ os.linesep
)
assert jpeg in out
assert report == (jpeg not in out)

View File

@ -1,5 +1,7 @@
from __future__ import annotations
import sys
from .features import pilinfo
pilinfo()
pilinfo(supported_formats="--report" not in sys.argv)

View File

@ -230,6 +230,9 @@ def pilinfo(out=None, supported_formats=True):
"""
Prints information about this installation of Pillow.
This function can be called with ``python3 -m PIL``.
It can also be called with ``python3 -m PIL.report`` or ``python3 -m PIL --report``
to have "supported_formats" set to ``False``, omitting the list of all supported
image file formats.
:param out:
The output stream to print to. Defaults to ``sys.stdout`` if ``None``.
@ -249,12 +252,17 @@ def pilinfo(out=None, supported_formats=True):
for py_version in py_version[1:]:
print(f" {py_version.strip()}", file=out)
print("-" * 68, file=out)
print(f"Python executable is {sys.executable or 'unknown'}", file=out)
if sys.prefix != sys.base_prefix:
print(f"Environment Python files loaded from {sys.prefix}", file=out)
print(f"System Python files loaded from {sys.base_prefix}", file=out)
print("-" * 68, file=out)
print(
f"Python modules loaded from {os.path.dirname(Image.__file__)}",
f"Python Pillow modules loaded from {os.path.dirname(Image.__file__)}",
file=out,
)
print(
f"Binary modules loaded from {os.path.dirname(Image.core.__file__)}",
f"Binary Pillow modules loaded from {os.path.dirname(Image.core.__file__)}",
file=out,
)
print("-" * 68, file=out)

5
src/PIL/report.py Normal file
View File

@ -0,0 +1,5 @@
from __future__ import annotations
from .features import pilinfo
pilinfo(supported_formats=False)