-
Notifications
You must be signed in to change notification settings - Fork 5
move python side of workbench to the invest repo #72
Changes from 24 commits
6f75e19
00400c3
1026ff2
07ff357
8e74648
0753359
5e5a905
36d5444
4d217e9
11bd67f
a3468b0
eda948e
6cf63fc
47b572c
c7e8d8c
f00dff3
7ea16cd
1c54f78
cedf89d
80ff6d2
d468d51
55add42
10330d4
5fe3c2e
9e42849
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,29 +9,34 @@ workflows of an InVEST user. | |
## To develop and launch this Application | ||
|
||
* `npm install` | ||
* clone natcap.invest and checkout a recent revision (e.g. `main`) | ||
* setup a conda* environment with deps for `natcap.invest Flask PyInstaller` | ||
* build invest binaries | ||
`python -m PyInstaller --workpath build/pyi-build --clean --distpath build ./invest-flask.spec` | ||
* `npm start` | ||
* bind to an `invest` executeable (see package.json "invest" for a compatible version) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Related to this and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it will be changed frequenty, but yes, the "invest" property will need to be updated to whatever version of invest we want packaged with the workbench. Maybe in the future we would want to programmaticaly default to the latest invest release, but for now hardcoding the invest version in package.json seems okay to me. |
||
|
||
(* invest-flask.spec script assumes a conda environment) | ||
In production, the invest exe comes from prebuilt binaries that are an artifact of the `invest` build process. | ||
|
||
## To build this application | ||
For development, choose either: | ||
**A.** Duplicate the production setup by fetching prebuilt binaries `npm run fetch-invest` | ||
**B.** Use an any other locally installed, compatible, invest CLI (e.g. from a local python environment). To configure this, see `.env-example` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo Use an any |
||
|
||
`npm run build` -- calls babel to transpile ES6 and jsx code to commonjs | ||
* `npm start` | ||
|
||
`npm run dist` -- packages build source into an electron application using electron-builder | ||
## To package this app for distribution | ||
|
||
`npm run build` - calls babel to transpile ES6 and jsx code to commonjs; moves other resources (CSS, JSON) to the build directory | ||
|
||
### To run linter or tests | ||
`npm run dist` - packages build source into an electron application using electron-builder | ||
|
||
|
||
### To run various scripts and local programs | ||
See the "scripts" section of `package.json` and run them like: | ||
`npm run lint` | ||
`npm run test` | ||
|
||
To run these or other command-line utils of locally installed packages outside the context of the `package.json scripts`, use `npx` (e.g. `npx eslint ...`) as a shortcut to the executeable. | ||
To run other scripts or CLIs of locally installed packages, | ||
prefix commands with `npx` (e.g. `npx eslint ...`). Otherwise, only | ||
globally installed packages are on the PATH. | ||
Comment on lines
+35
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, thank you. |
||
|
||
### To run a single test file: | ||
#### E.g. run a single test file: | ||
`npx jest --coverage=false --verbose app.test.js` | ||
|
||
To run snippets of code outside the electron runtime, but with the same ECMAscript features and babel configurations, use `node -r @babel/register script.js`. | ||
To run javascript outside the electron runtime, but with the same ECMAscript features and babel configurations, use `node -r @babel/register script.js`. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
const https = require('https'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const url = require('url'); | ||
const pkg = require('../package'); | ||
|
||
let filePrefix; | ||
// The invest build process only builds for these OS | ||
// The prefixes on the zip file are defined by invest's Makefile $OSNAME | ||
switch (process.platform) { | ||
case 'win32': | ||
filePrefix = 'windows'; | ||
break; | ||
case 'darwin': | ||
filePrefix = 'mac'; | ||
break; | ||
default: | ||
throw new Error( | ||
`No prebuilt invest binaries are available for ${process.platform}` | ||
); | ||
} | ||
|
||
const HOSTNAME = pkg.invest.hostname; | ||
const BUCKET = pkg.invest.bucket; | ||
const FORK = pkg.invest.fork; | ||
const VERSION = pkg.invest.version; | ||
const SRCFILE = `${filePrefix}_invest_binaries.zip`; | ||
const DESTFILE = path.resolve('build/binaries.zip'); | ||
|
||
const urladdress = url.resolve( | ||
HOSTNAME, path.join(BUCKET, FORK, VERSION, SRCFILE) | ||
); | ||
|
||
/** | ||
* Download a file from src to dest. | ||
* | ||
* @param {string} src - url for a single publicly hosted file | ||
* @param {string} dest - local path for saving the file | ||
*/ | ||
function download(src, dest) { | ||
console.log(`downloading ${src}`); | ||
fs.existsSync(path.dirname(dest)) || fs.mkdirSync(path.dirname(dest)); | ||
const fileStream = fs.createWriteStream(dest); | ||
https.get(src, (response) => { | ||
console.log(`http status: ${response.statusCode}`); | ||
if (response.statusCode !== 200) { | ||
fileStream.close(); | ||
return; | ||
} | ||
response.pipe(fileStream); | ||
fileStream.on('finish', () => { | ||
fileStream.close(); | ||
}); | ||
}).on('error', (e) => { | ||
console.log(e); | ||
}); | ||
} | ||
|
||
download(urladdress, DESTFILE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was the reason for dropping
npx
just because it's not really needed?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah,
npx
was pretty redundant inside this "scripts" context. I mainly usenpx
because it searches the local node_modules first for CLIs like electron, etc. But the "scripts" context already ensures that, I've since learned.