Skip to content

Commit 75c5607

Browse files
authored
Switch active Python LSP modules from Pyright to ty (#475)
2 parents 31c79a6 + 8ee4fff commit 75c5607

6 files changed

Lines changed: 118 additions & 16 deletions

File tree

pkgs/modules/default.nix

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ let
5353
python = pkgs.python313;
5454
pypkgs = pkgs.python313Packages;
5555
})
56-
(import ./pyright-extended {
57-
nodejs = pkgs-24_11.nodejs-18_x;
58-
})
59-
(import ./pyright)
56+
(import ./ty)
6057
(import ./ruff)
6158

6259
(import ./nodejs {

pkgs/modules/python-base/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ in
2828
description = ''
2929
Basic module for Python. Includes the interpreter and basic Replit
3030
configuration but nothing else. This may be combined with the
31-
pyright-extended module.
31+
ty module.
3232
'';
3333

3434
replit.packages = [

pkgs/modules/python/default.nix

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{ python, pypkgs }:
22
{ pkgs-unstable
3-
, pkgs-24_11
4-
, pkgs-23_05
53
, lib
64
, ...
75
}:
@@ -60,10 +58,7 @@ let
6058
inherit pkgs python python-ld-library-path;
6159
};
6260

63-
pyright-extended = pkgs.callPackage ../../pyright-extended {
64-
nodejs = pkgs-24_11.nodejs-18_x;
65-
yapf = pypkgs.yapf;
66-
};
61+
ty = pkgs.callPackage ../../ty { };
6762

6863
sitecustomize = pkgs.callPackage ./sitecustomize.nix { };
6964

@@ -85,7 +80,7 @@ in
8580
name = "Python Tools";
8681
displayVersion = pythonVersion;
8782
description = ''
88-
Development tools for Python. Includes Python interpreter, Pip, Poetry, Pyright extended language server.
83+
Development tools for Python. Includes Python interpreter, Pip, Poetry, and the ty language server.
8984
'';
9085

9186
replit.packages = [
@@ -108,11 +103,11 @@ in
108103
];
109104
};
110105

111-
replit.dev.languageServers.pyright-extended = {
112-
name = "pyright-extended";
113-
displayVersion = pyright-extended.version;
106+
replit.dev.languageServers.ty = {
107+
name = "ty";
108+
displayVersion = ty.version;
114109
language = "python3";
115-
start = "${pyright-extended}/bin/langserver.index.js --stdio";
110+
start = "${ty}/bin/ty server";
116111
};
117112

118113
replit.dev.packagers.upmPython = {

pkgs/modules/ty/default.nix

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{ pkgs, ... }:
2+
let
3+
ty = pkgs.callPackage ../../ty { };
4+
in
5+
{
6+
id = "ty";
7+
name = "ty LSP";
8+
displayVersion = ty.version;
9+
description = ''
10+
Ty is an extremely fast Python type checker from Astral with an integrated language server.
11+
'';
12+
replit.dev.languageServers.ty = {
13+
name = "ty";
14+
displayVersion = ty.version;
15+
language = "python3";
16+
start = "${ty}/bin/ty server";
17+
};
18+
19+
replit.env = {
20+
PATH = "${ty}/bin";
21+
};
22+
}

pkgs/ty/default.nix

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{ lib
2+
, stdenv
3+
, rustPlatform
4+
, fetchFromGitHub
5+
, installShellFiles
6+
, buildPackages
7+
, versionCheckHook
8+
, nix-update-script
9+
,
10+
}:
11+
12+
rustPlatform.buildRustPackage (finalAttrs: {
13+
pname = "ty";
14+
version = "0.0.21";
15+
16+
src = fetchFromGitHub {
17+
owner = "astral-sh";
18+
repo = "ty";
19+
tag = finalAttrs.version;
20+
fetchSubmodules = true;
21+
hash = "sha256-/R0nw9V0IhuTxRaZNydvk/xGC5V1gYHQxBkAU/Cjsmw=";
22+
};
23+
24+
postPatch = lib.optionalString stdenv.hostPlatform.isDarwin ''
25+
rm ${finalAttrs.cargoRoot}/crates/ty/tests/file_watching.rs
26+
'';
27+
28+
cargoRoot = "ruff";
29+
buildAndTestSubdir = finalAttrs.cargoRoot;
30+
31+
cargoBuildFlags = [ "--package=ty" ];
32+
33+
cargoHash = "sha256-NaWWX6EAVkEg/KQ+Up0t2fh/24fnTo6i5dDZoOWErjg=";
34+
35+
nativeBuildInputs = [ installShellFiles ];
36+
37+
preCheck = ''
38+
export CARGO_BIN_EXE_ty="$PWD"/target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/ty
39+
'';
40+
41+
cargoTestFlags = [
42+
"--package=ty"
43+
"--package=ty_python_semantic"
44+
"--package=ty_test"
45+
];
46+
47+
checkFlags = [
48+
"--skip=python_environment::ty_environment_and_active_environment"
49+
"--skip=python_environment::ty_environment_and_discovered_venv"
50+
"--skip=python_environment::ty_environment_is_only_environment"
51+
"--skip=python_environment::ty_environment_is_system_not_virtual"
52+
"--skip=mdtest::generics/pep695/functions.md"
53+
];
54+
55+
nativeInstallCheckInputs = [ versionCheckHook ];
56+
doInstallCheck = true;
57+
58+
postInstall = lib.optionalString (stdenv.hostPlatform.emulatorAvailable buildPackages) (
59+
let
60+
emulator = stdenv.hostPlatform.emulator buildPackages;
61+
in
62+
''
63+
installShellCompletion --cmd ty \
64+
--bash <(${emulator} $out/bin/ty generate-shell-completion bash) \
65+
--fish <(${emulator} $out/bin/ty generate-shell-completion fish) \
66+
--zsh <(${emulator} $out/bin/ty generate-shell-completion zsh)
67+
''
68+
);
69+
70+
passthru = {
71+
updateScript = nix-update-script { };
72+
};
73+
74+
meta = {
75+
description = "Extremely fast Python type checker and language server, written in Rust";
76+
homepage = "https://github.com/astral-sh/ty";
77+
changelog = "https://github.com/astral-sh/ty/blob/${finalAttrs.version}/CHANGELOG.md";
78+
license = lib.licenses.mit;
79+
mainProgram = "ty";
80+
maintainers = with lib.maintainers; [
81+
bengsparks
82+
figsoda
83+
GaetanLepage
84+
];
85+
};
86+
})

pkgs/upgrade-map/default.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ let
2525
"go" = "go-1.19";
2626
"go-1.23" = "go-1.24";
2727
"go-1.24" = "go-1.25";
28+
"pyright" = "ty";
29+
"pyright-extended" = "ty";
2830
"r-4.3" = "r-4.4";
2931
"r-4.4" = "r-4.5";
3032
"rust" = "rust-1.69";

0 commit comments

Comments
 (0)