Skip to content

Commit 81e7a45

Browse files
authored
Fable 4 (snake island) refactor (#59)
* Fable 4 (snake island) refactor * fix: update deps * doc: update readme
1 parent b202a25 commit 81e7a45

File tree

13 files changed

+191
-84
lines changed

13 files changed

+191
-84
lines changed

.config/dotnet-tools.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
"fantomas"
1515
]
1616
},
17-
"fable-py": {
18-
"version": "4.0.0-alpha-032",
17+
"fable": {
18+
"version": "4.0.0-snake-island-alpha-006",
1919
"commands": [
20-
"fable-py"
20+
"fable"
2121
]
2222
}
2323
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,5 @@ build
137137
src/**/*.py
138138

139139
.ionide/
140+
141+
.fake

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 $"fable-py --exclude Fable.Core --outDir {buildPath}" srcPath
24+
run dotnet $"fable --exclude Fable.Core --lang Python --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 $"fable-py --outDir {buildPath}/tests" testsPath
34+
"python", dotnet $"fable --lang Python --outDir {buildPath}/tests" testsPath
3535
]
3636
|> runParallel
3737
run pytest $"{buildPath}/tests" ""

README.md

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
![Build and Test](https://github.com/dbrattli/Fable.Python/workflows/Build%20and%20Test/badge.svg)
44
[![Nuget](https://img.shields.io/nuget/vpre/Fable.Python)](https://www.nuget.org/packages/Fable.Python/)
55

6-
[Fable](https://github.com/fable-compiler/Fable/tree/beyond) is a compiler that
7-
translates F# source files to JavaScript and Python.
6+
[Fable](https://github.com/fable-compiler/Fable/tree/beyond) is a
7+
compiler that translates F# source files to JavaScript and Python.
88

9-
This Fable Python repository is a community driven project that contains the Python type bindings for Fable. The
10-
library will eventually contain Python (stdlib) bindings for Fable based on Python
11-
[typeshed](https://github.com/python/typeshed). It will also contain type binding for many other 3rd party libraries
12-
such as Flask, MicroBit and many more. Some bindings have already been added:
9+
This Fable Python repository is a community driven project that contains
10+
the Python type bindings for Fable. The library will eventually contain
11+
Python (stdlib) bindings for Fable based on Python
12+
[typeshed](https://github.com/python/typeshed). It will also contain
13+
type binding for many other 3rd party libraries such as Flask, MicroBit
14+
and many more. Some bindings have already been added:
1315

1416
- Python Standard Libray
1517
- Jupyter
@@ -19,16 +21,17 @@ such as Flask, MicroBit and many more. Some bindings have already been added:
1921

2022
## Version
2123

22-
This library currently targets Python 3.9. Types bindings for other versions of Python should not be added to this
23-
library until we decide how to deal with Python version handling.
24+
This library currently targets Python 3.9. Types bindings for other
25+
versions of Python should not be added to this library until we decide
26+
how to deal with Python version handling.
2427

2528
## Installation
2629

2730
Prerequisite for compiling F# to Python using Fable:
2831

2932
```sh
30-
> dotnet tool install --global fable-py --version 4.0.0-alpha-032
31-
> dotnet add package Fable.Core.Experimental --version 4.0.0-alpha-032
33+
> dotnet tool install --global fable --version 4.0.0-snake-island-alpha-006
34+
> dotnet add package Fable.Core --version 4.0.0-snake-island-alpha-006
3235
```
3336

3437
To use the `Fable.Python` library in your Fable project:
@@ -49,7 +52,7 @@ let result = json.dumps object
4952
To compile an F# Fable project to Python run e.g:
5053

5154
```sh
52-
> fable-py MyProject.fsproj
55+
> fable --lang Python MyProject.fsproj
5356
```
5457

5558
For more examples see the
@@ -74,25 +77,38 @@ It contains example code for using Fable Python with:
7477
- [TypedCssClasses](https://github.com/zanaptak/TypedCssClasses)
7578
- [Typed-BNF](https://github.com/thautwarm/Typed-BNF#readme)
7679

80+
## Poetry
81+
82+
Fable.Python uses [Poetry](https://python-poetry.org/) for package and
83+
dependency management. This means that packages generated within
84+
`fable_modules` must be referenced as [path
85+
dependencies](https://python-poetry.org/docs/dependency-specification/#path-dependencies).
86+
It is also possible to reference
87+
[fable-library](https://pypi.org/project/fable-library/) from PyPI to
88+
avoid bundling the code.
89+
7790
## Contributing
7891

79-
This project is community driven. If the type binding you are looking for is currently missing, then
80-
you need to add them to the relavant files (or add new ones). Open a [PR](https://github.com/dbrattli/Fable.Python/pull/3/files) to
81-
get them included.
92+
This project is community driven. If the type binding you are looking
93+
for is currently missing, then you need to add them to the relavant
94+
files (or add new ones). Open a
95+
[PR](https://github.com/dbrattli/Fable.Python/pull/3/files) to get them
96+
included.
8297

83-
The `src/stdlib` directory contains type bindings for modules in the Python 3 standard library. We also accept type
84-
bindings for 3rd party libraries as long as:
98+
The `src/stdlib` directory contains type bindings for modules in the
99+
Python 3 standard library. We also accept type bindings for 3rd party
100+
libraries as long as:
85101

86102
- the package is publicly available on the [Python Package Index](https://pypi.org/);
87103
- the package supports any Python version supported by Fable Python; and
88104
- the package does not ship with its own stubs or type annotations
89105

90-
There's not much Python specific documentation yet, but the process of adding type bindings for Python is similar to JS:
106+
There's not much Python specific documentation yet, but the process of
107+
adding type bindings for Python is similar to JS:
91108

92109
- https://fable.io/docs/communicate/js-from-fable.html
93110
- https://medium.com/@zaid.naom/f-interop-with-javascript-in-fable-the-complete-guide-ccc5b896a59f
94111

95-
96112
## Differences from JS
97113

98114
Note that import all is different from JS. E.g:
@@ -117,3 +133,14 @@ Current plan:
117133
1. Add bindings for Python `ast` module (in progress)
118134
2. Use `ast` module to parse Python typeshed annotations
119135
3. Generate F# bindings
136+
137+
## Road-map
138+
139+
- Use a dedicated List.fs for Python. List.fs currently depends on
140+
Array.fs that is not an efficient list implmentation for Python.
141+
142+
- Compile Fable.Library as a published library (done)
143+
144+
- Use poetry for Python references to Fable modules (done)
145+
146+
- Update docs
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Fable.Core.Experimental
1+
Fable.Core

examples/timeflies/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ references NuGet packages.
1515
## Build
1616

1717
```sh
18-
> dotnet fable-py
18+
> dotnet fable --lang Python
1919
```
2020

21-
2221
## Run
2322

2423
```sh

examples/timeflies/TimeFlies.fsproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
<Compile Include="Program.fs" />
1010
</ItemGroup>
1111
<ItemGroup>
12-
<PackageReference Include="Fable.Python" Version="0.16.0" />
13-
<PackageReference Include="Fable.Core.Experimental" Version="4.0.0-alpha-032" />
14-
<PackageReference Include="FSharp.Control.AsyncRx" Version="1.6.0" />
12+
<PackageReference Include="Fable.Python" Version="0.17.0" />
13+
<PackageReference Include="Fable.Core" Version="4.0.0-snake-island-alpha-006" />
14+
<PackageReference Include="FSharp.Control.AsyncRx" Version="1.6.1" />
1515
</ItemGroup>
1616
</Project>

examples/timeflies/poetry.lock

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

examples/timeflies/pyproject.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
[tool.poetry]
3+
name = "timeflies"
4+
version = "0.1.0"
5+
description = "Fable Timeflies Demo"
6+
authors = ["Dag Brattli <dag@brattli.net>"]
7+
license = "MIT"
8+
9+
[tool.poetry.dependencies]
10+
python = "^3.9"
11+
fable-library = ""
12+
fable-python = ""
13+
fsharp-control-async-rx = ""
14+
15+
[tool.poetry.dev-dependencies]
16+
fable-library = {path = "./fable_modules/fable-library", develop = true}
17+
fable-python = {path = "./fable_modules/fable-python", develop = true}
18+
fsharp-control-async-rx = {path = "./fable_modules/fsharp-control-async-rx", develop = true}
19+
20+
[tool.fable]
21+
package-dir = "."
22+
23+
[build-system]
24+
requires = ["poetry-core>=1.0.0"]
25+
build-backend = "poetry.core.masonry.api"

paket.dependencies

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ storage: none
55
framework: net6.0, netstandard2.0, netstandard2.1
66

77
nuget FSharp.Core ~> 4.7
8-
nuget Fable.Core.Experimental >= 4.0.0-alpha-032
8+
nuget Fable.Core >= 4.0.0-snake-island-alpha-006
99

1010
group Test
1111
source https://api.nuget.org/v3/index.json
1212
storage: none
1313
framework: net6.0
1414

1515
nuget FSharp.Core
16-
nuget Fable.Core.Experimental >= 4.0.0-alpha-032
16+
nuget Fable.Core >= 4.0.0-snake-island-alpha-006
1717
nuget Microsoft.NET.Test.Sdk ~> 16
1818
nuget XUnit ~> 2
1919
nuget xunit.runner.visualstudio ~> 2

0 commit comments

Comments
 (0)