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

Make pygments mandatory and fix string highlighting #13189

Merged
merged 2 commits into from
Feb 8, 2025

Conversation

The-Compiler
Copy link
Member

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Feb 3, 2025
Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

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

Awesome, thanks!

@The-Compiler The-Compiler force-pushed the pygments-improvements branch from 747caba to 44e9f68 Compare February 3, 2025 18:06
@The-Compiler
Copy link
Member Author

Didn't quite work out as planned, as I didn't see that the not in assertion output also uses _diff_text, but then post-processes the diff to show a nicer output:

newdiff = [f"{saferepr(term, maxsize=42)} is contained here:"]
for line in diff:
if line.startswith("Skipping"):
continue
if line.startswith("- "):
continue
if line.startswith("+ "):
newdiff.append(" " + line[2:])
else:
newdiff.append(line)

Opted to add a dummy_highlighter function to avoid having to special-case this in _diff_text, WDYT?

@nicoddemus
Copy link
Member

Opted to add a dummy_highlighter function to avoid having to special-case this in _diff_text, WDYT?

Sounds good to me. 👍

Copy link
Contributor

@BenjaminSchubert BenjaminSchubert left a comment

Choose a reason for hiding this comment

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

Looks great, thanks!

Copy link

@KotlinIsland KotlinIsland left a comment

Choose a reason for hiding this comment

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

awesome PR, this is a very welcome change

I think it would make sense to document the extra somewhere. explain why it exists/what it does

@The-Compiler
Copy link
Member Author

I think it would make sense to document the extra somewhere. explain why it exists/what it does

I don't think there's a good place for this in the docs, especially because we don't do this kind of thing for any of the other dependencies either. And if you see it in action (and/or know what Pygments does), I think it's kind of obvious.

@KotlinIsland
Copy link

KotlinIsland commented Feb 4, 2025

think it's kind of obvious

I have no idea what pygments is/does, and I have no idea how to discover if a package has any extras or not. I think not stating that this extra functionality is available would be a disservice to your users 🙂

@The-Compiler
Copy link
Member Author

This PR makes it a dependency, not an extra. You don't need to know it exists, you will just get syntax highlighting after installing pytest.

@KotlinIsland
Copy link

oh, my mistake! sorry, okay that's great!

@The-Compiler The-Compiler force-pushed the pygments-improvements branch from 44e9f68 to ca6557e Compare February 4, 2025 16:52
@The-Compiler The-Compiler force-pushed the pygments-improvements branch from ca6557e to cb089b6 Compare February 4, 2025 16:53
@The-Compiler
Copy link
Member Author

@Pierre-Sassoulas @Zac-HD @RonnyPfannschmidt Do you have any objections/concerns with adding Pygments as a default dependency (at least until PEP 771 – Default Extras for Python Software Packages | peps.python.org is a thing), or should I merge this?

(Sorry for the explicit ping - not asking for a full review as I think we have this covered, just for an opinion on the dependency because I'd like to give everyone a chance to speak up if there is some implication I didn't consider)

@Zac-HD
Copy link
Member

Zac-HD commented Feb 5, 2025

In general I prefer minimal dependencies, but I think the case for Pygments is strong enough to add it in this case.

If we do get a default-extras PEP I'd be keen to move it to that and make sure we test without it too though.

@hugovk
Copy link
Member

hugovk commented Feb 7, 2025

(at least until PEP 771 – Default Extras for Python Software Packages | peps.python.org is a thing)

The PEP is now up for discussion, please leave a comment if you'd like to add your support or give other feedback:

https://discuss.python.org/t/pep-771-default-extras-for-python-software-packages/79706

@The-Compiler The-Compiler merged commit a3d55a6 into pytest-dev:main Feb 8, 2025
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot:chronographer:provided (automation) changelog entry is part of PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(🎁) color the diff of strings Add "color" install extra
8 participants