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

broken pre-commit hook in v1.13.0 #430

Closed
jorenham opened this issue Jun 19, 2024 · 15 comments · Fixed by #440
Closed

broken pre-commit hook in v1.13.0 #430

jorenham opened this issue Jun 19, 2024 · 15 comments · Fixed by #440

Comments

@jorenham
Copy link
Contributor

It appears to be related to the docify dependency, specifically that it

[...] does not appear to be a Python project: neither 'setup.py' nor 'pyproject.toml' found.


.pre-commit-config.yaml

repos:
  - repo: https://github.com/DetachHead/basedpyright
    rev: v1.13.0
    hooks:
      - id: basedpyright

command:

pre-commit run --all-files

output:

[INFO] Installing environment for https://github.com/DetachHead/basedpyright.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('~/.cache/pre-commit/repo1wwiq2m7/py_env-python3.12/bin/python', '-mpip', 'install', '.')
return code: 1
stdout:
    Processing ~/.cache/pre-commit/repo1wwiq2m7
      Installing build dependencies: started
      Installing build dependencies: finished with status 'error'
stderr:
      error: subprocess-exited-with-error
      
      × pip subprocess to install build dependencies did not run successfully.
      │ exit code: 1
      ╰─> [7 lines of output]
          Collecting docify@ git+https://github.com/AThePeanut4/docify@8896d7f4f3543b4f48ef8ebdec3b96250d5d1900
            Cloning https://github.com/AThePeanut4/docify (to revision 8896d7f4f3543b4f48ef8ebdec3b96250d5d1900) to /tmp/pip-install-j9rai9n9/docify_41b61fc0ad1345dfb369ea3dcad90429
            Running command git clone --filter=blob:none --quiet https://github.com/AThePeanut4/docify /tmp/pip-install-j9rai9n9/docify_41b61fc0ad1345dfb369ea3dcad90429
            Running command git rev-parse -q --verify 'sha^8896d7f4f3543b4f48ef8ebdec3b96250d5d1900'
            Running command git fetch -q https://github.com/AThePeanut4/docify 8896d7f4f3543b4f48ef8ebdec3b96250d5d1900
            Resolved https://github.com/AThePeanut4/docify to commit 8896d7f4f3543b4f48ef8ebdec3b96250d5d1900
          ERROR: docify@ git+https://github.com/AThePeanut4/docify@8896d7f4f3543b4f48ef8ebdec3b96250d5d1900 from git+https://github.com/AThePeanut4/docify@8896d7f4f3543b4f48ef8ebdec3b96250d5d1900 does not appear to be a Python project: neither 'setup.py' nor 'pyproject.toml' found.
          [end of output]
      
      note: This error originates from a subprocess, and is likely not a problem with pip.
    error: subprocess-exited-with-error
    
    × pip subprocess to install build dependencies did not run successfully.
    │ exit code: 1
    ╰─> See above for output.
    
    note: This error originates from a subprocess, and is likely not a problem with pip.
Check the log at ~/.cache/pre-commit/pre-commit.log

contents of ~/.cache/pre-commit/pre-commit.log:

### version information

```
pre-commit version: 3.7.1
git --version: git version 2.34.1
sys.version:
    3.12.4 (main, Jun 11 2024, 23:44:10) [GCC 11.4.0]
sys.executable: ~/Workspace/optype/.venv/bin/python
os.name: posix
sys.platform: linux
```

### error information

```
An unexpected error has occurred: CalledProcessError: command: ('~/.cache/pre-commit/repo1wwiq2m7/py_env-python3.12/bin/python', '-mpip', 'install', '.')
return code: 1
stdout:
    Processing ~/.cache/pre-commit/repo1wwiq2m7
      Installing build dependencies: started
      Installing build dependencies: finished with status 'error'
stderr:
      error: subprocess-exited-with-error
      
      × pip subprocess to install build dependencies did not run successfully.
      │ exit code: 1
      ╰─> [7 lines of output]
          Collecting docify@ git+https://github.com/AThePeanut4/docify@8896d7f4f3543b4f48ef8ebdec3b96250d5d1900
            Cloning https://github.com/AThePeanut4/docify (to revision 8896d7f4f3543b4f48ef8ebdec3b96250d5d1900) to /tmp/pip-install-j9rai9n9/docify_41b61fc0ad1345dfb369ea3dcad90429
            Running command git clone --filter=blob:none --quiet https://github.com/AThePeanut4/docify /tmp/pip-install-j9rai9n9/docify_41b61fc0ad1345dfb369ea3dcad90429
            Running command git rev-parse -q --verify 'sha^8896d7f4f3543b4f48ef8ebdec3b96250d5d1900'
            Running command git fetch -q https://github.com/AThePeanut4/docify 8896d7f4f3543b4f48ef8ebdec3b96250d5d1900
            Resolved https://github.com/AThePeanut4/docify to commit 8896d7f4f3543b4f48ef8ebdec3b96250d5d1900
          ERROR: docify@ git+https://github.com/AThePeanut4/docify@8896d7f4f3543b4f48ef8ebdec3b96250d5d1900 from git+https://github.com/AThePeanut4/docify@8896d7f4f3543b4f48ef8ebdec3b96250d5d1900 does not appear to be a Python project: neither 'setup.py' nor 'pyproject.toml' found.
          [end of output]
      
      note: This error originates from a subprocess, and is likely not a problem with pip.
    error: subprocess-exited-with-error
    
    × pip subprocess to install build dependencies did not run successfully.
    │ exit code: 1
    ╰─> See above for output.
    
    note: This error originates from a subprocess, and is likely not a problem with pip.
```

```
Traceback (most recent call last):
  File "~/Workspace/optype/.venv/lib/python3.12/site-packages/pre_commit/error_handler.py", line 73, in error_handler
    yield
  File "~/Workspace/optype/.venv/lib/python3.12/site-packages/pre_commit/main.py", line 417, in main
    return run(args.config, store, args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/Workspace/optype/.venv/lib/python3.12/site-packages/pre_commit/commands/run.py", line 442, in run
    install_hook_envs(to_install, store)
  File "~/Workspace/optype/.venv/lib/python3.12/site-packages/pre_commit/repository.py", line 238, in install_hook_envs
    _hook_install(hook)
  File "~/Workspace/optype/.venv/lib/python3.12/site-packages/pre_commit/repository.py", line 94, in _hook_install
    lang.install_environment(
  File "~/Workspace/optype/.venv/lib/python3.12/site-packages/pre_commit/languages/python.py", line 214, in install_environment
    lang_base.setup_cmd(prefix, install_cmd)
  File "~/Workspace/optype/.venv/lib/python3.12/site-packages/pre_commit/lang_base.py", line 86, in setup_cmd
    cmd_output_b(*cmd, cwd=prefix.prefix_dir, **kwargs)
  File "~/Workspace/optype/.venv/lib/python3.12/site-packages/pre_commit/util.py", line 111, in cmd_output_b
    raise CalledProcessError(returncode, cmd, stdout_b, stderr_b)
pre_commit.util.CalledProcessError: command: ('~/.cache/pre-commit/repo1wwiq2m7/py_env-python3.12/bin/python', '-mpip', 'install', '.')
return code: 1
stdout:
    Processing ~/.cache/pre-commit/repo1wwiq2m7
      Installing build dependencies: started
      Installing build dependencies: finished with status 'error'
stderr:
      error: subprocess-exited-with-error
      
      × pip subprocess to install build dependencies did not run successfully.
      │ exit code: 1
      ╰─> [7 lines of output]
          Collecting docify@ git+https://github.com/AThePeanut4/docify@8896d7f4f3543b4f48ef8ebdec3b96250d5d1900
            Cloning https://github.com/AThePeanut4/docify (to revision 8896d7f4f3543b4f48ef8ebdec3b96250d5d1900) to /tmp/pip-install-j9rai9n9/docify_41b61fc0ad1345dfb369ea3dcad90429
            Running command git clone --filter=blob:none --quiet https://github.com/AThePeanut4/docify /tmp/pip-install-j9rai9n9/docify_41b61fc0ad1345dfb369ea3dcad90429
            Running command git rev-parse -q --verify 'sha^8896d7f4f3543b4f48ef8ebdec3b96250d5d1900'
            Running command git fetch -q https://github.com/AThePeanut4/docify 8896d7f4f3543b4f48ef8ebdec3b96250d5d1900
            Resolved https://github.com/AThePeanut4/docify to commit 8896d7f4f3543b4f48ef8ebdec3b96250d5d1900
          ERROR: docify@ git+https://github.com/AThePeanut4/docify@8896d7f4f3543b4f48ef8ebdec3b96250d5d1900 from git+https://github.com/AThePeanut4/docify@8896d7f4f3543b4f48ef8ebdec3b96250d5d1900 does not appear to be a Python project: neither 'setup.py' nor 'pyproject.toml' found.
          [end of output]
      
      note: This error originates from a subprocess, and is likely not a problem with pip.
    error: subprocess-exited-with-error
    
    × pip subprocess to install build dependencies did not run successfully.
    │ exit code: 1
    ╰─> See above for output.
    
    note: This error originates from a subprocess, and is likely not a problem with pip.
```
@jorenham
Copy link
Contributor Author

I don't quite understand why it fails within pre-commit, but succeeds when I pip install . a local clone of basedpyright within a fresh venv 🤔

@DetachHead
Copy link
Owner

ideally it should just use the wheel from pypi instead of trying to build it. maybe @KotlinIsland could take a look as he's more familiar with pre-commit than me

jorenham added a commit to jorenham/optype that referenced this issue Jun 19, 2024
@jorenham
Copy link
Contributor Author

As I mentioned in AThePeanut4/docify#3, I believe that adding a valid pyproject.toml to docify would be enough in this case.
But I agree that a PyPI dependency would be best.

@KotlinIsland
Copy link
Collaborator

I'm seeing this, not sure what anything here means 😅

uv pip install git+https://github.com/AThePeanut4/docify@8896d7f4f3543b4f48ef8ebdec3b96250d5d1900
 Updated https://github.com/AThePeanut4/docify (8896d7f)
error: Failed to build: `git+https://github.com/AThePeanut4/docify@8896d7f4f3543b4f48ef8ebdec3b96250d5d1900`
  Caused by: Invalid source distribution: The archive contains neither a `pyproject.toml` nor a `setup.py` file at the top level

@DetachHead
Copy link
Owner

it shouldnt need to install docify at all because it shouldn't be trying to build the package itself. is there a way to make pre-commit install it from pypi instead?

@jorenham
Copy link
Contributor Author

In the pre-commit docs it says

The installed package will provide an executable that will match the entry – usually through console_scripts or scripts in setup.py.

So if I understand correctly, after it does a pip install ., it manually looks in the pyproject.toml for a script that matches the hook.

So that must be where it attempts to install docify. No idea why though...

@KotlinIsland
Copy link
Collaborator

I don't think that's what it means, I think it means that within the environment, there must be an executable with the name of the 'entry', in this case basedpyright.

@KotlinIsland
Copy link
Collaborator

I think that pre-commit always installs the repo at the url and doesn't use pypi, we could refactor to a config that uses a local instead?

pre-commit is not a very good tool, I don't know why it's considered industry standard...

@KotlinIsland
Copy link
Collaborator

Maybe this?

  - name: basedpyright
  - description: 'pyright fork with various type checking improvements, improved vscode support and pylance features built into the language server'
  - entry: basedpyright
  - language: local
  - 'types_or': [ python, pyi ]
  - require_serial: true
  - additional_dependencies: [ basedpyright==1.13.0 ]
  - minimum_pre_commit_version: '2.9.2'

@KotlinIsland
Copy link
Collaborator

ergh, I think we would need to do something like this https://github.com/psf/black-pre-commit-mirror/blob/main/.pre-commit-hooks.yaml

Create a new repo that just installs basedpyright...

@jorenham
Copy link
Contributor Author

At least a repo like that doesn't seem like it's a lot of effort to create or maintain 🤷🏻

@DetachHead
Copy link
Owner

just forked the black mirror. wanna check if this works? https://github.com/DetachHead/basedpyright-pre-commit-mirror

@jorenham
Copy link
Contributor Author

@DetachHead I checked it, but this is what I get:

[INFO] Initializing environment for https://github.com/DetachHead/basedpyright-pre-commit-mirror.
An unexpected error has occurred: CalledProcessError: command: ('/usr/bin/git', 'checkout', 'v1.13.0')
return code: 1
stdout: (none)
stderr:
    error: pathspec 'v1.13.0' did not match any file(s) known to git

@DetachHead
Copy link
Owner

sorry, forgot to push a tag. try again now

@jorenham
Copy link
Contributor Author

@DetachHead yes it works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants