Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] PyO3 walking skeleton for Python #3804

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
Draft
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: 2 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,15 @@ jobs:
- name: Setup dotnet tools
run: dotnet tool restore

# - name: Check F# formatting (fantomas)
# run: dotnet fantomas src/Fable.Transforms/Python --check

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install poetry
run: |
pip install poetry
pipx install poetry
pipx install maturin

- name: Fable Library - Python (linux)
if: matrix.platform == 'ubuntu-latest'
Expand Down
69 changes: 49 additions & 20 deletions poetry.lock

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

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ python-dateutil = "^2.9.0"
[tool.poetry.dev-dependencies]
pytest = "^8.1.1"
ruff = "^0.3.4"
maturin = "^1.5.0"

[tool.pyright]
reportMissingTypeStubs = false
Expand Down
31 changes: 18 additions & 13 deletions src/Fable.Build/FableLibrary/Core.fs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,23 @@ type BuildFableLibrary
abstract member CopyStage: unit -> unit
default _.CopyStage() = ()

abstract member FableBuildStage: unit -> unit

default this.FableBuildStage() =
let args =
CmdLine.appendRaw sourceDir
>> CmdLine.appendPrefix "--outDir" outDir
>> CmdLine.appendPrefix "--fableLib" fableLibArg
>> CmdLine.appendPrefix "--lang" language
>> CmdLine.appendPrefix "--exclude" "Fable.Core"
>> CmdLine.appendPrefix "--define" "FABLE_LIBRARY"
>> CmdLine.appendRaw "--noCache"
// Target implementation can require additional arguments
>> this.FableArgsBuilder

Command.Fable(args)


member this.Run(?skipIfExist: bool) =
let skipIfExist = defaultArg skipIfExist false

Expand All @@ -63,19 +80,7 @@ type BuildFableLibrary
Directory.Delete(buildDir, true)

Calm "Building Fable.Library" |> toConsole

let args =
CmdLine.appendRaw sourceDir
>> CmdLine.appendPrefix "--outDir" outDir
>> CmdLine.appendPrefix "--fableLib" fableLibArg
>> CmdLine.appendPrefix "--lang" language
>> CmdLine.appendPrefix "--exclude" "Fable.Core"
>> CmdLine.appendPrefix "--define" "FABLE_LIBRARY"
>> CmdLine.appendRaw "--noCache"
// Target implementation can require additional arguments
>> this.FableArgsBuilder

Command.Fable(args)
this.FableBuildStage()

Calm "Copy stage" |> toConsole
this.CopyStage()
Expand Down
27 changes: 27 additions & 0 deletions src/Fable.Build/FableLibrary/Python.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ open System.IO
open Fake.IO
open Build.Utils
open SimpleExec
open BlackFox.CommandLine

type BuildFableLibraryPython() =
inherit
Expand All @@ -15,17 +16,43 @@ type BuildFableLibraryPython() =
Path.Combine("temp", "fable-library-py", "fable_library")
)

override this.FableBuildStage() =
let args =
CmdLine.appendRaw this.SourceDir
>> CmdLine.appendPrefix "--outDir" this.OutDir
>> CmdLine.appendPrefix "--fableLib" "."
>> CmdLine.appendPrefix "--lang" this.Language
>> CmdLine.appendPrefix "--exclude" "Fable.Core"
>> CmdLine.appendPrefix "--define" "FABLE_LIBRARY"
>> CmdLine.appendRaw "--noCache"
// Target implementation can require additional arguments
>> this.FableArgsBuilder

Command.Fable(args)


override this.CopyStage() =
// // Copy all *.rs files to the build directory
Directory.GetFiles(this.LibraryDir, "*") |> Shell.copyFiles this.BuildDir

Directory.GetFiles(this.SourceDir, "*.py") |> Shell.copyFiles this.OutDir
// Python extension modules
Directory.GetFiles(Path.Combine(this.SourceDir, "core"), "*")
|> Shell.copyFiles (Path.Combine(this.OutDir, "core"))
// Rust sources for building the extension modules
Directory.GetFiles(Path.Combine(this.LibraryDir, "src"), "*")
|> Shell.copyFiles (Path.Combine(this.BuildDir, "src"))


override this.PostFableBuildStage() =
// Fix issues with Fable .fsproj not supporting links
let linkedFileFolder =
Path.Combine(this.BuildDir, "fable_library", "fable-library-ts")

Command.Run("poetry", "config virtualenvs.in-project true", this.BuildDir)
Command.Run("poetry", "install", this.BuildDir) // Maturn needs a local virtual environment
Command.Run("maturin", "develop --release", this.BuildDir)

Directory.GetFiles(linkedFileFolder, "*") |> Shell.copyFiles this.OutDir

Shell.deleteDir (this.BuildDir </> "fable_library/fable-library-ts")
Expand Down
Loading
Loading