Skip to content

Commit 12a8199

Browse files
committed
Added flask (wip)
1 parent 96d88c7 commit 12a8199

File tree

17 files changed

+315
-16
lines changed

17 files changed

+315
-16
lines changed

Build.fs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ open Helpers
66
initializeContext()
77

88
let buildPath = Path.getFullName "build"
9-
let srcPath = Path.getFullName "src"
9+
let srcPath = Path.getFullName "stdlib"
1010
let deployPath = Path.getFullName "deploy"
1111
let testsPath = Path.getFullName "test"
1212

@@ -19,8 +19,6 @@ Target.create "Clean" (fun _ ->
1919
// run dotnet $"run -c Release -p {cliPath} -- clean --yes --lang Python " buildPath
2020
)
2121

22-
Target.create "InstallClient" (fun _ -> run npm "install" ".")
23-
2422
Target.create "Build" (fun _ ->
2523
Shell.mkdir buildPath
2624
run dotnet $"run -c Release -p {cliPath} -- --lang Python --exclude Fable.Core --outDir {buildPath}/lib" srcPath
@@ -30,13 +28,14 @@ Target.create "Run" (fun _ ->
3028
run dotnet "build" srcPath
3129
)
3230

33-
Target.create "RunTests" (fun _ ->
31+
Target.create "Test" (fun _ ->
3432
run dotnet "build" testsPath
3533
[ "native", dotnet "run" testsPath
3634
"python", dotnet $"run -c Release -p {cliPath} -- --lang Python --exclude Fable.Core --outDir {buildPath}/tests" testsPath
3735
]
3836
|> runParallel
3937
Shell.Exec("touch", $"{buildPath}/tests/__init__.py") |> ignore
38+
Shell.Exec("touch", $"{buildPath}/tests/stdlib/__init__.py") |> ignore
4039
run pytest $"{buildPath}/tests" ""
4140
)
4241

@@ -48,16 +47,13 @@ open Fake.Core.TargetOperators
4847

4948
let dependencies = [
5049
"Clean"
51-
==> "InstallClient"
5250
==> "Build"
5351

5452
"Clean"
55-
==> "InstallClient"
5653
==> "Run"
5754

58-
"InstallClient"
59-
==> "Build"
60-
==> "RunTests"
55+
"Build"
56+
==> "Test"
6157
]
6258

6359
[<EntryPoint>]

examples/flask/App.fs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module Safe
2+
3+
open Fable.Python.Builtins
4+
open Flask
5+
6+
let app = Flask.Create(__name__)
7+
let index = app.route("/")
8+
9+
let hello_world () =
10+
"<p>Hello, World!</p>"
11+
//flask.render_template()
12+
13+
hello_world |> index |> ignore

examples/flask/Flask.fsproj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project Sdk="Microsoft.NET.Sdk">
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
<GenerateProgramFile>false</GenerateProgramFile>
6+
<Author>Dag Brattli</Author>
7+
<Copyright>Dag Brattli</Copyright>
8+
</PropertyGroup>
9+
<ItemGroup>
10+
<Compile Include="App.fs" />
11+
</ItemGroup>
12+
<ItemGroup>
13+
<ProjectReference Include="../../../Fable/src/Fable.Core/Fable.Core.fsproj" />
14+
<ProjectReference Include="../../stdlib/Fable.Python.fsproj" />
15+
<ProjectReference Include="../../flask/Fable.Python.Flask.fsproj" />
16+
</ItemGroup>
17+
18+
<Import Project="..\..\.paket\Paket.Restore.targets" />
19+
</Project>

examples/flask/build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
dotnet run -c Release -p ../../../Fable/src/Fable.Cli -- --lang Python --exclude Fable.Core

examples/flask/poetry.lock

Lines changed: 191 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/flask/pyproject.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
[tool.poetry]
3+
name = "flask-example"
4+
version = "0.1.0"
5+
description = "Flask Example"
6+
authors = ["Dag Brattli <[email protected]>"]
7+
license = "MIT"
8+
9+
[tool.poetry.dependencies]
10+
python = "^3.8"
11+
fable-library = "^0.0.1"
12+
Flask = "^2.0.1"
13+
14+
[tool.poetry.dev-dependencies]
15+
16+
[build-system]
17+
requires = ["poetry-core>=1.0.0"]
18+
build-backend = "poetry.core.masonry.api"

flask/Fable.Python.Flask.fsproj

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project Sdk="Microsoft.NET.Sdk">
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
6+
<Author>Dag Brattli</Author>
7+
<Copyright>Dag Brattli</Copyright>
8+
<PackageLicenseFile>LICENSE</PackageLicenseFile>
9+
<WarnOn>3390;$(WarnOn)</WarnOn>
10+
</PropertyGroup>
11+
<ItemGroup>
12+
<Compile Include="Flask.fs" />
13+
</ItemGroup>
14+
<ItemGroup>
15+
<ProjectReference Include="../../Fable/src/Fable.Core/Fable.Core.fsproj" />
16+
</ItemGroup>
17+
<ItemGroup>
18+
<Content Include="pyproject.toml; *.fsproj; **\*.fs; **\*.fsi" PackagePath="fable\" />
19+
</ItemGroup>
20+
<ItemGroup>
21+
<None Include="..\LICENSE" Pack="true" Visible="false" PackagePath=""/>
22+
</ItemGroup>
23+
<Import Project="..\.paket\Paket.Restore.targets" />
24+
</Project>

flask/Flask.fs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module Flask
2+
3+
open Fable.Core
4+
5+
// fsharplint:disable MemberNames
6+
type RequestBase =
7+
abstract url : string
8+
9+
type Request =
10+
inherit RequestBase
11+
12+
type Flask =
13+
abstract route : rule: string -> ((unit -> string) -> Flask)
14+
abstract route : rule: string * methods: string array -> ((unit -> string) -> Flask)
15+
16+
17+
type FlaskStatic =
18+
[<Emit("$0(import_name=$1)")>]
19+
abstract Create : string -> Flask
20+
21+
[<Import("Flask", "flask")>]
22+
let Flask: FlaskStatic = nativeOnly
23+
24+
type IExports =
25+
abstract render_template : template_name_or_list: string -> string
26+
abstract render_template : template_name_or_list: string seq -> string
27+
abstract request : Request
28+
29+
[<ImportAll("flask")>]
30+
let flask : IExports = nativeOnly

src/Ast.fs renamed to stdlib/Ast.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,5 @@ type IExports =
120120
/// Return a formatted dump of the tree in node.
121121
abstract dump : node: AST * annotate_fields: bool * include_attributes: bool -> string
122122

123-
[<Import("ast")>]
123+
[<ImportAll("ast")>]
124124
let ast: IExports = nativeOnly

src/Builtins.fs renamed to stdlib/Builtins.fs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,8 @@ type IExports =
120120
file: _OpenFile * mode: OpenTextMode * buffering: int * encoding: string * errors: string * newline: string ->
121121
TextIOWrapper
122122

123-
[<Import("builtins")>]
123+
[<ImportAll("builtins")>]
124124
let builtins: IExports = nativeOnly
125+
126+
[<Emit("__name__")>]
127+
let __name__ : string = nativeOnly

0 commit comments

Comments
 (0)