Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
"fantomas"
]
},
"fable-py": {
"version": "4.0.0-alpha-032",
"fable": {
"version": "4.0.0-snake-island-alpha-006",
"commands": [
"fable-py"
"fable"
]
}
}
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,5 @@ build
src/**/*.py

.ionide/

.fake
4 changes: 2 additions & 2 deletions Build.fs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Target.create "Clean" (fun _ ->

Target.create "Build" (fun _ ->
Shell.mkdir buildPath
run dotnet $"fable-py --exclude Fable.Core --outDir {buildPath}" srcPath
run dotnet $"fable --exclude Fable.Core --lang Python --outDir {buildPath}" srcPath
)

Target.create "Run" (fun _ ->
Expand All @@ -31,7 +31,7 @@ Target.create "Run" (fun _ ->
Target.create "Test" (fun _ ->
run dotnet "build" testsPath
[ "native", dotnet "run" testsPath
"python", dotnet $"fable-py --outDir {buildPath}/tests" testsPath
"python", dotnet $"fable --lang Python --outDir {buildPath}/tests" testsPath
]
|> runParallel
run pytest $"{buildPath}/tests" ""
Expand Down
63 changes: 45 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
![Build and Test](https://github.com/dbrattli/Fable.Python/workflows/Build%20and%20Test/badge.svg)
[![Nuget](https://img.shields.io/nuget/vpre/Fable.Python)](https://www.nuget.org/packages/Fable.Python/)

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

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

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

## Version

This library currently targets Python 3.9. Types bindings for other versions of Python should not be added to this
library until we decide how to deal with Python version handling.
This library currently targets Python 3.9. Types bindings for other
versions of Python should not be added to this library until we decide
how to deal with Python version handling.

## Installation

Prerequisite for compiling F# to Python using Fable:

```sh
> dotnet tool install --global fable-py --version 4.0.0-alpha-032
> dotnet add package Fable.Core.Experimental --version 4.0.0-alpha-032
> dotnet tool install --global fable --version 4.0.0-snake-island-alpha-006
> dotnet add package Fable.Core --version 4.0.0-snake-island-alpha-006
```

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

```sh
> fable-py MyProject.fsproj
> fable --lang Python MyProject.fsproj
```

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

## Poetry

Fable.Python uses [Poetry](https://python-poetry.org/) for package and
dependency management. This means that packages generated within
`fable_modules` must be referenced as [path
dependencies](https://python-poetry.org/docs/dependency-specification/#path-dependencies).
It is also possible to reference
[fable-library](https://pypi.org/project/fable-library/) from PyPI to
avoid bundling the code.

## Contributing

This project is community driven. If the type binding you are looking for is currently missing, then
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
get them included.
This project is community driven. If the type binding you are looking
for is currently missing, then 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 get them
included.

The `src/stdlib` directory contains type bindings for modules in the Python 3 standard library. We also accept type
bindings for 3rd party libraries as long as:
The `src/stdlib` directory contains type bindings for modules in the
Python 3 standard library. We also accept type bindings for 3rd party
libraries as long as:

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

There's not much Python specific documentation yet, but the process of adding type bindings for Python is similar to JS:
There's not much Python specific documentation yet, but the process of
adding type bindings for Python is similar to JS:

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


## Differences from JS

Note that import all is different from JS. E.g:
Expand All @@ -117,3 +133,14 @@ Current plan:
1. Add bindings for Python `ast` module (in progress)
2. Use `ast` module to parse Python typeshed annotations
3. Generate F# bindings

## Road-map

- Use a dedicated List.fs for Python. List.fs currently depends on
Array.fs that is not an efficient list implmentation for Python.

- Compile Fable.Library as a published library (done)

- Use poetry for Python references to Fable modules (done)

- Update docs
2 changes: 1 addition & 1 deletion examples/microbit/src/paket.references
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Fable.Core.Experimental
Fable.Core
3 changes: 1 addition & 2 deletions examples/timeflies/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ references NuGet packages.
## Build

```sh
> dotnet fable-py
> dotnet fable --lang Python
```


## Run

```sh
Expand Down
6 changes: 3 additions & 3 deletions examples/timeflies/TimeFlies.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Fable.Python" Version="0.16.0" />
<PackageReference Include="Fable.Core.Experimental" Version="4.0.0-alpha-032" />
<PackageReference Include="FSharp.Control.AsyncRx" Version="1.6.0" />
<PackageReference Include="Fable.Python" Version="0.17.0" />
<PackageReference Include="Fable.Core" Version="4.0.0-snake-island-alpha-006" />
<PackageReference Include="FSharp.Control.AsyncRx" Version="1.6.1" />
</ItemGroup>
</Project>
54 changes: 54 additions & 0 deletions examples/timeflies/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions examples/timeflies/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

[tool.poetry]
name = "timeflies"
version = "0.1.0"
description = "Fable Timeflies Demo"
authors = ["Dag Brattli <dag@brattli.net>"]
license = "MIT"

[tool.poetry.dependencies]
python = "^3.9"
fable-library = ""
fable-python = ""
fsharp-control-async-rx = ""

[tool.poetry.dev-dependencies]
fable-library = {path = "./fable_modules/fable-library", develop = true}
fable-python = {path = "./fable_modules/fable-python", develop = true}
fsharp-control-async-rx = {path = "./fable_modules/fsharp-control-async-rx", develop = true}

[tool.fable]
package-dir = "."

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
4 changes: 2 additions & 2 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ storage: none
framework: net6.0, netstandard2.0, netstandard2.1

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

group Test
source https://api.nuget.org/v3/index.json
storage: none
framework: net6.0

nuget FSharp.Core
nuget Fable.Core.Experimental >= 4.0.0-alpha-032
nuget Fable.Core >= 4.0.0-snake-island-alpha-006
nuget Microsoft.NET.Test.Sdk ~> 16
nuget XUnit ~> 2
nuget xunit.runner.visualstudio ~> 2
Expand Down
Loading