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

pympress: init at 1.2.0 #62137

Merged
merged 2 commits into from Oct 30, 2019
Merged

pympress: init at 1.2.0 #62137

merged 2 commits into from Oct 30, 2019

Conversation

tbenst
Copy link
Contributor

@tbenst tbenst commented May 27, 2019

Motivation for this change

Pympress is a simple yet powerful PDF reader designed for dual-screen presentations.

Things done

Added pympress and dependency python-vlc

  • 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 nix-review --run "nix-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)
  • Assured whether relevant documentation is up to date
  • Fits CONTRIBUTING.md.

Copy link
Member

@aanderse aanderse left a comment

Choose a reason for hiding this comment

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

A few small things I noticed on a quick first pass.

pkgs/applications/office/pympress/default.nix Outdated Show resolved Hide resolved
pkgs/applications/office/pympress/default.nix Outdated Show resolved Hide resolved
pkgs/applications/office/pympress/default.nix Outdated Show resolved Hide resolved
pkgs/development/python-modules/python-vlc/default.nix Outdated Show resolved Hide resolved
pkgs/development/python-modules/python-vlc/default.nix Outdated Show resolved Hide resolved
pkgs/applications/office/pympress/default.nix Outdated Show resolved Hide resolved
pkgs/development/python-modules/python-vlc/default.nix Outdated Show resolved Hide resolved
@tbenst
Copy link
Contributor Author

tbenst commented May 28, 2019

Ok, I'm completely baffled... this package is working fine for pdfs with video on Ubuntu with wrapProgram, but not NixOS. For it to work on NixOS, I can do the following:

> pympress has_video.pdf
[ video fails ]
> nix-shell -p pympress
$ pympress has_video.pdf
[ video succeeds ]

Any idea why this only works in a shell?

@nixos-discourse
Copy link

This pull request has been mentioned on Nix community. There might be relevant details there:

https://discourse.nixos.org/t/ld-library-path-not-set-for-application-unless-in-shell/3060/1

pkgs/applications/office/pympress/default.nix Outdated Show resolved Hide resolved
};

/* with check, segmentation fault:
_gtk_style_provider_private_get_settings: assertion 'GTK_IS_STYLE_PROVIDER_PRIVATE (provider)' failed
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, the tests would likely need to run under X.

See for example

checkPhase = ''
export NO_AT_BRIDGE=1
xvfb-run -s '-screen 0 800x600x24' dbus-run-session \
--config-file=${dbus.daemon}/share/dbus-1/session.conf \
meson test --print-errorlogs
'';

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thx! Do you know what the default checkPhase is for Python? I think it's different from pkgs/stdenv/generic/setup.sh? I'm not sure how the tests are running--there are no tests I can find in pympress repo & python -m unittest does nothing, but the default checkPhase is somehow calling useful tests!

Copy link
Contributor

Choose a reason for hiding this comment

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

It is basically python setup.py test:

${python.pythonForBuild.interpreter} nix_run_setup test

pkgs/applications/office/pympress/default.nix Outdated Show resolved Hide resolved
pkgs/applications/office/pympress/default.nix Outdated Show resolved Hide resolved
@jtojnar
Copy link
Contributor

jtojnar commented May 31, 2019

Do you have an example of PDF with video that we could try?

@tbenst
Copy link
Contributor Author

tbenst commented Jun 2, 2019

@jtojnar here's an example, note that both files need to be in same directory & must open with pdf player that supports video (eg okular or pympress in a nix-shell per #62137 (comment) ;):
https://open-science.s3-us-west-2.amazonaws.com/pdfvid/bayesian_opt.mp4
https://open-science.s3-us-west-2.amazonaws.com/pdfvid/video.pdf

@jtojnar
Copy link
Contributor

jtojnar commented Jun 2, 2019

Works fine for me in pympress not executed in nix-shell.

@tbenst
Copy link
Contributor Author

tbenst commented Jul 1, 2019

@jtojnar what platform? I just tested on two different NixOS machines with sandboxing and video fails unless in a shell. It worked fine however on Ubuntu. I don't think vlc is available unless in the shell for some reason

@jtojnar
Copy link
Contributor

jtojnar commented Jul 13, 2019

I just ran the following commands on NixOS unstable with sandboxing enabled:

$ git hub pull checkout 62137
Fetching pull/62137/head from git@github.com:NixOS/nixpkgs.git
$ nix-build -A pympress
/nix/store/wxhipgsg3qg0fajad28zv9rji76s7jb9-pympress-1.2.0
$ result/bin/pympress ~/Documents/video.pdf
[00007fb2f0006990] cache_read stream error: cannot pre fill buffer
[00007fb2f8001310] cache_read stream error: cannot pre fill buffer
[00007fb2f80189c0] mjpeg demux error: cannot peek
[00007fb2f00212e0] mjpeg demux error: cannot peek
[000000000192d270] main input error: Your input can't be opened
[000000000192d270] main input error: VLC is unable to open the MRL 'file:///home/jtojnar/Documents/bayesian_opt.mp4'. Check the log for details.
[00000000019234c0] main input error: Your input can't be opened
[00000000019234c0] main input error: VLC is unable to open the MRL 'file:///home/jtojnar/Documents/bayesian_opt.mp4'. Check the log for details.

I do see the player but clicking play does not seem to do anything:

Screenshot from 2019-07-13 05-13-01

@aanderse
Copy link
Member

aanderse commented Sep 1, 2019

@tbenst any motivation to continue with this PR?

@tbenst
Copy link
Contributor Author

tbenst commented Sep 1, 2019

@aanderse yes definitely. I’m a bit at a loss why video works in a nix-shell but not otherwise. Perhaps nix-shell isn’t as tight of a sandbox and can access system vlc. In that case the problem may lie with python-vlc

@jtojnar
Copy link
Contributor

jtojnar commented Sep 1, 2019

nix-shell is not sandboxed at all. It can run in a clean environment (like env -i) when you supply --pure flag to it but that’s all.

I can confirm that VLC is indeed loaded on NixOS without nix-shell as I do not have VLC installed but I see errors from VLC when I try to play the video.

How does the failure manifest for you? Do you see the player but it does not play? What do you have in console?

@tbenst
Copy link
Contributor Author

tbenst commented Sep 4, 2019

@jtojnar ah thanks for that, and for the continued help! I'm away from my NixOS box on a poor internet connection, so I'll dive back in on this in a week or so. My recollection is I see the same error you report. Additional info is available in the log file /tmp/pympress.log, which shows this error:

ERROR:pympress.media_overlay:Video support using VLC is disabled.
Traceback (most recent call last):
  File "/nix/store/56fpikjys6a693qfvsrqnhh8cc40vhxh-pympress-1.2.0/lib/python3.7/site-packages/pympress/media_overlay.py", line 548, in <module>
    VLCVideo._instance = vlc.Instance(vlc_opts)
  File "/nix/store/dsm2g8w0vmih9piz8znzbkygy8im4w96-python3.7-python-vlc-3.0.6109/lib/python3.7/site-packages/vlc.py", line 1821, in __new__
    return libvlc_new(len(args), args)
  File "/nix/store/dsm2g8w0vmih9piz8znzbkygy8im4w96-python3.7-python-vlc-3.0.6109/lib/python3.7/site-packages/vlc.py", line 4618, in libvlc_new
    ctypes.c_void_p, ctypes.c_int, ListPOINTER(ctypes.c_char_p))
  File "/nix/store/dsm2g8w0vmih9piz8znzbkygy8im4w96-python3.7-python-vlc-3.0.6109/lib/python3.7/site-packages/vlc.py", line 280, in _Cfunction
    raise NameError('no function %r' % (name,))
NameError: no function 'libvlc_new'

Which suggests that python-vlc is not finding VLC for some reason. Perhaps this is why it works (read: video plays on click) for me in nix-shell: I have vlc installed.

@jtojnar
Copy link
Contributor

jtojnar commented Sep 8, 2019

I redownloaded the MP4 file and now the video plays.

Could you rebase to resolve the merge conflict and also use separate commit per package?

@tbenst
Copy link
Contributor Author

tbenst commented Sep 11, 2019

@jtojnar happy to once can confirm this issue is fixed. I just followed the exact same steps as you but video did not work. I'm also on NixOS unstable with sandboxing enabled.

❯ mkdir ~/Downloads/pympress

❯ cd ~/Downloads/pympress

❯ wget https://open-science.s3-us-west-2.amazonaws.com/pdfvid/bayesian_opt.mp4

❯ wget https://open-science.s3-us-west-2.amazonaws.com/pdfvid/video.pdf

❯ cd ~/code/nixpkgs

❯ git checkout origin/pympress

❯ nix-build -A pympress       
these derivations will be built:
  /nix/store/pq8b4ysjavk8sfxyv5scydqxnx9arjwg-pympress-1.2.0.drv
building '/nix/store/pq8b4ysjavk8sfxyv5scydqxnx9arjwg-pympress-1.2.0.drv'...
[...]
/nix/store/wxhipgsg3qg0fajad28zv9rji76s7jb9-pympress-1.2.0

❯ result/bin/pympress ~/Downloads/pympress/video.pdf 
^C

❯ cat /tmp/pympress.log                             
ERROR:pympress.media_overlay:Video support using VLC is disabled.
Traceback (most recent call last):
  File "/nix/store/wxhipgsg3qg0fajad28zv9rji76s7jb9-pympress-1.2.0/lib/python3.7/site-packages/pympress/media_overlay.py", line 548, in <module>
    VLCVideo._instance = vlc.Instance(vlc_opts)
  File "/nix/store/7iidq681h2rm15xs4jci02dc4f60184n-python3.7-python-vlc-3.0.6109/lib/python3.7/site-packages/vlc.py", line 1821, in __new__
    return libvlc_new(len(args), args)
  File "/nix/store/7iidq681h2rm15xs4jci02dc4f60184n-python3.7-python-vlc-3.0.6109/lib/python3.7/site-packages/vlc.py", line 4618, in libvlc_new
    ctypes.c_void_p, ctypes.c_int, ListPOINTER(ctypes.c_char_p))
  File "/nix/store/7iidq681h2rm15xs4jci02dc4f60184n-python3.7-python-vlc-3.0.6109/lib/python3.7/site-packages/vlc.py", line 280, in _Cfunction
    raise NameError('no function %r' % (name,))
NameError: no function 'libvlc_new'

@jtojnar
Copy link
Contributor

jtojnar commented Sep 11, 2019

Do you see a different error when you drop LD_LIBRARY_PATH? Or what does strace -f tell you about libraries being loaded?

@lheckemann lheckemann added this to the 20.03 milestone Sep 12, 2019
@tbenst
Copy link
Contributor Author

tbenst commented Sep 24, 2019

@jtojnar, nope, dropping LD_LIBRARY_PATH does not change anything.

I just noticed on Ubuntu that video works when I'm in bash but not in zsh, haven't verified on NixOS yet.

edit: any tips on using strace -f? I see a crazy deluge of information

@tbenst
Copy link
Contributor Author

tbenst commented Oct 1, 2019

Rebased. I think the issue is per https://github.com/NixOS/nixpkgs/pull/62137/files#r289532543. Turns out find_library is basically broken (intentionally) in NixOS #27751, so source patching is only way to go. I'm trying to do this with the following line:

patchPhase = ''
    substituteInPlace "vlc.py" \ 
      --replace "p = find_library('vlc')" 'p = "'' + vlc + ''/include/lib/libvlc.so.5"'
    '';

But this gives: substituteStream(): ERROR: Invalid command line argument:. Any tips?

Edit: I also tried substituteInPlace "vlc.py" --replace "p = find_library('vlc')" "p = \"\''${vlc}/include/lib/libvlc.so.5\""

@jtojnar
Copy link
Contributor

jtojnar commented Oct 1, 2019

Except for the confusing quoting, I do not see any issue at a glance. I would suggest using a patch file with substituteAll, since that will make the future need for change obvious by being unable to apply the patch, and also because it is much more elegant. Either way, you should neve override patchPhase, as it will silently break patches attribute.

@jtojnar
Copy link
Contributor

jtojnar commented Oct 2, 2019

And I do not think #27751 has anything to do with this. It only removed ldconfig lookup, not dl lookup, which seems to work fine.

@tbenst
Copy link
Contributor Author

tbenst commented Oct 2, 2019

@jtojnar is there an elegant way to do a patch file with a dynamic path? Not sure how to point to ${vlc} without hardcoding the incredibly fragile "/nix/store/1yy8jfyij1f8l7hhnxl2qvavdh2vmcl2-vlc-3.0.6"

As for find_library, maybe I'm wrong but #25763 (comment) makes me think that this function is more-or-less broken on NixOS.

@jtojnar
Copy link
Contributor

jtojnar commented Oct 2, 2019

See

patches = [
(substituteAll {
src = ./pyogg-paths.patch;
flacLibPath="${flac.out}/lib/libFLAC${stdenv.hostPlatform.extensions.sharedLibrary}";
oggLibPath="${libogg}/lib/libogg${stdenv.hostPlatform.extensions.sharedLibrary}";
vorbisLibPath="${libvorbis}/lib/libvorbis${stdenv.hostPlatform.extensions.sharedLibrary}";
vorbisFileLibPath="${libvorbis}/lib/libvorbisfile${stdenv.hostPlatform.extensions.sharedLibrary}";
vorbisEncLibPath="${libvorbis}/lib/libvorbisenc${stdenv.hostPlatform.extensions.sharedLibrary}";
opusLibPath="${libopus}/lib/libopus${stdenv.hostPlatform.extensions.sharedLibrary}";
opusFileLibPath="${opusfile}/lib/libopusfile${stdenv.hostPlatform.extensions.sharedLibrary}";
})
];

@tbenst
Copy link
Contributor Author

tbenst commented Oct 4, 2019

Video is now working! I think this is good to go. Thanks @jtojnar for patient help.

@tbenst
Copy link
Contributor Author

tbenst commented Oct 8, 2019

Made changes requested, but left postInstall wrapping as video did not work without. Also, I tried adding tests in, but got stymied by a required config file that is generated at runtime. Hopefully can leave that for future work as does appear satisfactorily functional.

Edit: oops, an example layout file made it in this commit. Is there an easy way for me to copy this to ~/.config/pympress for package test, or would that break sandbox? If so the tests may work

@tbenst
Copy link
Contributor Author

tbenst commented Oct 30, 2019

@jtojnar finally had a chance to debug this. Was a simple fix, patch needed to be ${vlc}/lib/libvlc.so.5 not ${vlc}/include/lib/libvlc.so.5

After final review, I think this is ready to go!

@jtojnar jtojnar force-pushed the pympress branch 2 times, most recently from 9eb7248 to cc9b816 Compare October 30, 2019 12:22
Co-Authored-By: Jan Tojnar <jtojnar@gmail.com>
Copy link
Contributor

@jtojnar jtojnar left a comment

Choose a reason for hiding this comment

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

Thanks. I updated the two packages, split them into separate commits, cleaned them up a bit and fixed the licenses. The tests were just a false negatives from Python’s test runner trying to run the application for some reason, there are actually no tests.

Did not update to 1.4.1 since it is not on PyPI and only seems to relevant to Windows. 1.5.0 is still in beta.

Co-Authored-By: Jan Tojnar <jtojnar@gmail.com>
@tbenst
Copy link
Contributor Author

tbenst commented Oct 30, 2019

@jtojnar that's terrific, thanks so much for your patient help! I learned a lot :)

@tbenst tbenst deleted the pympress branch November 1, 2019 20:09
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

5 participants