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

grib-api: Provide python bindings #25990

Merged
merged 1 commit into from
Jun 7, 2017

Conversation

knedlsepp
Copy link
Member

@knedlsepp knedlsepp commented May 22, 2017

This provides a default method for using the grib-api python bindings.

Motivation for this change
Things done
  • Tested using sandboxing
    (nix.useSandbox on NixOS,
    or option build-use-sandbox in nix.conf
    on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • Linux
  • 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/)
  • Fits CONTRIBUTING.md.

@mention-bot
Copy link

@knedlsepp, thanks for your PR! By analyzing the history of the files in this pull request, we identified @FRidh to be a potential reviewer.

@knedlsepp knedlsepp changed the title grib-api: Add grib-api to pythonPackages grib-api: Provide python bindings May 22, 2017
@FRidh
Copy link
Member

FRidh commented May 22, 2017

Could you move the outputs to a "py" output? See e.g. libxml2.

@knedlsepp
Copy link
Member Author

knedlsepp commented May 22, 2017

@FRidh: I'm not sure what you mean by that. I've been looking how other libraries in nixpkgs that provide python bindings do it and only found opencv and gdal, so I basically copied how it's done in opencv and gdal.

@FRidh
Copy link
Member

FRidh commented May 22, 2017

@knedlsepp see #19631 and #20516 (I know realise they're duplicates).

What I meant is that Python bindings are preferably put in a separate output (see multiple outputs in manual and moveToOuput function) to reduce closure size for programs that do not need the bindings.

This provides a default method for using the grib-api python bindings.
@FRidh
Copy link
Member

FRidh commented May 22, 2017

So, by default we would build with bindings, however, the main output would not contain them. Instead, they're in the package.py derivation/output.

@knedlsepp knedlsepp force-pushed the provide-grib-api-python-bindings branch from 644b83d to 2ff56a1 Compare May 22, 2017 14:42
@knedlsepp
Copy link
Member Author

knedlsepp commented May 22, 2017

@FRidh: I tried to split the output, but now when I try to run:

export NIX_PATH=nixpkgs=<PATH_TO_NIXPKGS_CLONE>
nix-shell -p pythonPackages.grib-api python --run "python -c 'import gribapi'"

I get an import error for numpy, which should be a propagatedBuildInput. How do I deal with that?

@@ -43,6 +47,11 @@ stdenv.mkDerivation rec{
ctest -R "t_definitions|t_calendar|t_unit_tests" -VV
'';

postFixup = stdenv.lib.optionalString enablePython ''
moveToOutput lib/${pythonPackages.python.libPrefix} "$py"
Copy link
Member

@FRidh FRidh May 22, 2017

Choose a reason for hiding this comment

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

I think you can use moveToOutput ${python.sitePackages} "$py"

@FRidh
Copy link
Member

FRidh commented May 22, 2017

As long as you add a numpy store path somewhere, it typically works. Normally, we use nix/propagated-native-build-inputs. We don't have a nice way for it yet, but what you could do is echo ${numpy} to that file.

@knedlsepp
Copy link
Member Author

knedlsepp commented May 22, 2017

I see, that's what is being done in libxml2Python

  libxml2Python = pkgs.buildEnv { # slightly hacky
    name = "libxml2+py-${self.libxml2.version}";
    paths = with libxml2; [ dev bin py ];
    inherit (libxml2) passthru;
    # the hook to find catalogs is hidden by buildEnv
    postBuild = ''
      mkdir "$out/nix-support"
      cp '${libxml2.dev}/nix-support/propagated-native-build-inputs' "$out/nix-support/"
    '';
  };

Honestly I'm a bit hesitant to add all that noise for what would result in a minor saving of disk space. (I just checked: The main library would cosume about 27MB, some tools built upon the lib in bin would consume 6MB and the python bindings are about 0.28MB) I got the feeling that at some point we will want to get rid of this "slightly hacky" solution. Personally at the moment I would rather keep this thing as simple as possible.

@knedlsepp knedlsepp force-pushed the provide-grib-api-python-bindings branch from 8d6b913 to 2ff56a1 Compare May 22, 2017 15:42
@FRidh
Copy link
Member

FRidh commented May 22, 2017

@knedlsepp its up to you to choose as maintainer whether you maintain separate outputs or not. I suppose this package is not used as much as libxml2.

We should definitely find a better way. Because its not possible to modify outputs I think in the long term we might want to take the direction I took for pythonPackages.tkinter, i.e., copying the files from the py output into a new derivation.

@knedlsepp
Copy link
Member Author

@FRidh: Would you consider merging?

@FRidh FRidh merged commit 90d5dd3 into NixOS:master Jun 7, 2017
@knedlsepp knedlsepp deleted the provide-grib-api-python-bindings branch August 28, 2017 08:05
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

3 participants