nix-community / poetry2nix

Convert poetry projects to nix automagically [maintainer=]
MIT License
892 stars 451 forks source link

Support for build projects that have git dependency? #1846

Open jtara1 opened 1 month ago

jtara1 commented 1 month ago

Describe the issue

If I poetry add git+https://github.com/jtara1/send_mail.git@f4715883cfe4e605b4809b51da8bdf75e774ab32 in a project flake then build this as a nix derivation using poetry2nix, I'm getting an error when trying to build the project flake nixosModules deps.

Running phase: buildPhase
Executing pipBuildPhase
Creating a wheel...
WARNING: The directory '/homeless-shelter/.cache/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you should use sudo's -H flag.
Processing /build/source
  Running command Preparing metadata (pyproject.toml)
  Preparing metadata (pyproject.toml) ... done
ERROR: Exception:
Traceback (most recent call last):
  File "/nix/store/gdrxvb3nca9q5r8r40i1vy7srxx0myhr-python3.11-pip-24.0/lib/python3.11/site-packages/pip/_internal/cli/base_command.py", line 180, in exc_logging_wrapper
    status = run_func(*args)
             ^^^^^^^^^^^^^^^
  File "/nix/store/gdrxvb3nca9q5r8r40i1vy7srxx0myhr-python3.11-pip-24.0/lib/python3.11/site-packages/pip/_internal/cli/req_command.py", line 245, in wrapper
    return func(self, options, args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/gdrxvb3nca9q5r8r40i1vy7srxx0myhr-python3.11-pip-24.0/lib/python3.11/site-packages/pip/_internal/commands/wheel.py", line 147, in run
    requirement_set = resolver.resolve(reqs, check_supported_wheels=True)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/gdrxvb3nca9q5r8r40i1vy7srxx0myhr-python3.11-pip-24.0/lib/python3.11/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 76, in resolve
    collected = self.factory.collect_root_requirements(root_reqs)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/gdrxvb3nca9q5r8r40i1vy7srxx0myhr-python3.11-pip-24.0/lib/python3.11/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 534, in collect_root_requirements
    reqs = list(
           ^^^^^
  File "/nix/store/gdrxvb3nca9q5r8r40i1vy7srxx0myhr-python3.11-pip-24.0/lib/python3.11/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 490, in _make_requirements_from_install_req
    cand = self._make_base_candidate_from_link(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/gdrxvb3nca9q5r8r40i1vy7srxx0myhr-python3.11-pip-24.0/lib/python3.11/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 228, in _make_base_candidate_from_link
    self._link_candidate_cache[link] = LinkCandidate(
                                       ^^^^^^^^^^^^^^
  File "/nix/store/gdrxvb3nca9q5r8r40i1vy7srxx0myhr-python3.11-pip-24.0/lib/python3.11/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 290, in __init__
    super().__init__(
  File "/nix/store/gdrxvb3nca9q5r8r40i1vy7srxx0myhr-python3.11-pip-24.0/lib/python3.11/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 156, in __init__
    self.dist = self._prepare()
                ^^^^^^^^^^^^^^^
  File "/nix/store/gdrxvb3nca9q5r8r40i1vy7srxx0myhr-python3.11-pip-24.0/lib/python3.11/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 222, in _prepare
    dist = self._prepare_distribution()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/gdrxvb3nca9q5r8r40i1vy7srxx0myhr-python3.11-pip-24.0/lib/python3.11/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 301, in _prepare_distribution
    return preparer.prepare_linked_requirement(self._ireq, parallel_builds=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/gdrxvb3nca9q5r8r40i1vy7srxx0myhr-python3.11-pip-24.0/lib/python3.11/site-packages/pip/_internal/operations/prepare.py", line 525, in prepare_linked_requirement
    return self._prepare_linked_requirement(req, parallel_builds)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/gdrxvb3nca9q5r8r40i1vy7srxx0myhr-python3.11-pip-24.0/lib/python3.11/site-packages/pip/_internal/operations/prepare.py", line 640, in _prepare_linked_requirement
    dist = _get_prepared_distribution(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/gdrxvb3nca9q5r8r40i1vy7srxx0myhr-python3.11-pip-24.0/lib/python3.11/site-packages/pip/_internal/operations/prepare.py", line 71, in _get_prepared_distribution
    abstract_dist.prepare_distribution_metadata(
  File "/nix/store/gdrxvb3nca9q5r8r40i1vy7srxx0myhr-python3.11-pip-24.0/lib/python3.11/site-packages/pip/_internal/distributions/sdist.py", line 67, in prepare_distribution_metadata
    self.req.prepare_metadata()
  File "/nix/store/gdrxvb3nca9q5r8r40i1vy7srxx0myhr-python3.11-pip-24.0/lib/python3.11/site-packages/pip/_internal/req/req_install.py", line 579, in prepare_metadata
    self.metadata_directory = generate_metadata(
                              ^^^^^^^^^^^^^^^^^^
  File "/nix/store/gdrxvb3nca9q5r8r40i1vy7srxx0myhr-python3.11-pip-24.0/lib/python3.11/site-packages/pip/_internal/operations/build/metadata.py", line 35, in generate_metadata
    distinfo_dir = backend.prepare_metadata_for_build_wheel(metadata_dir)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/gdrxvb3nca9q5r8r40i1vy7srxx0myhr-python3.11-pip-24.0/lib/python3.11/site-packages/pip/_internal/utils/misc.py", line 766, in prepare_metadata_for_build_wheel
    return super().prepare_metadata_for_build_wheel(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/gdrxvb3nca9q5r8r40i1vy7srxx0myhr-python3.11-pip-24.0/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_impl.py", line 186, in prepare_metadata_for_build_wheel
    return self._call_hook('prepare_metadata_for_build_wheel', {
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/gdrxvb3nca9q5r8r40i1vy7srxx0myhr-python3.11-pip-24.0/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_impl.py", line 321, in _call_hook
    raise BackendUnavailable(data.get('traceback', ''))
pip._vendor.pyproject_hooks._impl.BackendUnavailable: Traceback (most recent call last):
  File "/nix/store/gdrxvb3nca9q5r8r40i1vy7srxx0myhr-python3.11-pip-24.0/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 77, in _build_backend
    obj = import_module(mod_path)
          ^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/h723hb9m43lybmvfxkk6n7j4v664qy7b-python3-3.11.9/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1126, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1126, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1126, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1140, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'poetry'

Is this test case, git dep, covered in this repos tests/?

I had other several other deps like flask, flask-cors, etc that I had poetry added and it was building fine.

jtara1 commented 1 month ago

This issue shouldn't be a problem w/ poetry2nix after trying setuptools and mkDerivation, getting error

error: builder for '/nix/store/idigng0xk0smjcb8c6jpxggyg0b5advn-python3.11-send-mail-1.0.2.drv' failed with exit code 2;
       last 10 log lines:
       >   File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
       >   File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
       >   File "<frozen importlib._bootstrap>", line 1126, in _find_and_load_unlocked
       >   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
       >   File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
       >   File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
       >   File "<frozen importlib._bootstrap>", line 1140, in _find_and_load_unlocked
       > ModuleNotFoundError: No module named 'setuptools'
       > 
       > 
       For full logs, run 'nix log /nix/store/idigng0xk0smjcb8c6jpxggyg0b5advn-python3.11-send-mail-1.0.2.drv'.
vale981 commented 2 weeks ago

Hi :),

adding poetry-core as a build input in an override worked for me (hiroplotutils is the git dependency)

        packages = {
          loopBath = poetry2nix.mkPoetryApplication {
            projectDir = self;
            preferWheels = true;

            overrides = poetry2nix.overrides.withDefaults (final: prev: {
              hiroplotutils = prev.hiroplotutils.overridePythonAttrs
                (
                  old: {
                    buildInputs = (old.buildInputs or [ ]) ++ [ prev.poetry-core ];
                  }
                );
              matplotlib = with pkgs; prev.matplotlib.override (
                {
                  enableGtk3 = true;
                }
              );
            });
          };
          default = self.packages.${system}.loopBath;
        };