Guidance on installing python packages in "development mode"

Hi folks,

I’m working on a project, for which one of the Python deps I’m using is “broken”, hence I’m trying to setup a shell.nix file that installs this particular package in development mode, so that I can take a crack at fixing any bugs that I encounter.

The shell.nix file I’m trying to use for this is:

{ pkgs ? import <nixpkgs> { } }:

pkgs.python3Packages.buildPythonPackage rec {
  pname = "oceanwaves";
  version = "1.0.0rc6";
  src = ../../../../../../Source/oceanwaves-python;
  doCheck = false;

  propagatedBuildInputs = with pkgs.python3Packages;
    [ docopt numpy scipy xarray

Only the first line of propagatedBuildInputs is required by the package at install time, the rest are just other things I need for this particular project.

Whenever I drop into a nix-shell env though, it looks like many of these things (including oceanwaves, the package I’m trying to edit) aren’t actually getting installed. For example, ipython is unavailable, and neither is oceanwaves:

Python 3.8.9 (default, Apr  2 2021, 11:20:07) 
[GCC 10.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import oceanwaves
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'oceanwaves'

Wondering if anybody has some wisdom on what I’m doing wrong here.

It might be that you’re invoking your system python. Try doing something like:

{ pkgs ? import <nixpkgs> {} }:

pkgs.mkShell {
  buildInputs = [
    (pkgs.writeScriptBin "hello" ''
      echo hello

Replacing writeScriptBin with buildPythonPackage.

Note I’ve never tried this with a custom python package so I can’t say with certainty that it will work, though if it doesn’t what I’d personally then do is checkout a new worktree of nixpkgs, adding it there as a proper package, and replace import <nixpkgs> with import /path/to/nixpkgs/worktree.

Please take a look at: nixpkgs/ at f2f583eceb7b6ab9a7f0c9b14dfaac9d0b059a10 · NixOS/nixpkgs · GitHub

Sounds like exactly your use case. I did the same thing when working at a previous job.