-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #373 from informatics-lab/forestjs
ForestJS
- Loading branch information
Showing
10 changed files
with
114 additions
and
18 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
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,19 @@ | ||
const helloWorld = () => "Hello, World!" | ||
|
||
|
||
// Populate variable options from dataset value | ||
const link_selects = function(dataset_select, variable_select, source) { | ||
let label = dataset_select.value; | ||
if (label !== "") { | ||
let index = source.data['datasets'].indexOf(label) | ||
let defaults = ["Please specify"]; | ||
variable_select.options = defaults.concat( | ||
source.data['variables'][index]); | ||
} | ||
} | ||
|
||
|
||
module.exports = { | ||
helloWorld, | ||
link_selects | ||
} |
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,8 @@ | ||
const forest = require("./forest") | ||
|
||
|
||
describe("helloWorld", () => { | ||
it("should return message", () => { | ||
expect(forest.helloWorld()).toEqual("Hello, World!") | ||
}) | ||
}) |
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,2 @@ | ||
window.forest = require('./forest') | ||
|
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,20 @@ | ||
{ | ||
"name": "forestjs", | ||
"version": "0.0.1", | ||
"description": "Helper JS for FOREST Python library", | ||
"main": "index.js", | ||
"dependencies": { | ||
"redux": "^4.0.5" | ||
}, | ||
"devDependencies": { | ||
"browserify": "^16.5.1", | ||
"jest": "^26.0.1" | ||
}, | ||
"scripts": { | ||
"test": "jest", | ||
"watch": "jest --watch ./*.test.js", | ||
"build": "browserify main.js -o ../static/forest-min.js" | ||
}, | ||
"author": "andrewgryan", | ||
"license": "BSD-3-Clause" | ||
} |
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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
bokeh>=2.0.1 # Port to 2.0.0 in future | ||
nodejs>=10.13 | ||
datashader | ||
h5netcdf | ||
iris | ||
|
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 |
---|---|---|
|
@@ -3,7 +3,11 @@ | |
""" | ||
import os | ||
import re | ||
import subprocess | ||
import setuptools | ||
import setuptools.command.build_py | ||
import setuptools.command.develop | ||
import setuptools.command.install | ||
|
||
|
||
NAME = "forest" | ||
|
@@ -27,11 +31,57 @@ def load(fname): | |
return result | ||
|
||
|
||
def build_js(command_subclass): | ||
"""Decorator to call npm install and npm run build""" | ||
subclass_run = command_subclass.run | ||
def run(self): | ||
self.run_command("build_js") | ||
subclass_run(self) | ||
command_subclass.run = run | ||
return command_subclass | ||
|
||
|
||
@build_js | ||
class InstallCommand(setuptools.command.install.install): | ||
"""Python and JS code""" | ||
|
||
|
||
@build_js | ||
class DevelopCommand(setuptools.command.develop.develop): | ||
"""Python and JS code""" | ||
|
||
|
||
@build_js | ||
class BuildPyCommand(setuptools.command.build_py.build_py): | ||
"""Python and JS code""" | ||
|
||
|
||
class BuildJSCommand(setuptools.command.build_py.build_py): | ||
"""Use nodejs and npm commands to browserify forest.js | ||
.. note:: Assume current working directory is package ROOT | ||
""" | ||
def run(self): | ||
cwd = os.getcwd() | ||
os.chdir("forest/js") | ||
if not os.path.exists("node_modules"): | ||
subprocess.check_call(["npm", "install"]) | ||
subprocess.check_call(["npm", "run", "build"]) | ||
os.chdir(cwd) | ||
super().run() | ||
|
||
|
||
setuptools.setup( | ||
name=NAME, | ||
version=find_version(), | ||
author="Andrew Ryan", | ||
author_email="[email protected]", | ||
cmdclass={ | ||
"install": InstallCommand, | ||
"develop": DevelopCommand, | ||
"build_py": BuildPyCommand, | ||
"build_js": BuildJSCommand, | ||
}, | ||
description="Forecast visualisation and survey tool", | ||
packages=setuptools.find_packages(), | ||
package_data={ | ||
|
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,12 @@ | ||
import os | ||
import subprocess | ||
|
||
|
||
JS_DIR = os.path.join(os.path.dirname(__file__), "../forest/js") | ||
|
||
|
||
def test_forestjs(): | ||
cwd = os.getcwd() | ||
os.chdir(JS_DIR) | ||
subprocess.check_call(["npm", "test"]) | ||
os.chdir(cwd) |