nixpkgs/pkgs/development
Ivan ca8b128aa1 credstash: add standalone Python application (#51807)
credstash was only available as a library. Provide it as a standalone
application as well.

In order for this to work, I needed to remove the copy of
the library that's placed in $out/bin and marked executable
during the install phase. Other than the patched shebang and
executable bit, it's identical to the library that's installed to
$out/lib/python3.7/site-packages.

Before the postFixup has run `wrapPythonPrograms`, $out/bin contains
two Python files -- credstash and credstash.py -- where bin/credstash
is the executable you'd expect a user to invoke from the command-line
and bin/credstash.py contains the credstash module, which bin/credstash
imports.

After `wrapPythonPrograms` has run, bin/credstash is a shell
wrapper around the bin/.credstash-wrapped python entrypoint, and
bin/credstash.py is shell wrapper around bin/.credstash.py-wrapped.
Invoking bin/credstash execs bin/.credstash-wrapped, and that python
script attempts to import the credstash module from bin/credstash.py,
the shell wrapper, rather than either bin/.credstash.py-wrapped or
lib/python3.7/site-packages/credstash.py.

This leads to an error:

    $ credstash get mykey
    Traceback (most recent call last):
      File "/nix/store/hk6yma716w6141lcdh509d6qyyi7zm0i-python3.7-credstash-1.15.0/bin/.credstash-wrapped", line 8, in <module>
        from credstash import main
      File "/nix/store/hk6yma716w6141lcdh509d6qyyi7zm0i-python3.7-credstash-1.15.0/bin/credstash.py", line 2
        export PATH='/nix/store/6lm4gi5iv8fbf1b1mm6g3gfnnv63f1gn-python3-3.7.1/bin:/nix/store/hk6yma716w6141lcdh509d6qyyi7zm0i-python3.7-credstash-1.15.0/bin:/nix/store/2n13gf1zdr39ir5dynxlkqndxgy36g08-python3.7-setuptools-40.4.3/bin:/nix/store/mhnqwpa4y1l81zi4cwx989i8h8z9g67l-python3.7-jmespath-0.9.0/bin:/nix/store/qc6q3a2nv4211wyh7q319v6zzd3ab6pc-python3.7-docutils-0.14/bin'${PATH:+':'}$PATH
                  ^
    SyntaxError: invalid syntax

If we try using `dontWrapPythonPrograms` to resolve this, runtime
dependency lookups fail:

    $ credstash get mykey
    Traceback (most recent call last):
      File "/run/current-system/sw/bin/credstash", line 7, in <module>
        from credstash import main
      File "/nix/store/8rmldlvlv1z1xl7w02dy7f5qhkzdrg8z-python3.7-credstash-1.15.0/bin/credstash.py", line 26, in <module>
        import boto3
    ModuleNotFoundError: No module named 'boto3'

I was able to resolve things by simply removing bin/credstash.py before
the postFixup phase has a chance to wrap any executables. Now the
executable imports the library correctly:

 (shell wrapper)
  bin/credstash
        │      (python executable)
        └─> bin/.credstash-wrapped
                   │                        (python library)
                   └─> lib/python3.7/site-packages/credstash.py
2018-12-11 10:49:27 +01:00
..
arduino
beam-modules
bower-modules/generic
compilers Merge master into staging-next 2018-12-08 12:40:13 +01:00
coq-modules coqPackages.simple-io: init at 0.2 2018-12-10 15:35:34 +00:00
dhall-modules
dotnet-modules/patches
em-modules/generic
go-modules
guile-modules Treewide: use HTTPS on GNU domains 2018-12-02 15:51:59 +01:00
haskell-modules Merge master into staging-next 2018-12-07 15:22:35 +01:00
idris-modules
interpreters metamath: 0.167 -> 0.168 2018-12-11 09:10:06 +00:00
java-modules
libraries Merge pull request #51811 from veprbl/pr/cernlib_fix 2018-12-10 15:30:05 +01:00
lisp-modules Add cl-jpeg, cl-pdf & cl-typesetting, no extra external deps 2018-12-05 07:01:40 +01:00
lua-modules
misc systems/parse.nix: support eabihf 2018-12-02 19:49:36 -06:00
mobile
node-packages nodePackages: Regenerate and fix azure-cli 2018-12-10 11:46:46 +01:00
ocaml-modules ocamlPackages.checkseum: init at 0.0.3 2018-12-11 08:12:27 +00:00
perl-modules perlPackages: remove old broken packets 2018-11-27 08:11:10 +00:00
pharo
pure-modules
python-modules credstash: add standalone Python application (#51807) 2018-12-11 10:49:27 +01:00
r-modules rstudioWrapper: include desktop file 2018-12-07 16:44:01 -05:00
ruby-modules Merge master into staging-next 2018-12-08 12:40:13 +01:00
tools sbt-extras: 2018-09-27 -> 2018-12-04 2018-12-10 12:56:39 -05:00
web nodejs.updateScript: fix evaluation 2018-12-03 00:49:37 +00:00