-
Notifications
You must be signed in to change notification settings - Fork 166
pyright: init #504
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
Open
otavio
wants to merge
1
commit into
numtide:main
Choose a base branch
from
otavio:pyright-init
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+118
−0
Open
pyright: init #504
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| { | ||
| lib, | ||
| pkgs, | ||
| config, | ||
| ... | ||
| }: | ||
| let | ||
| escapePath = lib.replaceStrings [ "/" "." ] [ "-" "" ]; | ||
| in | ||
| { | ||
| meta.maintainers = [ "otavio" ]; | ||
| # Example contains store paths | ||
|
otavio marked this conversation as resolved.
|
||
| meta.skipExample = true; | ||
|
otavio marked this conversation as resolved.
|
||
|
|
||
| options.programs.pyright = { | ||
| enable = lib.mkEnableOption "pyright"; | ||
| package = lib.mkPackageOption pkgs "pyright" { }; | ||
| directories = lib.mkOption { | ||
| description = '' | ||
| Directories to run pyright in. | ||
|
|
||
| Pyright auto-discovers `pyrightconfig.json` or `pyproject.toml` | ||
| (`[tool.pyright]`) starting from the directory it is invoked in. | ||
| Use `extraPaths` in that config to add module search paths — | ||
| pyright does not read the `PYTHONPATH` environment variable. | ||
| ''; | ||
| type = lib.types.attrsOf ( | ||
| lib.types.submodule ( | ||
| { name, ... }: | ||
| { | ||
| options = { | ||
| directory = lib.mkOption { | ||
| type = lib.types.str; | ||
| default = name; | ||
| description = '' | ||
| Directory to run pyright in, relative to the project root. | ||
| The empty string means the project root itself — no `cd` | ||
| is performed. | ||
| ''; | ||
| }; | ||
| options = lib.mkOption { | ||
| type = lib.types.listOf lib.types.str; | ||
| default = [ ]; | ||
| example = [ "--warnings" ]; | ||
| description = "Options to pass to pyright"; | ||
| }; | ||
| modules = lib.mkOption { | ||
| type = lib.types.listOf lib.types.str; | ||
| default = [ "" ]; | ||
| example = [ | ||
| "mymodule" | ||
| "tests" | ||
| ]; | ||
| description = "Modules to check (passed as positional file/directory arguments)"; | ||
| }; | ||
| }; | ||
| } | ||
| ) | ||
| ); | ||
| default = { | ||
| "" = { }; | ||
| }; | ||
| example = { | ||
| "" = { | ||
| modules = [ | ||
| "mymodule" | ||
| "tests" | ||
| ]; | ||
| }; | ||
| "subdir" = { }; | ||
| }; | ||
| }; | ||
| }; | ||
|
|
||
| config = lib.mkIf config.programs.pyright.enable { | ||
| settings.formatter = lib.mapAttrs' ( | ||
| name: cfg: | ||
| let | ||
| nonEmptyModules = lib.filter (m: m != "") cfg.modules; | ||
|
otavio marked this conversation as resolved.
|
||
| cdLine = lib.optionalString (cfg.directory != "") "cd ${lib.escapeShellArg cfg.directory}"; | ||
|
otavio marked this conversation as resolved.
|
||
| args = lib.escapeShellArgs (cfg.options ++ nonEmptyModules); | ||
| in | ||
| lib.nameValuePair "pyright${lib.optionalString (name != "") "-${escapePath name}"}" { | ||
|
otavio marked this conversation as resolved.
|
||
| command = pkgs.bash; | ||
| # Pyright resolves imports from a whole-module context, not per file, | ||
| # so the wrapper ignores the file path treefmt passes as `$0` and always | ||
| # invokes pyright on the configured `modules` (or the whole `directory` | ||
| # when `modules` is empty). With treefmt's batch-size limit this means | ||
| # pyright may be invoked more than once per directory on large file sets | ||
| # — each call redundantly type-checks the same modules. | ||
| # | ||
| # `treefmt --stdin` is not supported: pyright type-checks the on-disk | ||
| # modules regardless of what is piped in, so editor integrations should | ||
| # use pyright's language server directly. A clean opt-out will become | ||
| # possible once treefmt's Stdin Specification lands | ||
| # (numtide/treefmt#586). | ||
| options = [ | ||
| "-eucx" | ||
| '' | ||
| ${cdLine} | ||
| exec ${lib.getExe config.programs.pyright.package} ${args} | ||
| '' | ||
| ]; | ||
| includes = lib.concatMap ( | ||
|
otavio marked this conversation as resolved.
|
||
| module: | ||
| let | ||
| prefix = lib.optional (cfg.directory != "") cfg.directory ++ lib.optional (module != "") module; | ||
| in | ||
| [ | ||
| (lib.concatStringsSep "/" (prefix ++ [ "*.py" ])) | ||
|
otavio marked this conversation as resolved.
|
||
| (lib.concatStringsSep "/" (prefix ++ [ "*.pyi" ])) | ||
| ] | ||
| ) cfg.modules; | ||
| } | ||
| ) config.programs.pyright.directories; | ||
| }; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.