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

Allow user to force syntax highlighting using config file, env var or command line. Enable syntax highlighting in GitHub Action. #353

Merged
merged 19 commits into from
Apr 10, 2022

Conversation

akaihola
Copy link
Owner

@akaihola akaihola commented Apr 3, 2022

By default, highlighting is now enabled if outputting to a terminal and pygments is installed.

Highlighting can now be force enabled for non-terminal output or force disabled for terminal output using:

  • color = {true|false} in pyproject.toml,
  • the PY_COLORS={0|1} environment variables (overrides pyproject.toml), or
  • the --color/--no-color command line options (override both pyproject.toml and the environment variable)

Remaining tasks:

Fixes #263.

See also #355 as a follow-up issue (possible support for the NO_COLOR environment variable).

@akaihola akaihola added the enhancement New feature or request label Apr 3, 2022
@akaihola akaihola added this to the 1.5.0 milestone Apr 3, 2022
@akaihola akaihola requested a review from mayk0gan April 3, 2022 19:51
@akaihola akaihola self-assigned this Apr 3, 2022
@akaihola akaihola changed the title Make force highlighting configurable Allow user to force highlighting using config file, env var or command line Apr 4, 2022
@akaihola
Copy link
Owner Author

akaihola commented Apr 5, 2022

It works in akaihola/pgtricks#18!

kuva

@akaihola akaihola changed the title Allow user to force highlighting using config file, env var or command line Allow user to force highlighting using config file, env var or command line. Use in GitHub Action. Apr 5, 2022
@akaihola
Copy link
Owner Author

akaihola commented Apr 5, 2022

@mayk0gan, good news, you can see syntax highlighting in action for Darker output in akaihola/pgtricks build #24 (see screenshot in earlier comment).

Could you review this pull request and approve it for merging if it looks good to you?

@akaihola akaihola changed the title Allow user to force highlighting using config file, env var or command line. Use in GitHub Action. Allow user to force syntax highlighting using config file, env var or command line. Enable syntax highlighting in GitHub Action. Apr 5, 2022
@akaihola akaihola added help wanted Extra attention is needed review needed Please volunteer for code review to speed up merging this pull request. Thank you! labels Apr 6, 2022
@akaihola akaihola requested a review from MatthijsBurgh April 9, 2022 19:37
@akaihola
Copy link
Owner Author

akaihola commented Apr 9, 2022

Looking for a reviewer for this, pinging contributors previously interested in the GitHub Action:
@jenshnielsen @cclauss @brtknr @yoursvivek

@akaihola akaihola requested a review from roniemartinez April 9, 2022 19:41
Copy link
Collaborator

@roniemartinez roniemartinez left a comment

Choose a reason for hiding this comment

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

LGTM

README.rst Outdated Show resolved Hide resolved
src/darker/tests/test_highlighting.py Show resolved Hide resolved
Copy link
Collaborator

@MatthijsBurgh MatthijsBurgh left a comment

Choose a reason for hiding this comment

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

I think we should allow true and false for color.

src/darker/config.py Show resolved Hide resolved
src/darker/help.py Show resolved Hide resolved
src/darker/highlighting/__init__.py Show resolved Hide resolved
src/darker/tests/test_command_line.py Show resolved Hide resolved
src/darker/tests/test_highlighting.py Show resolved Hide resolved
src/darker/tests/test_highlighting.py Show resolved Hide resolved
The environment variable `PY_COLORS` overrides `color =` from
`pyproject.toml`, and the command line options override both of those.
This helps in testing feature branches like this one in actual GitHub
workflows of other repositories.
akaihola and others added 10 commits April 10, 2022 13:11
Thanks @roniemartinez

Co-authored-by: Ronie Martinez <ronmarti18@gmail.com>
So lower case `true` and `false`.
If `pygments` isn't installed, highlighting should never be used. So
these test cases can be easily parameterized as a test matrix.

Also simplified the other half of `should_use_color()` tests a bit.
Thanks @MatthijsBurgh!

Co-authored-by: Matthijs van der Burgh <MatthijsBurgh@outlook.com>
@akaihola akaihola merged commit ad6cde1 into master Apr 10, 2022
@akaihola akaihola deleted the force-colors branch April 10, 2022 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed review needed Please volunteer for code review to speed up merging this pull request. Thank you!
Projects
Development

Successfully merging this pull request may close these issues.

The GitHub action for Darker doesn't use syntax highlighting
3 participants