Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions pkgs/modules/python/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ let
inherit pkgs python python-ld-library-path;
};

ty = pkgs.callPackage ../../ty { };

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

uv = pkgs.callPackage ./uv {
Expand All @@ -79,8 +77,9 @@ in
id = "python-${pythonVersion}";
name = "Python Tools";
displayVersion = pythonVersion;
imports = [ (import ../ty) ];
description = ''
Development tools for Python. Includes Python interpreter, Pip, Poetry, and the ty language server.
Development tools for Python. Includes Python interpreter, Pip, Poetry, the ty language server, and Ruff formatting.
'';

replit.packages = [
Expand All @@ -103,13 +102,6 @@ in
];
};

replit.dev.languageServers.ty = {
name = "ty";
displayVersion = ty.version;
language = "python3";
start = "${ty}/bin/ty server";
};

replit.dev.packagers.upmPython = {
name = "Python packager";
language = "python3";
Expand Down
77 changes: 71 additions & 6 deletions pkgs/modules/ty/default.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,66 @@
{ pkgs, ... }:
{ pkgs, lib, ... }:
let
ty = pkgs.callPackage ../../ty { };

formatter = import ../../formatter {
inherit pkgs;
};

run-ruff-format = pkgs.writeShellApplication {
name = "run-ruff-format";
runtimeInputs = [
pkgs.bash
pkgs.ruff
];
extraShellCheckFlags = [ "-x" ];
text = ''
#!/bin/bash

# Source the shared options parsing script
source ${formatter}/bin/parse-formatter-options "$@"

if [[ "$apply" == "true" ]]; then
if [[ "$stdinMode" == "true" ]]; then
ruff format --stdin-filename "$file" - > "$file"
else
ruff format --quiet "$file"
fi
exit 0
fi

if [[ "$stdinMode" == "true" ]]; then
ruff format --stdin-filename "$file" -
else
ruff format --stdin-filename "$file" - < "$file"
fi
'';
checkPhase = ''
cat > test.py << 'EOF'
def greet( name:str ) ->None:
print( f"hello, {name}" )
EOF

$out/bin/run-ruff-format -f test.py > output.py
printf 'def greet(name: str) -> None:\n print(f"hello, {name}")\n' > expected.py
if ! diff expected.py output.py; then
echo "format output doesn't match expectation"
exit 1
fi

cp test.py applied.py
$out/bin/run-ruff-format --apply -f applied.py
if ! diff expected.py applied.py; then
echo "apply format output doesn't match expectation"
exit 1
fi
'';
};
in
{
id = "ty";
name = "ty LSP";
displayVersion = ty.version;
description = ''
id = lib.mkDefault "ty";
name = lib.mkDefault "ty LSP";
displayVersion = lib.mkDefault ty.version;
description = lib.mkDefault ''
Ty is an extremely fast Python type checker from Astral with an integrated language server.
'';
replit.dev.languageServers.ty = {
Expand All @@ -16,7 +70,18 @@ in
start = "${ty}/bin/ty server";
};

replit.dev.formatters.ruff = {
name = "Ruff";
displayVersion = pkgs.ruff.version;
language = "python3";
extensions = [ ".py" ];
start = {
args = [ "${run-ruff-format}/bin/run-ruff-format" ];
};
stdin = true;
};

replit.env = {
PATH = "${ty}/bin";
PATH = lib.mkDefault "${ty}/bin";
};
}
Loading