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

hugo: helpers/content.go: call rst2html directly to render content #47600

Merged
merged 1 commit into from Oct 13, 2018
Merged

hugo: helpers/content.go: call rst2html directly to render content #47600

merged 1 commit into from Oct 13, 2018

Conversation

shreyanshk
Copy link
Contributor

@shreyanshk shreyanshk commented Oct 1, 2018

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
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Fits CONTRIBUTING.md.

}

-func getPythonExecPath() string {
- path, err := exec.LookPath("python")
Copy link
Member

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).

Copy link
Member

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?

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

@Mic92 Mic92 Oct 4, 2018

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.

Copy link
Contributor Author

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.

Copy link
Member

@Mic92 Mic92 Oct 5, 2018

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
Copy link
Member

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.
{ stdenv, hugo, python3, which }:

stdenv.mkDerivation rec {
name = "hugoWithRST";
Copy link
Member

@Mic92 Mic92 Oct 12, 2018

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.

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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 Mic92 merged commit 2993047 into NixOS:master Oct 13, 2018
@shreyanshk
Copy link
Contributor Author

@Mic92 ,
When would this patch be added into the nixos-18.09 channel? I see the channel was updated some time ago but the patch is still not present into that branch.
Thanks.

@Mic92
Copy link
Member

Mic92 commented Oct 18, 2018

I have not backported the commit back then to 18.09. This is now the case: f8847fc

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

Successfully merging this pull request may close these issues.

None yet

4 participants