Skip to content

Pyright git hook fails to use languages.python.uv virtual environment #1966

Closed
@Ten0

Description

@Ten0

With the following configuration

  languages.python = {
    enable = true;
    directory = "./mypythonproject";
    version = "3.11.10";
    uv = {
      enable = true;
      sync.enable = true;
    };
  };

  packages = with pkgs; [
    pyright
  ];

  git-hooks.hooks.pyright = {
    enable = true;
    package = pkgs.pyright; # For consistency with packages above
    args = [ "--warnings" ]; # Make it fail if warnings are present
  };

pyright will not run in the virtual environment that uv created, leading to it not detecting packages that would otherwise be available, so it can't properly typecheck.

e.g.
with pyproject.toml

[project]
	dependencies = [
		"requests>=2.28.2",
	]
	description = "Add your description here"
	name = "myproject"
	readme = "README.md"
	requires-python = "==3.11.10"
	version = "0.0.0"

python code:

import requests

we get:

warning: Import "requests" could not be resolved from source (reportMissingModuleSource)
0 errors, 1 warning, 0 informations

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions