Skip to content

Commit e5c16d9

Browse files
committed
Use fable-py
1 parent 74e6568 commit e5c16d9

File tree

16 files changed

+165
-153
lines changed

16 files changed

+165
-153
lines changed

.config/dotnet-tools.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@
99
]
1010
},
1111
"fantomas-tool": {
12-
"version": "4.5.3",
12+
"version": "4.5.4",
1313
"commands": [
1414
"fantomas"
1515
]
16+
},
17+
"fable-py": {
18+
"version": "4.0.0-alpha-003",
19+
"commands": [
20+
"fable-py"
21+
]
1622
}
1723
}
1824
}

.github/workflows/build-and-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ jobs:
2727
- name: Build
2828
run: dotnet run Build --configuration Release --no-restore
2929
- name: Test
30-
run: dotnet run RunTests
30+
run: dotnet run Test

Build.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Target.create "Clean" (fun _ ->
2121

2222
Target.create "Build" (fun _ ->
2323
Shell.mkdir buildPath
24-
run dotnet $"run -c Release -p {cliPath} -- --lang Python --exclude Fable.Core --outDir {buildPath}" srcPath
24+
run dotnet $"fable-py -c Release -p {cliPath} --exclude Fable.Core --outDir {buildPath}" srcPath
2525
)
2626

2727
Target.create "Run" (fun _ ->
@@ -31,7 +31,7 @@ Target.create "Run" (fun _ ->
3131
Target.create "Test" (fun _ ->
3232
run dotnet "build" testsPath
3333
[ "native", dotnet "run" testsPath
34-
"python", dotnet $"run -c Release -p {cliPath} -- --lang Python --exclude Fable.Core --outDir {buildPath}/tests" testsPath
34+
"python", dotnet $"fable-py -c Release -p {cliPath} --exclude Fable.Core --outDir {buildPath}/tests" testsPath
3535
]
3636
|> runParallel
3737
run pytest $"{buildPath}/tests" ""

examples/microbit/App.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ module App
22

33
open Fable.Python.MicroBit
44

5-
display.scroll("Fable Python!") |> ignore
5+
display.scroll ("Fable Python!") |> ignore

examples/timeflies/Program.fs

Lines changed: 87 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,87 @@
1-
// Learn more about F# at http://docs.microsoft.com/dotnet/fsharp
2-
module Program
3-
4-
open System
5-
open FSharp.Control
6-
open Fable.Python
7-
open Fable.Python.TkInter
8-
open Fable.Python.Queue
9-
10-
type Msg =
11-
| Place of label: Label * x: int * y: int
12-
//| Place of x: int * y: int
13-
| Empty
14-
15-
let root = Tk()
16-
root.title("Fable Python Rocks on Tkinter!")
17-
let queue = Queue<Msg> ()
18-
19-
let source, mouseMoves: IAsyncObserver<int*int>*IAsyncObservable<int*int> = AsyncRx.subject()
20-
21-
let workerAsync (mb: MailboxProcessor<Event>) =
22-
let rec messageLoop () =
23-
async {
24-
let! event = mb.Receive ()
25-
do! source.OnNextAsync((event.x, event.y))
26-
27-
return! messageLoop ()
28-
}
29-
messageLoop ()
30-
31-
let agent = MailboxProcessor<TkInter.Event>.Start(workerAsync)
32-
33-
let frame = Frame(root, width=800, height=600, bg="white")
34-
frame.bind("<Motion>", agent.Post) |> ignore
35-
frame.pack()
36-
37-
let stream =
38-
Seq.toList "TIME FLIES LIKE AN ARROW"
39-
|> Seq.mapi (fun i c -> i, Label(frame, text=(string c), fg="black", bg="white"))
40-
|> AsyncRx.ofSeq
41-
|> AsyncRx.flatMap (fun (i, label) ->
42-
mouseMoves
43-
|> AsyncRx.delay (100 * i)
44-
|> AsyncRx.map (fun (x, y) -> label, x + i * 12 + 15, y))
45-
46-
let sink (ev: Notification<Label*int*int>) =
47-
async {
48-
match ev with
49-
| OnNext (label, x, y) -> queue.put(Place(label, x, y))
50-
| OnError(err) -> printfn $"Stream Error: {err}"
51-
| _ -> printfn "Stream Completed"
52-
return ()
53-
}
54-
55-
let mainAsync =
56-
async {
57-
use! disposable = stream.SubscribeAsync(sink)
58-
59-
let rec update () =
60-
let size = queue.qsize()
61-
for _ in 1..size do
62-
let msg = queue.get(false)
63-
64-
match msg with
65-
| Place (label, x, y) -> label.place(x, y)
66-
| _ -> ()
67-
68-
match size with
69-
| n when n > 0 -> root.after(1, update)
70-
| _ -> root.after(10, update)
71-
72-
root.after(1, update)
73-
root.mainloop()
74-
75-
return ()
76-
}
77-
78-
[<EntryPoint>]
79-
let main argv =
80-
printfn "Started ..."
81-
Async.Start mainAsync
82-
83-
0 // return an integer exit code
1+
// Learn more about F# at http://docs.microsoft.com/dotnet/fsharp
2+
module Program
3+
4+
open System
5+
open FSharp.Control
6+
open Fable.Python
7+
open Fable.Python.TkInter
8+
open Fable.Python.Queue
9+
10+
type Msg =
11+
| Place of label: Label * x: int * y: int
12+
//| Place of x: int * y: int
13+
| Empty
14+
15+
let root = Tk()
16+
root.title ("Fable Python Rocks on Tkinter!")
17+
let queue = Queue<Msg>()
18+
19+
let source, mouseMoves: IAsyncObserver<int * int> * IAsyncObservable<int * int> = AsyncRx.subject ()
20+
21+
let workerAsync (mb: MailboxProcessor<Event>) =
22+
let rec messageLoop () =
23+
async {
24+
let! event = mb.Receive()
25+
do! source.OnNextAsync((event.x, event.y))
26+
27+
return! messageLoop ()
28+
}
29+
30+
messageLoop ()
31+
32+
let agent = MailboxProcessor<TkInter.Event>.Start (workerAsync)
33+
34+
let frame = Frame(root, width = 800, height = 600, bg = "white")
35+
frame.bind ("<Motion>", agent.Post) |> ignore
36+
frame.pack ()
37+
38+
let stream =
39+
Seq.toList "TIME FLIES LIKE AN ARROW"
40+
|> Seq.mapi (fun i c -> i, Label(frame, text = (string c), fg = "black", bg = "white"))
41+
|> AsyncRx.ofSeq
42+
|> AsyncRx.flatMap
43+
(fun (i, label) ->
44+
mouseMoves
45+
|> AsyncRx.delay (100 * i)
46+
|> AsyncRx.map (fun (x, y) -> label, x + i * 12 + 15, y))
47+
48+
let sink (ev: Notification<Label * int * int>) =
49+
async {
50+
match ev with
51+
| OnNext (label, x, y) -> queue.put (Place(label, x, y))
52+
| OnError (err) -> printfn $"Stream Error: {err}"
53+
| _ -> printfn "Stream Completed"
54+
55+
return ()
56+
}
57+
58+
let mainAsync =
59+
async {
60+
use! disposable = stream.SubscribeAsync(sink)
61+
62+
let rec update () =
63+
let size = queue.qsize ()
64+
65+
for _ in 1 .. size do
66+
let msg = queue.get (false)
67+
68+
match msg with
69+
| Place (label, x, y) -> label.place (x, y)
70+
| _ -> ()
71+
72+
match size with
73+
| n when n > 0 -> root.after (1, update)
74+
| _ -> root.after (10, update)
75+
76+
root.after (1, update)
77+
root.mainloop ()
78+
79+
return ()
80+
}
81+
82+
[<EntryPoint>]
83+
let main argv =
84+
printfn "Started ..."
85+
Async.Start mainAsync
86+
87+
0 // return an integer exit code
Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
2-
3-
<PropertyGroup>
4-
<OutputType>Exe</OutputType>
5-
<TargetFramework>net5.0</TargetFramework>
6-
<WarnOn>3390;$(WarnOn)</WarnOn>
7-
</PropertyGroup>
8-
9-
<ItemGroup>
10-
<Compile Include="Program.fs" />
11-
</ItemGroup>
12-
13-
<ItemGroup>
14-
<PackageReference Include="Fable.Python" Version="0.5.0" />
15-
<PackageReference Include="FSharp.Control.AsyncRx" Version="1.6.0" />
16-
</ItemGroup>
17-
<ItemGroup>
18-
<ProjectReference Include="../GitHub/Fable/src/Fable.Core/Fable.Core.fsproj" />
19-
</ItemGroup>
20-
21-
</Project>
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project Sdk="Microsoft.NET.Sdk">
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net5.0</TargetFramework>
6+
<WarnOn>3390;$(WarnOn)</WarnOn>
7+
</PropertyGroup>
8+
<ItemGroup>
9+
<Compile Include="Program.fs" />
10+
</ItemGroup>
11+
<ItemGroup>
12+
<PackageReference Include="Fable.Python" Version="0.5.0" />
13+
<PackageReference Include="FSharp.Control.AsyncRx" Version="1.6.0" />
14+
</ItemGroup>
15+
<ItemGroup>
16+
<ProjectReference Include="../GitHub/Fable/src/Fable.Core/Fable.Core.fsproj" />
17+
</ItemGroup>
18+
<Import Project="..\..\.paket\Paket.Restore.targets" />
19+
</Project>

paket.dependencies

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ source https://api.nuget.org/v3/index.json
33
storage: none
44
framework: net5.0, netstandard2.0, netstandard2.1
55

6-
nuget FSharp.Core 5.0.0
6+
nuget FSharp.Core
7+
nuget Fable.Core.Experimental >= 4.0.0-alpha-002
78

89
group Test
910
source https://api.nuget.org/v3/index.json
1011
storage: none
1112
framework: net5.0
1213

13-
nuget FSharp.Core 5.0.0
14+
nuget FSharp.Core
15+
nuget Fable.Core.Experimental >= 4.0.0-alpha-002
1416
nuget Microsoft.NET.Test.Sdk ~> 16
1517
nuget XUnit ~> 2
1618
nuget xunit.runner.visualstudio ~> 2

paket.lock

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ STORAGE: NONE
22
RESTRICTION: || (== net5.0) (== netstandard2.0) (== netstandard2.1)
33
NUGET
44
remote: https://api.nuget.org/v3/index.json
5-
FSharp.Core (5.0)
5+
Fable.Core.Experimental (4.0.0-alpha-002)
6+
FSharp.Core (>= 4.7.2)
7+
FSharp.Core (6.0)
68

79
GROUP Build
810
STORAGE: NONE
@@ -51,7 +53,7 @@ NUGET
5153
FSharp.Control.Reactive (5.0.2)
5254
FSharp.Core (>= 4.7.2)
5355
System.Reactive (>= 5.0)
54-
FSharp.Core (5.0.2)
56+
FSharp.Core (6.0)
5557
System.Collections.Immutable (5.0)
5658
System.Reactive (5.0)
5759

@@ -60,12 +62,14 @@ STORAGE: NONE
6062
RESTRICTION: == net5.0
6163
NUGET
6264
remote: https://api.nuget.org/v3/index.json
63-
FSharp.Core (5.0)
65+
Fable.Core.Experimental (4.0.0-alpha-002)
66+
FSharp.Core (>= 4.7.2)
67+
FSharp.Core (6.0)
6468
Microsoft.CodeCoverage (16.11)
6569
Microsoft.NET.Test.Sdk (16.11)
6670
Microsoft.CodeCoverage (>= 16.11)
6771
Microsoft.TestPlatform.TestHost (>= 16.11)
68-
Microsoft.NETCore.Platforms (5.0.2)
72+
Microsoft.NETCore.Platforms (5.0.4)
6973
Microsoft.TestPlatform.ObjectModel (16.11)
7074
NuGet.Frameworks (>= 5.0)
7175
System.Reflection.Metadata (>= 1.6)

src/Fable.Python.fsproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323

2424
<Compile Include="microbit/MicroBit.fs" />
2525
</ItemGroup>
26-
<ItemGroup>
27-
<ProjectReference Include="../../Fable/src/Fable.Core/Fable.Core.fsproj" />
28-
</ItemGroup>
2926
<ItemGroup>
3027
<Content Include="pyproject.toml; *.fsproj; **\*.fs; **\*.fsi" PackagePath="fable\" />
3128
</ItemGroup>

src/cognite-sdk/CogniteSdk.fs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ module Fable.Python.CogniteSdk
33
open Fable.Core
44

55
type ITimeSeries =
6-
abstract plot: start: string * ``end``: string * aggregates: string array * granularity: string -> unit
6+
abstract plot : start: string * ``end``: string * aggregates: string array * granularity: string -> unit
77

88
type ITimeSeriesApi =
9-
abstract retrieve: id: int64 -> ITimeSeries
10-
abstract list: unit -> ITimeSeries list
9+
abstract retrieve : id: int64 -> ITimeSeries
10+
abstract list : unit -> ITimeSeries list
1111

12-
[<Import("CogniteClient", from="cognite.client")>]
12+
[<Import("CogniteClient", from = "cognite.client")>]
1313
type CogniteClient (?apiKey: string, ?api_subversion: string, ?project: string, ?clientName: string) =
14-
abstract member time_series: ITimeSeriesApi with get
15-
default this.time_series with get () = nativeOnly
16-
14+
abstract member time_series : ITimeSeriesApi
15+
override this.time_series = nativeOnly

0 commit comments

Comments
 (0)