Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --report argument to __main__.py to omit supported formats #7818

Merged
merged 14 commits into from Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/ISSUE_TEMPLATE/ISSUE_REPORT.md
Expand Up @@ -48,6 +48,10 @@ Thank you.
* Python:
* Pillow:

```text
please paste here the output of the following Python code: `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.

Expand Down
12 changes: 9 additions & 3 deletions Tests/test_features.py
Expand Up @@ -129,9 +129,15 @@
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:]

Check warning on line 135 in Tests/test_features.py

View check run for this annotation

Codecov / codecov/patch

Tests/test_features.py#L135

Added line #L135 was not covered by tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for the record, this happens for... virtual environments?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct: https://docs.python.org/3/library/sys.html#sys.base_prefix

I'm not sure if this can also happen outside of a virtual environment, e.g. on Conda, so I didn't want to explicitly state "Virtual Environment Python files...".

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
Expand Down
12 changes: 9 additions & 3 deletions Tests/test_main.py
Expand Up @@ -15,9 +15,15 @@
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:]

Check warning on line 21 in Tests/test_main.py

View check run for this annotation

Codecov / codecov/patch

Tests/test_main.py#L21

Added line #L21 was not covered by tests
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
Expand Down
4 changes: 3 additions & 1 deletion src/PIL/__main__.py
@@ -1,5 +1,7 @@
from __future__ import annotations

import sys

from .features import pilinfo

pilinfo()
pilinfo(supported_formats="--bugreport" not in sys.argv)
12 changes: 10 additions & 2 deletions src/PIL/features.py
Expand Up @@ -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 --bugreport`` 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``.
Expand All @@ -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)
Expand Down