|
1 | | -{ pkgs, ... }: |
| 1 | +{ pkgs, lib, ... }: |
2 | 2 | let |
3 | 3 | ty = pkgs.callPackage ../../ty { }; |
| 4 | + |
| 5 | + formatter = import ../../formatter { |
| 6 | + inherit pkgs; |
| 7 | + }; |
| 8 | + |
| 9 | + run-ruff-format = pkgs.writeShellApplication { |
| 10 | + name = "run-ruff-format"; |
| 11 | + runtimeInputs = [ |
| 12 | + pkgs.bash |
| 13 | + pkgs.ruff |
| 14 | + ]; |
| 15 | + extraShellCheckFlags = [ "-x" ]; |
| 16 | + text = '' |
| 17 | + #!/bin/bash |
| 18 | +
|
| 19 | + # Source the shared options parsing script |
| 20 | + source ${formatter}/bin/parse-formatter-options "$@" |
| 21 | +
|
| 22 | + if [[ "$apply" == "true" ]]; then |
| 23 | + if [[ "$stdinMode" == "true" ]]; then |
| 24 | + ruff format --stdin-filename "$file" - > "$file" |
| 25 | + else |
| 26 | + ruff format --quiet "$file" |
| 27 | + fi |
| 28 | + exit 0 |
| 29 | + fi |
| 30 | +
|
| 31 | + if [[ "$stdinMode" == "true" ]]; then |
| 32 | + ruff format --stdin-filename "$file" - |
| 33 | + else |
| 34 | + ruff format --stdin-filename "$file" - < "$file" |
| 35 | + fi |
| 36 | + ''; |
| 37 | + checkPhase = '' |
| 38 | + cat > test.py << 'EOF' |
| 39 | + def greet( name:str ) ->None: |
| 40 | + print( f"hello, {name}" ) |
| 41 | + EOF |
| 42 | +
|
| 43 | + $out/bin/run-ruff-format -f test.py > output.py |
| 44 | + printf 'def greet(name: str) -> None:\n print(f"hello, {name}")\n' > expected.py |
| 45 | + if ! diff expected.py output.py; then |
| 46 | + echo "format output doesn't match expectation" |
| 47 | + exit 1 |
| 48 | + fi |
| 49 | +
|
| 50 | + cp test.py applied.py |
| 51 | + $out/bin/run-ruff-format --apply -f applied.py |
| 52 | + if ! diff expected.py applied.py; then |
| 53 | + echo "apply format output doesn't match expectation" |
| 54 | + exit 1 |
| 55 | + fi |
| 56 | + ''; |
| 57 | + }; |
4 | 58 | in |
5 | 59 | { |
6 | | - id = "ty"; |
7 | | - name = "ty LSP"; |
8 | | - displayVersion = ty.version; |
9 | | - description = '' |
| 60 | + id = lib.mkDefault "ty"; |
| 61 | + name = lib.mkDefault "ty LSP"; |
| 62 | + displayVersion = lib.mkDefault ty.version; |
| 63 | + description = lib.mkDefault '' |
10 | 64 | Ty is an extremely fast Python type checker from Astral with an integrated language server. |
11 | 65 | ''; |
12 | 66 | replit.dev.languageServers.ty = { |
|
16 | 70 | start = "${ty}/bin/ty server"; |
17 | 71 | }; |
18 | 72 |
|
| 73 | + replit.dev.formatters.ruff = { |
| 74 | + name = "Ruff"; |
| 75 | + displayVersion = pkgs.ruff.version; |
| 76 | + language = "python3"; |
| 77 | + extensions = [ ".py" ]; |
| 78 | + start = { |
| 79 | + args = [ "${run-ruff-format}/bin/run-ruff-format" ]; |
| 80 | + }; |
| 81 | + stdin = true; |
| 82 | + }; |
| 83 | + |
19 | 84 | replit.env = { |
20 | | - PATH = "${ty}/bin"; |
| 85 | + PATH = lib.mkDefault "${ty}/bin"; |
21 | 86 | }; |
22 | 87 | } |
0 commit comments