NINAnor / python-template

1 stars 0 forks source link

Not compatible with pip 21.3 #19

Closed ghost closed 3 months ago

ghost commented 3 months ago

I get an error when using the template using Python 3.12.4

ERROR: File "setup.py" not found. Directory cannot be installed in editable mode: /home/taheera.ahmed/code/my-awesome-python-project
(A "pyproject.toml" file was found, but editable mode currently requires a setup.py based build.)
Traceback (most recent call last):
  File "nina-python-init.py", line 122, in <module>
    install_dependencies(output=output)
  File "nina-python-init.py", line 101, in install_dependencies
    subprocess.check_call(
  File "/usr/lib/python3.8/subprocess.py", line 364, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/home/taheera.ahmed/code/my-awesome-python-project/.venv/bin/python3', '-m', 'pip', 'install', '-e', '.[tools]']' returned non-zero exit status 1.
Traceback (most recent call last):
  File "/home/taheera.ahmed/.local/bin/copier", line 8, in <module>
    sys.exit(copier_app_run())
  File "/home/taheera.ahmed/.local/pipx/venvs/copier/lib/python3.8/site-packages/plumbum/cli/application.py", line 638, in run
    inst, retcode = subapp.run(argv, exit=False)
  File "/home/taheera.ahmed/.local/pipx/venvs/copier/lib/python3.8/site-packages/plumbum/cli/application.py", line 633, in run
    retcode = inst.main(*tailargs)
  File "/home/taheera.ahmed/.local/pipx/venvs/copier/lib/python3.8/site-packages/copier/cli.py", line 281, in main
    return _handle_exceptions(inner)
  File "/home/taheera.ahmed/.local/pipx/venvs/copier/lib/python3.8/site-packages/copier/cli.py", line 70, in _handle_exceptions
    method()
  File "/home/taheera.ahmed/.local/pipx/venvs/copier/lib/python3.8/site-packages/copier/cli.py", line 279, in inner
    worker.run_copy()
  File "/home/taheera.ahmed/.local/pipx/venvs/copier/lib/python3.8/site-packages/copier/main.py", line 228, in __exit__
    raise value
  File "/home/taheera.ahmed/.local/pipx/venvs/copier/lib/python3.8/site-packages/copier/cli.py", line 279, in inner
    worker.run_copy()
  File "/home/taheera.ahmed/.local/pipx/venvs/copier/lib/python3.8/site-packages/copier/main.py", line 832, in run_copy
    self._execute_tasks(self.template.tasks)
  File "/home/taheera.ahmed/.local/pipx/venvs/copier/lib/python3.8/site-packages/copier/main.py", line 323, in _execute_tasks
    subprocess.run(task_cmd, shell=use_shell, check=True, env=local.env)
  File "/usr/lib/python3.8/subprocess.py", line 516, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '. .venv/bin/activate && python3 nina-python-init.py main python  && rm nina-python-init.py' returned non-zero exit status 1.
frafra commented 3 months ago

Thanks Taheera :) It does not seem to be linked to a specific version of Python, actually.

This is how I checked it (just for reference):

$ for v in {9..13}; do nix-shell --pure -p copier -p python3$v --run 'copier copy --trust gh:ninanor/python-template /tmp/test --defaults' >&/dev/null && echo "Python 3.$v good" || echo "Python 3.$v bad"; rm -rf /tmp/test; done
Python 3.9 good
Python 3.10 good
Python 3.11 good
Python 3.12 good
Python 3.13 good

I found some comments on the web that this issue could be related to setuptools or pip. It turns out that this comment about the pip version being too old is correct.

I made a nix shell template named shell.nix.envsubst:

{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
    nativeBuildInputs = with pkgs.buildPackages;
    let
      custom = import (builtins.fetchTarball https://github.com/nixos/nixpkgs/tarball/$rev) {};
    in
    [
      copier
      cacert
      custom.python39Packages.pip
    ];
}

Then I made a small script to check different versions of pip based on older snapshots of NIX, specifically:

Here is the script:

#!/bin/bash

for r in bf7d05e64d1172ad9356b87bc8c2a643f600e1f0 c2828e8479f84baaf176d0986164231e408d6e1a
do
  rev=$r envsubst < shell.nix.envsubst > shell.nix
  nix-shell --pure --run 'copier copy --trust gh:ninanor/python-template /tmp/test --defaults' &>/dev/null &&
    echo "Revision $r good" ||
    echo "Revision $r bad"
  rm -rf /tmp/test
done

Here is the result:

Revision bf7d05e64d1172ad9356b87bc8c2a643f600e1f0 bad
Revision c2828e8479f84baaf176d0986164231e408d6e1a good

So, your version of pip is too old. I think that we should not try to fix at the code level and just target more recent versions of Python and pip.

frafra commented 3 months ago

Solution: upgrade to a newer version of pip :) For example:

pip install pip

Or, as a user:

pip install --user pip --ignore-installed pip