Skip to content

Add argparse to pygemnts2chroma_xml.py script#1140

Merged
alecthomas merged 1 commit into
alecthomas:masterfrom
flofriday:improve-pygments-convert-script
Sep 12, 2025
Merged

Add argparse to pygemnts2chroma_xml.py script#1140
alecthomas merged 1 commit into
alecthomas:masterfrom
flofriday:improve-pygments-convert-script

Conversation

@flofriday

@flofriday flofriday commented Sep 11, 2025

Copy link
Copy Markdown
Contributor

I also adapted the README to use uv since this removes an install step (uv resolves and installs dependencies on uv run).

We could also debate if we should switch from KotlinLexer as an example to some other lexer as there seems to be a bug upstream in pygments where KotlinLexer.get_tokendefs() returns a string that is not valid unicode. You can read more about the bug in this issue.

With argparse the error messages are a lot nicer and the script can better explain itself.

uv run pygments2chroma_xml.py --help                         
usage: pygments2chroma_xml.py [-h] lexer_class

Converts pygments RegexLexer classes to chroma xml grammar definitions.

positional arguments:
  lexer_class  The class name of the pygments lexer, like: 'pygments.lexers.jvm.KotlinLexer'.

options:
  -h, --help   show this help message and exit

Comment thread README.md Outdated

```sh
python3 _tools/pygments2chroma_xml.py \
cd _tools

@alecthomas alecthomas Sep 11, 2025

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This change and the .. below seem unnecessary...

@alecthomas alecthomas Sep 11, 2025

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Also the script is executable, you can actually just run ./_tools/pygments2chroma_xml.py

Want to run this too?

uv add --script ./_tools/pygments2chroma_xml.py pystache pygments

As the script currently doesn't have the dependencies embedded, it won't automatically download them or create a venv.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes that makes more sense.
Do we still need the _tools/pyprojects.toml file then?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Ah, no!

@flofriday flofriday force-pushed the improve-pygments-convert-script branch from 1478f1b to adf7b19 Compare September 11, 2025 21:38
@alecthomas alecthomas merged commit a5dc086 into alecthomas:master Sep 12, 2025
2 checks passed
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

Successfully merging this pull request may close these issues.

2 participants