This repository has been archived by the owner on Jan 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Python and R bindings): Initial versions of bindings for Python …
…and R
- Loading branch information
Showing
13 changed files
with
618 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,5 @@ | |
/dist | ||
/node_modules | ||
.DS_Store | ||
|
||
### Generated files ### | ||
types.ts | ||
/.mypy_cache | ||
*.out.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,4 @@ built | |
dist | ||
node_modules | ||
public | ||
|
||
### Generated files ### | ||
types.ts | ||
.mypy_cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
Any <- function () { | ||
self <- list() | ||
class(self) <- "Any" | ||
self | ||
} | ||
|
||
format.Any <- function (type) { | ||
"Any()" | ||
} | ||
|
||
Array <- function (items) { | ||
self <- list(items=items) | ||
class(self) <- "Array" | ||
self | ||
} | ||
|
||
format.Array <- function (type) { | ||
paste0("Array(", paste(sapply(type$items, format), collapse=", "), ")") | ||
} | ||
|
||
Union <- function (...) { | ||
self <- list(types=as.character(c(...))) | ||
class(self) <- "Union" | ||
self | ||
} | ||
|
||
format.Union <- function (type) { | ||
paste0("Union(", paste(sapply(type$types, format), collapse=", "), ")") | ||
} | ||
|
||
isType <- function (value, type) { | ||
if(class(type) == "Any") { | ||
TRUE | ||
} else if (class(type) == "character") { | ||
type_obj <- get(type) | ||
if (class(type_obj) %in% c('Any', 'Array', 'Union')) isType(value, type_obj) | ||
else inherits(value, type) | ||
} else if (class(type) == "Array") { | ||
if(class(value) != "list") return(FALSE) | ||
for(item in value) { | ||
if(!isType(item, type$items)) return(FALSE) | ||
} | ||
TRUE | ||
} else if(class(type) == "Union") { | ||
inherits(value, type$types) | ||
} else { | ||
FALSE | ||
} | ||
} | ||
|
||
assertType <- function (value, type) { | ||
if(!isType(value, type)) stop(paste("value is type", class(value), "not expected type", format(type)), call. = FALSE) | ||
value | ||
} | ||
|
||
setProp <- function (node, name, type, value) { | ||
if(!isType(value, type)) stop(paste("value for", name, "is type", class(value), "not expected type", format(type)), call. = FALSE) | ||
node[[name]] <- value | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
export PYTHONPATH=${PYTHONPATH}:${PWD} | ||
|
||
python3 tests/article.py | ||
|
||
mypy tests/article.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import types |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
Rscript tests/article.R |
Oops, something went wrong.