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 3 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 the output of running `python3 -m PIL --bugreport` here
Copy link
Member

Choose a reason for hiding this comment

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

Given some of the issues that we've dealt with, I can imagine users running python3 -m PIL --bugreport even if they're using a copy of Python other than python3 to invoke their code.

Would it be better to ask users to paste the output of from PIL import features;features.pilinfo(supported_formats=False)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. That also avoids the issue of --bugreport not being present in older versions.

However, I think adding the option python3 -m PIL --bugreport is still useful on its own.

Copy link
Member

@radarhere radarhere Feb 21, 2024

Choose a reason for hiding this comment

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

Should --bugreport be documented somewhere then?

Copy link
Member

Choose a reason for hiding this comment

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

I've created nulano#31

Copy link
Member

Choose a reason for hiding this comment

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

Can we suggest both? I like the idea of making it extremely easy as a first suggestion:


Paste the output of python3 -m PIL --bugreport or the output of the following Python code:

from PIL import features; features.pilinfo(supported_formats=False)

Copy link
Member

Choose a reason for hiding this comment

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

I'm just concerned about users following python3 -m PIL --bugreport so verbatim that they don't change the Python command to what they are using to run their script, e.g. #7532 (comment)

However, maybe it is better to make most users lives easier than to cater to absolutely everyone.

```

<!--
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)
9 changes: 7 additions & 2 deletions src/PIL/features.py
Expand Up @@ -249,12 +249,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