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

Pygments not installed; causes issues with JSON fields #932

Closed
randykleinman opened this issue Jan 3, 2025 · 2 comments
Closed

Pygments not installed; causes issues with JSON fields #932

randykleinman opened this issue Jan 3, 2025 · 2 comments

Comments

@randykleinman
Copy link

What version of Unfold are you using?

django-unfold==0.43.0

What version of Django are you using?

Django==5.1.3

What browser are you using?

Brave/Chrome/Firefox

Did you checked changelog/commit history, if the bug is not already fixed?

Yes

Did you searched other issues, if the bug is not already fixed?

Yes

Did you checked documentation?

Yes

Are you able to replicate the bug in the demo site?

No

Repository with reproduced bug

N/A

Describe your issue

Ignoring ImportErrors for the pygments package when displaying JSON fields causes the field to be displayed as text, instead of as prettified JSON.

Relevant code is here: https://github.com/unfoldadmin/django-unfold/blob/main/src/unfold/utils.py#L127-L133

Curious if there is a reason why pygments isn't called out as a dependency. Took a while to run this down as I had prettified JSON in my local development environment, but unstyled JSON fields in the admin for my production site. The reason came down to that my local development environment had extra packages that ended up installing pygments as one of their dependencies. Add pygments to by production dependencies and viola, pretty JSON.

No pygments:

Screenshot 2025-01-03 at 12 27 52 PM

With pygments:

Screenshot 2025-01-03 at 12 28 25 PM

@randykleinman randykleinman changed the title Pygments not installedl; causes issues with JSON fields Pygments not installed; causes issues with JSON fields Jan 3, 2025
@lukasvinclav
Copy link
Contributor

Hey Randy, yes you are right, the Pygments library is required to provide highlighting. By default, Unfold does not require to have this library installed and it silently skips highlighting if the library is not available. I'm not planning to add Pygments into dependencies as I want to keep dependencies minimal.

Anyway, I just created new documentation page for JSONField formatting options in admin #933 where I'm mentioning Pygments library and existing behavior. Of course, if you have idea how to improve the developer experience even more, let me know. I'm open to discuss.

@randykleinman
Copy link
Author

Thanks @lukasvinclav , I understand wanting to keep the dependencies minimal. As long as it is documented, like in #933, I think it is great. The only other option I could think of is creating an option package like unfold[pygments]==1.2.3 or unfold[highlighting], but since this seems to be a small one-off for JSON read only fields, a note in the docs is sufficient to creating more builds and build processes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants