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

does poetry2nix support {git = ... tag = ...} packages ? #160

Closed
teto opened this issue Aug 26, 2020 · 8 comments
Closed

does poetry2nix support {git = ... tag = ...} packages ? #160

teto opened this issue Aug 26, 2020 · 8 comments

Comments

@teto
Copy link
Contributor

teto commented Aug 26, 2020

with a shell.nix similar to

myPythonEnv = poetry2nix.mkPoetryEnv {
    projectDir = ./.;
  };

I get upon running nix-shell

fatal: impossible de trouver la référence distante refs/heads/v6.3.0
error: --- Error ------------------------------------------------------------------------------------------------------------- nix-shell
program 'git' failed with exit code 128
-------------------------------------------------------------- show-trace --------------------------------------------------------------
trace: while evaluating the attribute 'src.name'

fatal: *can't find remote reference* refs/heads/v6.3.0 (using nixos-unstable c59ea8b8a0e7f927e7291c14ea6cd1bd3a16ff38)

[[package]]
category = "main"
name = "custom-sdk"
optional = false
python-versions = "*"
version = "6.3.0"

[package.dependencies]
pandas = ">=0.25.0"
retrying = ">=1.3.3"
tqdm = ">=4.38.0"

[package.source]
reference = "660a747c9ef2a749c88fd87f4e009dd514352992"
type = "git"
url = "https://REDACTED/custom-sdk.git"

In a local checkout of the git repo, the tags are in .git/refs/tags and not in .git/refs/heads. I am not sure how git handles tags/refs but I am concerned the { git = , tag } pattern in pyproject.toml is not supported yet in poetry2nix ? or is it something else ?

the pyproject.toml contains
custom-sdk = {git = 'https://redacted/custom-sdk.git', tag = 'v6.3.0'}

@adisbladis
Copy link
Member

This should be supported:

ref = sourceSpec.branch or sourceSpec.rev or sourceSpec.tag or "HEAD";
.

Are we somehow constructing the builtins.fetchGit call wrongly?
Could you try to manually call builtins.fetchGit and see what you can get working?

@teto
Copy link
Contributor Author

teto commented Aug 27, 2020

poetry2nix looks for the ref in refs/heads/v6.3.0 when it really is in refs/tags/v6.3.0:

$ git show-ref                                                                                                         
ebcafd9e6337ade03a88cdf36eb59d480c9d60d3 refs/heads/dev
ebcafd9e6337ade03a88cdf36eb59d480c9d60d3 refs/remotes/origin/HEAD
ebcafd9e6337ade03a88cdf36eb59d480c9d60d3 refs/remotes/origin/dev
ebcafd9e6337ade03a88cdf36eb59d480c9d60d3 refs/remotes/origin/master
fe036a257690c825f70c2dc59bd44f96b14c25fc refs/tags/v0.0.2
062019afe37ceafefd6126262650f7446e1bc911 refs/tags/v6.3.0

according to the nix https://nixos.org/nix/manual/ it is possible to call builtins.fetchGit with ref = refs/tags/{tag}".

@teto
Copy link
Contributor Author

teto commented Aug 27, 2020

I've just asked on #git and tags only appear in refs/tags (and eventually .git/packed-refs) so I think poetry2nix code needs to be changed (or builtins.fetchGit should check in refs/tags as well )?

@teto
Copy link
Contributor Author

teto commented Aug 28, 2020

seems like there may be an issue with accessing the git repository itself (behing gitlab tokens https://USER:token@git.domain.net/repo.git), investigating ...

@teto
Copy link
Contributor Author

teto commented Aug 28, 2020

Looks like builtins.fetchGit works fine after all but poetry2nix seems to always set a ref, which may override the rev ? I've switch to using revs instead of tag and that fixed that problem

        if isGit then (
          builtins.trace source.url builtins.fetchGit {
            inherit (source) url;
            rev = source.reference;
            ref = sourceSpec.branch or sourceSpec.rev or sourceSpec.tag or "HEAD";
          }

but then I also hit

trace: aa271cf29b5b128407950bcca51765329f9826c2
fatal: impossible de trouver la référence distante refs/heads/aa271cf29b5b128407950bcca51765329f9826c2
error: --- Error --------------------------------------------------------------------------------------------------------------------------------------------------------------------- nix-shell
program 'git' failed with exit code 128

which corresponds to the poetry.lock

[package.source]
reference = "aa271cf29b5b128407950bcca51765329f9826c2"
type = "git"

weird that it would look in refs/heads for a rev ?!

@teto
Copy link
Contributor Author

teto commented Aug 28, 2020

(sorry for the spam). I've played a bit with the code and this change seems to fix everything (tags and all)

  src =
        if isGit then (

          let
            ref = sourceSpec.branch or sourceSpec.rev or sourceSpec.tag;
          in
          builtins.trace source.url builtins.fetchGit {
            inherit (source) url;
          } // (if source.reference != null then {
            rev = builtins.trace source.reference source.reference;
          } else {
            ref = sourceSpec.branch or sourceSpec.rev or sourceSpec.tag or "HEAD";
          })
        ) else if isLocal then (poetryLib.cleanPythonSources { src = localDepPath; }) else fetchFromPypi {
          pname = name;
          inherit (fileInfo) file hash kind;
        };
    }
  ) { }

@teto
Copy link
Contributor Author

teto commented Aug 31, 2020

@adisbladis agree with the fix (aka use only rev if present and ref otherwise) ? should I send a PR or do you want to fix it yourself ?

teto added a commit to teto/poetry2nix that referenced this issue Aug 31, 2020
teto added a commit to teto/poetry2nix that referenced this issue Sep 2, 2020
teto added a commit to teto/poetry2nix that referenced this issue Sep 8, 2020
@teto
Copy link
Contributor Author

teto commented Oct 26, 2020

not sure what happened but now works.

@teto teto closed this as completed Oct 26, 2020
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

Successfully merging a pull request may close this issue.

2 participants