seppeljordan / pypi2nix

package python modules for nix
0 stars 0 forks source link

Issue building a requirements.nix for a package that has only wheels available for its latest version. #2

Open ilyaGotfryd opened 4 years ago

ilyaGotfryd commented 4 years ago

I am building a requirements.nix the latest version (v1.1.1) of https://pypi.org/project/asyncnsq/ to use in my project however since the last package that contains tar.gz package is version 0.4.5 I can only see packages up to that version.

curl https://pypi.org/simple/asyncnsq/

for details.

seppeljordan commented 4 years ago

Hi, yes. With the current process this is unavoidable. pypi2nix assumes that we cannot trust any wheels that are prebuilt. You can circumvent this by building directly from the upstream source code repository. Try adding the following to your requirements.txt

git+https://github.com/aohan237/asyncnsq.git@1.1.0#egg=ayncnsq

Haven't tested this though. Let me know if this worked out for you. Also you could create an issue on their site asking them to upload tar archives to pypi.

ilyaGotfryd commented 4 years ago

I was actually working against v1.1.0 and ended up modifying the requirements.nix derivation output as follows:

"asyncnsq" = python.mkDerivation {
      format = "wheel";
      name = "asyncnsq-1.1.0";
      src = pkgs.fetchurl {
        url = "https://files.pythonhosted.org/packages/2d/85/873d884cb15cc12b1774ee52b35b52ad3dfd61ea17404f9017e8c26cafb7/asyncnsq-1.1.0-py3-none-any.whl";
        sha256 = "f59d6a54036ae2aae63ee448af1d44b1d9815be2577a985ba7e44a3b79cd9702";
      };
      doCheck = commonDoCheck;
      buildInputs = commonBuildInputs ++ [ ];
      propagatedBuildInputs = [
        self."python-snappy"
      ];
      meta = with pkgs.stdenv.lib; {
        homepage = "https://github.com/aohan237/asyncnsq";
        license = licenses.mit;
        description = "asyncio async/await nsq support";
      };
    };

I copied wheel URL and sha256 by hand and added format="wheel"; to derivation and it worked in my package. Is it not reasonable to permit prefetching wheel directly if one is available?

seppeljordan commented 4 years ago

What you are proposing could work out, but for that I'd have to implement a mechanism to detect if the wheel available is suitable for the current platform. Also this would mean that derivations produced on one system can not be used on a different platform, e.g. arm vs intel, linux vs windows.

ilyaGotfryd commented 4 years ago

So workflow would potentially be Wheel if one is available for the platform, otherwise, look for a tarball of that version and build else fail if an unreachable version for that platform is requested? Is it something that pip already taking care of internally? Also if you are interested in addressing this where would be the correct insertion point for this logic? I was looking for something to possibly work on for Hacktober.

seppeljordan commented 4 years ago

Hi, I would be grateful support on developing this and will gladly help you as far as I can. But I am not super eager to introduce this into the code base. Here is some thoughts that I had on fetching wheels:

That said, if you want to explore the this issue in the code, let me point you to a couple of source files:

ilyaGotfryd commented 4 years ago

Thank you for the write-up. This is a very helpful insight. I have done Python for a few years, but I am absolutely new to NixOS so I have barely any exposure to the underlying philosophy. In light of what you wrote, I wonder if I could take the following stance in implementation.

This way pypi2nix remains true to form, however, allows for exceptions. I am not sure if I am misreading the Python community intentions, but it appears to me that wheel is the way of the future.

seppeljordan commented 4 years ago

Hi, I agree with all your 4 points except the third one. You are right in that we should let the user know that there are newer versions than the downloaded one but throwing an error seems a little extreme. I suggest that the standard behavior can be a warning just before pypi2nix finished execution. Also exclude pre versions since most larger software projects publish pre-releases. Maybe we could have a flags called --allow-old-source-distribution/--no-allow-old-source-distribution where --allow-old-souce-distribution is the default. I guess implementing a warning for the user about old source distributions could be done with reasonable effort right now.

seppeljordan commented 4 years ago

BTW: The primary repository of this program is here.

ilyaGotfryd commented 4 years ago

Is there a way to move that issue there? I was trying to find an answer to my question and ended up in this repo. 🤓

seppeljordan commented 4 years ago

Unfortunately I cannot move this issue to another user.