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

Python integration #317

Merged
merged 25 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
32a4128
add hashcode tests
HLWeil Dec 8, 2023
92c72ee
array fixes in python compilation
HLWeil Dec 13, 2023
2d35cfb
update Fable and pyxpecto
HLWeil Jan 26, 2024
f0bb78d
switch towards using .venv for running transpiled python
HLWeil Feb 23, 2024
aa30389
move json schema validation to json tests
HLWeil Feb 23, 2024
93b6d94
replace mocha and expecto with pyxpecto
HLWeil Feb 23, 2024
688c628
work on json io support in python
HLWeil Feb 23, 2024
3dfaad7
adjustments to web and validation to allowe for python transpilation
HLWeil Feb 26, 2024
2540056
small fix for compressed json io stringtable conversion
HLWeil Feb 26, 2024
c534acf
fix and test comment regex handling for python
HLWeil Feb 27, 2024
556e2bf
fix http requests in python
HLWeil Feb 27, 2024
b5eaaed
hotfix fable python hashing of person
HLWeil Feb 27, 2024
66b83a2
several small changes to test stack
HLWeil Feb 28, 2024
9385d06
small fixes in python and setup instructions
HLWeil Mar 1, 2024
f75ce4d
small python tests hotfix
HLWeil Mar 1, 2024
4262833
hotfix js webrequest
HLWeil Mar 1, 2024
89aa3c2
fixed python tests to work on all platforms
floWetzels Mar 5, 2024
df663cb
include python setup in CI
HLWeil Mar 5, 2024
b0186f4
small fix to CI
HLWeil Mar 5, 2024
3e403cd
small fix to CI
HLWeil Mar 5, 2024
890048e
set ci fail-fast to false and fix py encoding in windows
HLWeil Mar 6, 2024
8becc67
update build project for releasing python package
HLWeil Mar 6, 2024
19d850e
several small cleanups according to PR #317 comments
HLWeil Mar 7, 2024
78914e0
bump to 1.2.0
HLWeil Mar 8, 2024
b6e2eca
small change to semver in npm
HLWeil Mar 8, 2024
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
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"fable": {
"version": "4.6.0",
"version": "4.13.0",
"commands": [
"fable"
]
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,24 @@ jobs:
test:

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3

# SETUP .NET
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.x.x
- name: Restore fable
run: dotnet tool restore

# SETUP NODE
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
Expand All @@ -33,6 +38,28 @@ jobs:
- name: install node modules ISA
working-directory: ./src/ISA
run: npm install

# SETUP PYTHON
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Setup Virtual Environment
run: python -m venv .venv
- name: Setup Poetry Windows
if: matrix.os == 'windows-latest'
run: |
.\.venv\Scripts\python.exe -m pip install -U pip setuptools
.\.venv\Scripts\python.exe -m pip install poetry
.\.venv\Scripts\python.exe -m poetry install --no-root
- name: Setup Poetry Unix
if: matrix.os == 'ubuntu-latest'
run: |
./.venv/bin/python -m pip install -U pip setuptools
./.venv/bin/python -m pip install poetry
./.venv/bin/python -m poetry install --no-root

# BUILD
- name: make script executable
if: matrix.os == 'ubuntu-latest'
run: chmod u+x build.sh
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ paket-files/
# Custom ignored files
dist/
tmp/
/.venv
/tests/JavaScript/ARCtrl
/tests/Python/ARCtrl
/tests/UI/ARCtrl
Expand Down
1 change: 1 addition & 0 deletions ARCtrl.sln
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.config\dotnet-tools.json = .config\dotnet-tools.json
global.json = global.json
package.json = package.json
pyproject.toml = pyproject.toml
README.md = README.md
RELEASE_NOTES.md = RELEASE_NOTES.md
EndProjectSection
Expand Down
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ and __JavaScript__! ❤️
```

```bash
<PackageReference Include="ARCtrl" Version="1.0.0-beta.1" />
<PackageReference Include="ARCtrl" Version="1.1.0" />
```

### JavaScript
Expand All @@ -44,10 +44,27 @@ Currently we provide some documentation in form of markdown files in the `/docs`
- verify with `npm --version` (Tested with v9.2.0)
- [.NET SDK](https://dotnet.microsoft.com/en-us/download)
- verify with `dotnet --version` (Tested with 7.0.306)
- [Python](https://www.python.org/downloads/)
- verify with `py --version` (Tested with 3.12.2)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a note for minimal 3.11.x


### Local Setup

1. `dotnet tool restore`
3. `npm install`
1. Setup dotnet tools

`dotnet tool restore`

2. Install NPM dependencies

`npm install`

3. Setup python environment

`py -m venv .venv`

4. Install [Poetry](https://python-poetry.org/) and dependencies

1. `.\.venv\Scripts\python.exe -m pip install -U pip setuptools`
2. `.\.venv\Scripts\python.exe -m pip install poetry`
3. `.\.venv\Scripts\python.exe -m poetry install --no-root`

Verify correct setup with `./build.cmd runtests` ✨
1 change: 1 addition & 0 deletions build.cmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@echo off

set PYTHONIOENCODING=utf-8
dotnet tool restore
cls
dotnet run --project ./build/build.fsproj %*
118 changes: 117 additions & 1 deletion build/BasicTasks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,122 @@ open Fake.IO.Globbing.Operators

open ProjectInfo

[<AutoOpen>]
module Helper =

open Fake
open Fake.Core

let createProcess exe arg dir =
CreateProcess.fromRawCommandLine exe arg
|> CreateProcess.withWorkingDirectory dir
|> CreateProcess.ensureExitCode

module Proc =

module Parallel =

open System

let locker = obj()

let colors = [|
ConsoleColor.DarkYellow
ConsoleColor.DarkCyan
ConsoleColor.Magenta
ConsoleColor.Blue
ConsoleColor.Cyan
ConsoleColor.DarkMagenta
ConsoleColor.DarkBlue
ConsoleColor.Yellow
|]

let print color (colored: string) (line: string) =
lock locker
(fun () ->
let currentColor = Console.ForegroundColor
Console.ForegroundColor <- color
Console.Write colored
Console.ForegroundColor <- currentColor
Console.WriteLine line)

let onStdout index name (line: string) =
let color = colors.[index % colors.Length]
if isNull line then
print color $"{name}: --- END ---" ""
else if String.isNotNullOrEmpty line then
print color $"{name}: " line

let onStderr name (line: string) =
let color = ConsoleColor.Red
if isNull line |> not then
print color $"{name}: " line

let redirect (index, (name, createProcess)) =
createProcess
|> CreateProcess.redirectOutputIfNotRedirected
|> CreateProcess.withOutputEvents (onStdout index name) (onStderr name)

let printStarting indexed =
for (index, (name, c: CreateProcess<_>)) in indexed do
let color = colors.[index % colors.Length]
let wd =
c.WorkingDirectory
|> Option.defaultValue ""
let exe = c.Command.Executable
let args = c.Command.Arguments.ToStartInfo
print color $"{name}: {wd}> {exe} {args}" ""

let run cs =
cs
|> Seq.toArray
|> Array.indexed
|> fun x -> printStarting x; x
|> Array.map redirect
|> Array.Parallel.map Proc.run

let dotnet = createProcess "dotnet"

let npx =
let npmPath =
match ProcessUtils.tryFindFileOnPath "npx" with
| Some path -> path
| None ->
"npm was not found in path. Please install it and make sure it's available from your path. " +
"See https://safe-stack.github.io/docs/quickstart/#install-pre-requisites for more info"
|> failwith

createProcess npmPath

let npm =
let npmPath =
match ProcessUtils.tryFindFileOnPath "npm" with
| Some path -> path
| None ->
"npm was not found in path. Please install it and make sure it's available from your path. " +
"See https://safe-stack.github.io/docs/quickstart/#install-pre-requisites for more info"
|> failwith

createProcess npmPath

let python =
if System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows) then
Fake.Core.Trace.log "Detected Windows System."
createProcess (__SOURCE_DIRECTORY__.Replace(@"\build",@"\.venv\Scripts\python.exe"))
else
Fake.Core.Trace.log "Detected Unix System."
createProcess (__SOURCE_DIRECTORY__.Replace(@"/build",@"/.venv/bin/python"))

let run proc arg dir =
proc arg dir
|> Proc.run
|> ignore

let runParallel processes =
processes
|> Proc.Parallel.run
|> ignore

let setPrereleaseTag = BuildTask.create "SetPrereleaseTag" [] {
printfn "Please enter pre-release package suffix"
let suffix = System.Console.ReadLine()
Expand All @@ -21,7 +137,7 @@ let clean = BuildTask.create "Clean" [] {
++ "tests/**/bin"
++ "tests/**/obj"
++ "dist"
++ ProjectInfo.pkgDir
++ ProjectInfo.netPkgDir
|> Shell.cleanDirs
}

Expand Down
2 changes: 1 addition & 1 deletion build/Build.fs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ open ReleaseTasks
let _release =
BuildTask.createEmpty
"Release"
[clean; build; runTests; pack; createTag; publishNuget; publishNPM]
[clean; build; runTests; pack; createTag; publishNuget; publishNPM; publishPyPi]

/// Full release of nuget package for the prerelease version.
let _preRelease =
Expand Down
1 change: 1 addition & 0 deletions build/Build.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<Compile Include="ReleaseNotesTasks.fs" />
<Compile Include="BasicTasks.fs" />
<Compile Include="GenerateIndexJs.fs" />
<Compile Include="GenerateIndexPy.fs" />
<Compile Include="TestTasks.fs" />
<Compile Include="PackageTasks.fs" />
<Compile Include="ReleaseTasks.fs" />
Expand Down
49 changes: 49 additions & 0 deletions build/GenerateIndexPy.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module GenerateIndexPy

open System
open System.IO
open System.Text.RegularExpressions


open System.Text

let createImportStatement path (classes : string []) =
let classes = classes |> Array.reduce (fun acc x -> acc + ", " + x)
sprintf "from %s import %s" path classes

let writePyIndexfile (path: string) (content: string) =
let filePath = Path.Combine(path, "arctrl.py")
File.WriteAllText(filePath, content)

let generateIndexFileContent (classes : (string*string) []) =
classes
|> Array.groupBy fst
|> Array.map (fun (p,a) -> createImportStatement p (a |> Array.map snd))

let classes =
[|
"__future__", "annotations"
"collections.abc", "Callable"
"typing", "Any"
".ISA.ISA.JsonTypes.comment", "Comment"
".ISA.ISA.JsonTypes.ontology_annotation","OntologyAnnotation";
".ISA.ISA.JsonTypes.person", "Person";
".ISA.ISA.JsonTypes.publication", "Publication";
".ISA.ISA.ArcTypes.composite_header", "IOType"
".ISA.ISA.ArcTypes.composite_header", "CompositeHeader";
".ISA.ISA.ArcTypes.composite_cell", "CompositeCell"
".ISA.ISA.ArcTypes.composite_column", "CompositeColumn"
".ISA.ISA.ArcTypes.arc_table", "ArcTable"
".ISA.ISA.ArcTypes.arc_types", "ArcAssay";
".ISA.ISA.ArcTypes.arc_types", "ArcStudy";
".ISA.ISA.ArcTypes.arc_types", "ArcInvestigation";
".Templates.template", "Template"
".Templates.templates", "Templates"
".Templates.template", "Organisation"
".arc","ARC"
|]

let ARCtrl_generate (rootPath: string) =
generateIndexFileContent classes
|> Array.reduce (fun a b -> a + "\n" + b)
|> writePyIndexfile rootPath
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

Loading
Loading