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
hugo: helpers/content.go: call rst2html directly to render content #47600
Conversation
} | ||
|
||
-func getPythonExecPath() string { | ||
- path, err := exec.LookPath("python") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be even incorrect if python
is not the correct version python version for rst2html
. Can you also open an issue upstream? They really only should do this on windows in my opinion and even there this probably also will work if rst2html is associated with the correct extension (i.e. rst2html.py).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also they check if rst2html
is in $PATH
and is executable. Is this even true on windows?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After digging in LookPath on windows it appears that .py has to be in PATHEXT
to be found by LookPath. This means if it is not already a registered extension it would not be found anyway. If it is registered then prepending python should be not necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know. I am unable to follow their reasoning as well.
I opened an issue upstream like a month ago but haven't received any response at all.
I think it's maybe because Nix is not on their priority list as they have quite a many other issues open. So, maybe we can apply the patch ourselves.
Of all the platforms where Nix works, except Windows, all natively support shebangs.
And, on Windows, Nix works under WSL (experimental) which supports shebangs. So, I believe, we can directly call rst2html for our use case without any issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to wait a few days/hours for them to merge or do you want to go ahead with the current version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, it should be merged. Hugo's next release is at least a month away.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea was to use fetchpatch
instead when it is merged in hugo master.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh! let's wait for upstream to merge it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The community looks active hopefully this will not take long.
@@ -12,6 +12,9 @@ buildGoPackage rec { | |||
rev = "v${version}"; | |||
sha256 = "0n27vyg66jfx4lwswsmdlybly8c9gy5rk7yhy7wzs3rwzlqv1jzj"; | |||
}; | |||
patches = [ | |||
./010-call-rst2html-directly.patch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Now this can fetched from the upstream repository.
Initially, rst2html was called via the python interpreter which would fail if the script was wrapped in a launcher as on NixOS.
pkgs/applications/misc/hugo/rst.nix
Outdated
{ stdenv, hugo, python3, which }: | ||
|
||
stdenv.mkDerivation rec { | ||
name = "hugoWithRST"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need this as a separate package? All it does is adding pygments
. Users who need hugo + docutils + pygments can just install both or write a shell.nix
for their project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried. Installing both packages doesn't work. Hugo is able to find docutils but not pygments.
What I did was:
nix-env -iA nixpkgs.hugo
nix-env -iA nixpkgs.python36Packages.docutils
nix-env -iA nixpkgs.python36Packages.pygments
But, that resulted in hugo reporting that it couldn't find pygments.
It looks like docutils needs pygments and it is unable to find it even if both are installed (but separately) because pygments is not on docutils's PATH (or PYTHONPATH).
Additionally, sure shell.nix works but then shell customization are lost. So, I added it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I usually use direnv to preserve my shell: https://github.com/direnv/direnv/wiki/Nix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be made a build option of hugo or a wrapper like weechat, but I would not clutter all-packages.nix with all possible dependency combinations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach is certainly simpler. I'll remove the extra package. Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Mic92 , I've updated the PR. Thanks.
@Mic92 , |
I have not backported the commit back then to 18.09. This is now the case: f8847fc |
Motivation for this change
Hugo launches rst2html by calling Python interpreter and passing it the path of rst2html file.
This doesn't work on NixOS because the real rst2html is actually wrapped behind a bash script which is responsible for correctly setting the env and then exec-ing the real rst2html.
The problem is that rst2html is actually a bash script and not a Python script. Hence, Python fails to launch it with SyntaxError.
This patch ensures that rst2html is called directly so the shebang work correctly.
Things done
sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)nix path-info -S
before and after)