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

pdm: missing editables module when entering devShell #1000

Closed
abathur opened this issue Jun 26, 2024 · 15 comments
Closed

pdm: missing editables module when entering devShell #1000

abathur opened this issue Jun 26, 2024 · 15 comments

Comments

@abathur
Copy link
Contributor

abathur commented Jun 26, 2024

I couldn't find other reports of this, so maybe I'm just holding it wrong, but after switching to the pdm module I started getting this traceback when I enter a devShell:

Traceback (most recent call last):
  File "/nix/store/kjg1yk7k0fflpzjnnpy745rb0haacii7-editable.py", line 229, in <module>
    make_editable(
  File "/nix/store/kjg1yk7k0fflpzjnnpy745rb0haacii7-editable.py", line 65, in make_editable
    editable_dist_info = make_dist_info(
  File "/nix/store/kjg1yk7k0fflpzjnnpy745rb0haacii7-editable.py", line 112, in make_dist_info
    dist_info_name = backend.prepare_metadata_for_build_editable(tmp_dir)
  File "/nix/store/nq1m0pmqh4yzncm311dj5pn8bzzn05hh-python3-3.9.19-env/lib/python3.9/site-packages/pdm/backend/__init__.py", line 87, in prepare_metadata_for_build_editable
    from pdm.backend.editable import EditableBuilder
  File "/nix/store/nq1m0pmqh4yzncm311dj5pn8bzzn05hh-python3-3.9.19-env/lib/python3.9/site-packages/pdm/backend/editable.py", line 7, in <module>
    from editables import EditableProject
ModuleNotFoundError: No module named 'editables'

I'm able to work around it by adding editables it to the app's python dependencies.

@JonBoyleCoding
Copy link

What do you mean by app's python dependencies - in the pyproject.toml or in the nix derivation somewhere?

@JonBoyleCoding
Copy link

JonBoyleCoding commented Jun 26, 2024

What do you mean by app's python dependencies - in the pyproject.toml or in the nix derivation somewhere?

Never mind - I figured it out (at least for me). Place it in the mkDerivation in the module (in the examples in this repo it would be the default.nix file)

@purepani
Copy link
Contributor

Curious, I've never had that happen before. I'll see if I can debug it later.

@abathur
Copy link
Contributor Author

abathur commented Jun 27, 2024

@JonBoyleCoding Were you just asking me to clarify, or does your response indicate that you've run into the same error?

I really was hoping someone would know what this was and just tell me I was holding it wrong, so we might be able to help run this to ground by finding a minimal repro.

I took a few quick swings at doing so this morning but haven't yet been able to isolate one, and I've got other fires to fight so I may not be able to revisit for a bit.

@JonBoyleCoding
Copy link

@JonBoyleCoding Were you just asking me to clarify, or does your response indicate that you've run into the same error?

I really was hoping someone would know what this was and just tell me I was holding it wrong, so we might be able to help run this to ground by finding a minimal repro.

I took a few quick swings at doing so this morning but haven't yet been able to isolate one, and I've got other fires to fight so I may not be able to revisit for a bit.

I encountered the same error and was asking if you could provide specifics on how you got around it. Thankfully I did manage to get around it for now!

@abathur
Copy link
Contributor Author

abathur commented Jun 27, 2024

Gotcha. I did something a little more targeted, but what you're saying sounds fine for a workaround.

I don't really love some specifics of the Nix half of this and will probably refactor later, but for reference I just added a new optional/dev dependency group to pyproject.toml containing only "editables". This part looks like:

[tool.pdm.dev-dependencies]
# workaround
editables = [
    "editables"
]

Back in flake.nix I appended dependencies from that group to the buildInputs for only the devShell so that editables didn't also leak into the container image. In barebones form, that looked something like:

let 
  get_dev_packages = groups: with groups;
        editables.packages //
        other_group_i_need.packages;
in {
  devShells.default = (pkgs.mkShell rec {
    inputsFrom = [
      packages.blah.devShell
    ];

    buildInputs = with pkgs; [
      # ...
    ] ++ map (x: (pkgs.lib.head (pkgs.lib.attrValues x)).public) (
      pkgs.lib.attrValues (get_dev_packages packages.blah.config.groups)
    );
  });
}

Is your project public, or is it generally fairly small/simple? This may be an easy fix for @purepani if we have a minimal reproduction at hand. My project's private and somewhat large so it'll take me some time to extract something minimal from it.

@purepani
Copy link
Contributor

I ended up getting the error today while working so I can figure it out based on that.

@JonBoyleCoding
Copy link

It will be public in a few days, but not yet. However if you've already got the error then presumably you can go forward with that.

@phaer
Copy link
Member

phaer commented Jun 28, 2024

@purepani Awesome, if you take a look! I could do as well, if you want and push a reproducer :)

@purepani
Copy link
Contributor

I'll take a look after work today!

@purepani
Copy link
Contributor

Looks like this may have been a bug in pdm-backend: pdm-project/pdm-backend#242.
It was fixed in the most recent update from a few weeks ago, so I made a PR in nixpkgs to update the backend: NixOS/nixpkgs#323292 (though I haven't tested it with
@phaer should we wait for this to be merged and hit nixpkgs or fix it here while we wait?

@purepani
Copy link
Contributor

purepani commented Jun 29, 2024

Even better looks like it was already commited into staging 5 days ago: NixOS/nixpkgs#320924

@phaer
Copy link
Member

phaer commented Jun 29, 2024

So we just have to wait until https://nixpk.gs/pr-tracker.html?pr=320924 hits nixpkgs-unstable and update the inputs then :)

@purepani
Copy link
Contributor

Yep exactly
I did test it by adding an overlay to update it, and it did work correctly so just until it gets merged(I wouldnt recommend this since it took a long time to build since it rebuilds a bunch of stuff)

@purepani
Copy link
Contributor

purepani commented Jul 9, 2024

This is now fixed as far as I can tell!

@abathur abathur closed this as completed Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants