DetachHead / basedpyright

pyright fork with various type checking improvements, improved vscode support and pylance features built into the language server
http://docs.basedpyright.com/
Other
600 stars 12 forks source link

broken pre-commit hook in v1.13.0 #430

Closed jorenham closed 1 week ago

jorenham commented 2 weeks ago

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 commented 2 weeks ago

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 commented 2 weeks ago

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 commented 2 weeks ago

As I mentioned in https://github.com/AThePeanut4/docify/issues/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 commented 2 weeks ago

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 commented 2 weeks ago

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 commented 2 weeks ago

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 commented 2 weeks ago

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 commented 2 weeks ago

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 commented 2 weeks ago

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 commented 2 weeks ago

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 commented 1 week ago

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

DetachHead commented 1 week ago

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

jorenham commented 1 week ago

@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 commented 1 week ago

sorry, forgot to push a tag. try again now

jorenham commented 1 week ago

@DetachHead yes it works!