-
Notifications
You must be signed in to change notification settings - Fork 326
Expand file tree
/
Copy pathPython.fs
More file actions
115 lines (94 loc) · 4.2 KB
/
Copy pathPython.fs
File metadata and controls
115 lines (94 loc) · 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
module Build.Test.Python
open Build.FableLibrary
open System.IO
open Build.Utils
open BlackFox.CommandLine
open SimpleExec
let private buildDir = Path.Resolve("temp", "tests", "Python")
let private sourceDir = Path.Resolve("tests", "Python")
let private fableLibraryBuildDir = Path.Resolve("temp", "fable-library-py")
let handle (args: string list) =
let skipFableLibrary = args |> List.contains "--skip-fable-library"
let skipFableLibraryCore = args |> List.contains "--skip-fable-library-core"
let isWatch = args |> List.contains "--watch"
let noDotnet = args |> List.contains "--no-dotnet"
let compileOnly = args |> List.contains "--compile-only"
let runTyping = args |> List.contains "--type-check"
let runFormat = args |> List.contains "--format"
BuildFableLibraryPython(skipCore = skipFableLibraryCore).Run(skipFableLibrary)
Directory.clean buildDir
Command.Run("uv", "sync")
// Install local fable-library as editable package for testing
// This ensures tests use the locally built version, not PyPI
Command.Run("uv", $"pip install -e {fableLibraryBuildDir}")
let fableArgs =
CmdLine.concat
[
CmdLine.empty
|> CmdLine.appendRaw sourceDir
|> CmdLine.appendPrefix "--outDir" buildDir
|> CmdLine.appendPrefix "--lang" "python"
|> CmdLine.appendPrefix "--exclude" "Fable.Core"
|> CmdLine.appendRaw "--noCache"
if isWatch then
let ruffCmd =
if runFormat then
$"uv run ruff check --select I,F401 --fix {buildDir} && uv run ruff format {buildDir} && "
else
""
CmdLine.empty
|> CmdLine.appendRaw "--watch"
|> CmdLine.appendRaw "--runWatch"
|> CmdLine.appendRaw $"{ruffCmd}uv run pytest {buildDir} -x"
]
if isWatch then
Async.Parallel
[
if not noDotnet then
Command.RunAsync("dotnet", "watch test -c Release", workingDirectory = sourceDir)
|> Async.AwaitTask
Command.WatchFableAsync(fableArgs, workingDirectory = buildDir)
|> Async.AwaitTask
]
|> Async.RunSynchronously
|> ignore
else
// Test against .NET
if compileOnly then
printfn "Skipping .NET test execution (--compile-only specified)"
else
Command.Run("dotnet", "test -c Release", workingDirectory = sourceDir)
// Test against Python
Command.Fable(fableArgs, workingDirectory = buildDir)
if runFormat then
// Run Ruff linter checking import sorting and fix any issues, and remove unused imports
Command.Run("uv", $"run ruff check --select I,F401 --fix {buildDir}")
// Run Ruff formatter on all generated files
Command.Run("uv", $"run ruff format {buildDir}")
// Run pytest
if compileOnly then
printfn "Skipping Python test execution (--compile-only specified)"
else
Command.Run("uv", $"run pytest {buildDir} -x")
// Count the number of typing errors (so we can keep an eye on them)
if runTyping then
printfn "Running type checking ..."
let output =
let struct (output, _) =
Command.ReadAsync(
"uv",
"run pyright .",
workingDirectory = buildDir,
handleExitCode = fun _ -> true
)
|> Async.AwaitTask
|> Async.RunSynchronously
output
// Extract and display only the summary line (last non-empty line)
let summaryLine =
output.Split([| '\n'; '\r' |], System.StringSplitOptions.RemoveEmptyEntries)
|> Array.tryLast
|> Option.defaultValue "No output"
printfn "Pyright summary: %s" summaryLine
else
printfn "Skipping type checking (use --type-check to enable)"