diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 14f2616..ea06c39 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -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" ] } } diff --git a/.gitignore b/.gitignore index 0f8f86f..65882b2 100644 --- a/.gitignore +++ b/.gitignore @@ -137,3 +137,5 @@ build src/**/*.py .ionide/ + +.fake \ No newline at end of file diff --git a/Build.fs b/Build.fs index cf526cb..a1b253f 100644 --- a/Build.fs +++ b/Build.fs @@ -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 _ -> @@ -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" "" diff --git a/README.md b/README.md index 032e98e..3eb7b7b 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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: @@ -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 @@ -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: @@ -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 diff --git a/examples/microbit/src/paket.references b/examples/microbit/src/paket.references index e0e5c8a..1d37423 100644 --- a/examples/microbit/src/paket.references +++ b/examples/microbit/src/paket.references @@ -1 +1 @@ -Fable.Core.Experimental \ No newline at end of file +Fable.Core \ No newline at end of file diff --git a/examples/timeflies/README.md b/examples/timeflies/README.md index 3f514ef..5b078a7 100644 --- a/examples/timeflies/README.md +++ b/examples/timeflies/README.md @@ -15,10 +15,9 @@ references NuGet packages. ## Build ```sh -> dotnet fable-py +> dotnet fable --lang Python ``` - ## Run ```sh diff --git a/examples/timeflies/TimeFlies.fsproj b/examples/timeflies/TimeFlies.fsproj index 4e31ac6..624575f 100644 --- a/examples/timeflies/TimeFlies.fsproj +++ b/examples/timeflies/TimeFlies.fsproj @@ -9,8 +9,8 @@ - - - + + + \ No newline at end of file diff --git a/examples/timeflies/poetry.lock b/examples/timeflies/poetry.lock new file mode 100644 index 0000000..14419cb --- /dev/null +++ b/examples/timeflies/poetry.lock @@ -0,0 +1,54 @@ +[[package]] +name = "fable-library" +version = "0.8.0" +description = "Fable library for Python" +category = "main" +optional = false +python-versions = "^3.8" +develop = true + +[package.source] +type = "directory" +url = "fable_modules/fable-library" + +[[package]] +name = "fable-python" +version = "0.1.0" +description = "Python bindings for Fable" +category = "main" +optional = false +python-versions = "^3.9" +develop = true + +[package.dependencies] +fable-library = "" + +[package.source] +type = "directory" +url = "fable_modules/fable-python" + +[[package]] +name = "fsharp-control-async-rx" +version = "1.6.1" +description = "Async Observables for F# and Fable" +category = "main" +optional = false +python-versions = ">=3.9,<4" +develop = true + +[package.dependencies] +fable-library = ">=0.7.0" + +[package.source] +type = "directory" +url = "fable_modules/fsharp-control-async-rx" + +[metadata] +lock-version = "1.1" +python-versions = "^3.9" +content-hash = "9ad00f12227f18e36ca297125065785ba9fa41f301eba68b117a0a965b8034a8" + +[metadata.files] +fable-library = [] +fable-python = [] +fsharp-control-async-rx = [] diff --git a/examples/timeflies/pyproject.toml b/examples/timeflies/pyproject.toml new file mode 100644 index 0000000..e973101 --- /dev/null +++ b/examples/timeflies/pyproject.toml @@ -0,0 +1,25 @@ + +[tool.poetry] +name = "timeflies" +version = "0.1.0" +description = "Fable Timeflies Demo" +authors = ["Dag Brattli "] +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" diff --git a/paket.dependencies b/paket.dependencies index e7d4964..5ac92c4 100644 --- a/paket.dependencies +++ b/paket.dependencies @@ -5,7 +5,7 @@ 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 @@ -13,7 +13,7 @@ group Test 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 diff --git a/paket.lock b/paket.lock index 85e28f7..e49412d 100644 --- a/paket.lock +++ b/paket.lock @@ -2,7 +2,7 @@ STORAGE: NONE RESTRICTION: || (== net6.0) (== netstandard2.0) (== netstandard2.1) NUGET remote: https://api.nuget.org/v3/index.json - Fable.Core.Experimental (4.0.0-alpha-021) + Fable.Core (4.0.0-snake-island-alpha-006) FSharp.Core (4.7.2) GROUP Build @@ -10,49 +10,49 @@ STORAGE: NONE RESTRICTION: == net6.0 NUGET remote: https://api.nuget.org/v3/index.json - Fake.Core.CommandLineParsing (5.20.4) + Fake.Core.CommandLineParsing (5.22) FParsec (>= 1.1.1) - FSharp.Core (>= 4.7.2) - Fake.Core.Context (5.20.4) - FSharp.Core (>= 4.7.2) - Fake.Core.Environment (5.20.4) - FSharp.Core (>= 4.7.2) - Fake.Core.FakeVar (5.20.4) - Fake.Core.Context (>= 5.20.4) - FSharp.Core (>= 4.7.2) - Fake.Core.Process (5.20.4) - Fake.Core.Environment (>= 5.20.4) - Fake.Core.FakeVar (>= 5.20.4) - Fake.Core.String (>= 5.20.4) - Fake.Core.Trace (>= 5.20.4) - Fake.IO.FileSystem (>= 5.20.4) - FSharp.Core (>= 4.7.2) - System.Collections.Immutable (>= 1.7.1) - Fake.Core.String (5.20.4) - FSharp.Core (>= 4.7.2) - Fake.Core.Target (5.20.4) - Fake.Core.CommandLineParsing (>= 5.20.4) - Fake.Core.Context (>= 5.20.4) - Fake.Core.Environment (>= 5.20.4) - Fake.Core.FakeVar (>= 5.20.4) - Fake.Core.Process (>= 5.20.4) - Fake.Core.String (>= 5.20.4) - Fake.Core.Trace (>= 5.20.4) - FSharp.Control.Reactive (>= 4.4.2) - FSharp.Core (>= 4.7.2) - Fake.Core.Trace (5.20.4) - Fake.Core.Environment (>= 5.20.4) - Fake.Core.FakeVar (>= 5.20.4) - FSharp.Core (>= 4.7.2) - Fake.IO.FileSystem (5.20.4) - Fake.Core.String (>= 5.20.4) - FSharp.Core (>= 4.7.2) + FSharp.Core (>= 6.0) + Fake.Core.Context (5.22) + FSharp.Core (>= 6.0) + Fake.Core.Environment (5.22) + FSharp.Core (>= 6.0) + Fake.Core.FakeVar (5.22) + Fake.Core.Context (>= 5.22) + FSharp.Core (>= 6.0) + Fake.Core.Process (5.22) + Fake.Core.Environment (>= 5.22) + Fake.Core.FakeVar (>= 5.22) + Fake.Core.String (>= 5.22) + Fake.Core.Trace (>= 5.22) + Fake.IO.FileSystem (>= 5.22) + FSharp.Core (>= 6.0) + System.Collections.Immutable (>= 5.0) + Fake.Core.String (5.22) + FSharp.Core (>= 6.0) + Fake.Core.Target (5.22) + Fake.Core.CommandLineParsing (>= 5.22) + Fake.Core.Context (>= 5.22) + Fake.Core.Environment (>= 5.22) + Fake.Core.FakeVar (>= 5.22) + Fake.Core.Process (>= 5.22) + Fake.Core.String (>= 5.22) + Fake.Core.Trace (>= 5.22) + FSharp.Control.Reactive (>= 5.0.2) + FSharp.Core (>= 6.0) + Fake.Core.Trace (5.22) + Fake.Core.Environment (>= 5.22) + Fake.Core.FakeVar (>= 5.22) + FSharp.Core (>= 6.0) + Fake.IO.FileSystem (5.22) + Fake.Core.String (>= 5.22) + FSharp.Core (>= 6.0) FParsec (1.1.1) FSharp.Core (>= 4.3.4) - FSharp.Control.Reactive (5.0.2) + FSharp.Control.Reactive (5.0.5) FSharp.Core (>= 4.7.2) - System.Reactive (>= 5.0) - FSharp.Core (6.0.1) + System.Reactive (>= 5.0 < 6.0) + FSharp.Core (6.0.5) System.Collections.Immutable (6.0) System.Runtime.CompilerServices.Unsafe (>= 6.0) System.Reactive (5.0) @@ -63,26 +63,26 @@ STORAGE: NONE RESTRICTION: == net6.0 NUGET remote: https://api.nuget.org/v3/index.json - Fable.Core.Experimental (4.0.0-alpha-021) - FSharp.Core (6.0.1) - Microsoft.CodeCoverage (17.0) + Fable.Core (4.0.0-snake-island-alpha-006) + FSharp.Core (6.0.5) + Microsoft.CodeCoverage (17.2) Microsoft.NET.Test.Sdk (16.11) Microsoft.CodeCoverage (>= 16.11) Microsoft.TestPlatform.TestHost (>= 16.11) - Microsoft.NETCore.Platforms (6.0.1) - Microsoft.TestPlatform.ObjectModel (17.0) - NuGet.Frameworks (>= 5.0) + Microsoft.NETCore.Platforms (6.0.5) + Microsoft.TestPlatform.ObjectModel (17.2) + NuGet.Frameworks (>= 5.11) System.Reflection.Metadata (>= 1.6) - Microsoft.TestPlatform.TestHost (17.0) - Microsoft.TestPlatform.ObjectModel (>= 17.0) + Microsoft.TestPlatform.TestHost (17.2) + Microsoft.TestPlatform.ObjectModel (>= 17.2) Newtonsoft.Json (>= 9.0.1) NETStandard.Library (2.0.3) Microsoft.NETCore.Platforms (>= 1.1) Newtonsoft.Json (13.0.1) - NuGet.Frameworks (6.0) + NuGet.Frameworks (6.2.1) System.Collections.Immutable (6.0) System.Runtime.CompilerServices.Unsafe (>= 6.0) - System.Reflection.Metadata (6.0) + System.Reflection.Metadata (6.0.1) System.Collections.Immutable (>= 6.0) System.Runtime.CompilerServices.Unsafe (6.0) xunit (2.4.1) @@ -102,4 +102,4 @@ NUGET xunit.extensibility.execution (2.4.1) NETStandard.Library (>= 1.6.1) xunit.extensibility.core (2.4.1) - xunit.runner.visualstudio (2.4.3) + xunit.runner.visualstudio (2.4.5) diff --git a/src/paket.references b/src/paket.references index bdc56d3..a0379c9 100644 --- a/src/paket.references +++ b/src/paket.references @@ -1,3 +1,3 @@ FSharp.Core -Fable.Core.Experimental \ No newline at end of file +Fable.Core \ No newline at end of file diff --git a/test/paket.references b/test/paket.references index 196a4ed..e02e67c 100644 --- a/test/paket.references +++ b/test/paket.references @@ -1,7 +1,7 @@ group Test FSharp.Core -Fable.Core.Experimental +Fable.Core Microsoft.NET.Test.Sdk