Specify the path of pygmentize

For reasons that are complicated to explain, I have pygmentize installed on my machine but it’s not in the PATH, so I call it using a relative path, like ./bin/pygmentize

I have seen that Hugo checks if pygmentize is in the PATH: https://github.com/gohugoio/hugo/blob/873a6f18851bcda79d562ff6c02e1109e8e31a88/helpers/pygments.go#L37

Is there a way to specify the path to pygmentize in the config file of Hugo?

No there isn’t. PATH only.

Thanks @bep.
Do you think this would be a welcomed modification to the code base?

Yes, but there should be a completeness to that PR, i.e. all of the external tools should have one, it should be default not set, i.e. fall default to the PATH logic currently in place.

1 Like

Good @bep.

Which other 3rd party tools are used by Hugo?

These 3:

  • rst2html (i.e. doctools)
  • asciidoc / asciidoctor
  • pygmentize

Is there some reason why you can’t just update your PATH? You’re adding a bunch of code to solve a problem that’s easily solved outside of Hugo.

1 Like

I am aware that it’s a weird situation but in my context I can have different versions of pygments on the same machine

Also, I’d like to ship a bundle that "just works"TM and avoid asking the user “hey you should install pygments”.

Wouldn’t this work well enough?

PATH=./bin:$PATH hugo

If you’re distributing a “bundle” to different people, you could use a script that calls hugo after modifying the PATH to the location of the binary, i.e.

# Inside hugo.sh
PATH="${BASH_SOURCE%/*}"/bin:$PATH hugo "$@"
  • "${BASH_SOURCE%/*}"/bin is the subdirectory bin under the folder containing the script
  • "$@" passes all arguments to the script to hugo, so the person would just call hugo.sh server --buildDrafts and it should work as normal.

(I haven’t actually tested the above, but it should work on systems that use the bash shell)

I am not sure I can do this is a sandboxed Mac application. I’ll investigate. If I can, my problem I solved.

Thanks @Shadow53

I verified this. I can tweak the PATH before running a child process. This will allow me to specify where’s pigmentize and such before running Hugo. So my proposed change doesn’t make a lot of sense. Will close the PR.
Thanks everybody for the feedback!