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

How to use the toPythonModule function with NUR? #114

Closed
smaret opened this Issue Feb 5, 2019 · 7 comments

Comments

Projects
None yet
3 participants
@smaret
Copy link
Contributor

smaret commented Feb 5, 2019

I've posted this question on discourse originally, but it did not receive much attention.

I would like to package an application (astrochem) that has Python bindings in NUR. In the nixpkgs tree, I would add the following line to python-packages.nix:

astrochem = toPythonModule (pkgs.astrochem.override { pythonPackages = self; });

I've tried something similar in in the default.nix of a nur-packages-templates fork:

astrochem = pkgs.pythonPackages.toPythonModule ((pkgs.callPackage ./pkgs/astrochem {pythonPackages = self; }).override { }); 

but then I get the following error:

nix-build -I . -A python27Packages.astrochem
error: undefined variable 'self' at /Users/smaret/Documents/Software/nur-packages/default.nix:18:103

How can I use the toPythonModule function in NUR?

@Mic92

This comment has been minimized.

Copy link
Contributor

Mic92 commented Feb 5, 2019

Does this work?

astrochem = pkgs.pythonPackages.toPythonModule (
  (pkgs.callPackage ./pkgs/astrochem { inherit (pkgs) pythonPackages; }).override { }
); 
@Mic92

This comment has been minimized.

Copy link
Contributor

Mic92 commented Feb 5, 2019

Make sure to use the same pythonPackages version as astrochem.

@Moredread

This comment has been minimized.

Copy link
Contributor

Moredread commented Feb 5, 2019

@Mic92 On that note, can you get the pythonPackages used from the package attrset, i.e. via astrochem.?

@Mic92

This comment has been minimized.

Copy link
Contributor

Mic92 commented Feb 5, 2019

@Moredread I found:

nix-repl> python3.pkgs.mypy.pythonModule.pkgs

I think this one should also work if you don't plan to override any python package:

astrochem = pkgs.pythonPackages.toPythonModule (
  (pkgs.callPackage ./pkgs/astrochem { }).override { }
); 
@smaret

This comment has been minimized.

Copy link
Contributor Author

smaret commented Feb 6, 2019

Does this work?

astrochem = pkgs.pythonPackages.toPythonModule (
  (pkgs.callPackage ./pkgs/astrochem { inherit (pkgs) pythonPackages; }).override { }
); 

It does, in the sense that I can build astrochem from the nur-packages-templates fork:

% nix-build -I. -A astrochem
/nix/store/jhfcqypfc1z4ghcnwzpw3mdi3c6xymwp-astrochem

However, I don't know how to start a nix shell with the astrochem Python module to test it. With nixpkgs, I do the following:

% nix-shell -p python27Packages.astrochem --run python2
Python 2.7.15 (default, Jan  6 2019, 04:12:31)
[GCC 4.2.1 Compatible Clang 5.0.2 (tags/RELEASE_502/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import astrochem
>>>

I've tried something similar in the nur-packages-templates fork but it does not work:

% nix-shell -A astrochem --run python2
Python 2.7.15 (default, Jan  6 2019, 04:12:31) 
[GCC 4.2.1 Compatible Clang 5.0.2 (tags/RELEASE_502/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import astrochem
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named astrochem
@Mic92

This comment has been minimized.

Copy link
Contributor

Mic92 commented Feb 7, 2019

nix-shell -A astrochem --run python2 is not quite what you want.
This gives only the dependency closure of astrochem but not the package itself.
You need a package that has astrochem in its propagatedBuildInputs
You can also write a shell.nix and put astrochem in.
It is now possible to refer to your local repository in NUR,
so you can check changes before pushing like this: https://github.com/nix-community/NUR#overriding-repositories

@smaret

This comment has been minimized.

Copy link
Contributor Author

smaret commented Feb 7, 2019

OK, thanks for your help.

@smaret smaret closed this Feb 7, 2019

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