-
Notifications
You must be signed in to change notification settings - Fork 2
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 #6 from lobis/2-javascript-nodejs-bindings
nodejs bindings - not complete
- Loading branch information
Showing
17 changed files
with
392 additions
and
29 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 |
---|---|---|
|
@@ -130,3 +130,5 @@ dmypy.json | |
|
||
.idea/ | ||
.vscode/ | ||
|
||
node_modules/ |
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,6 +1,20 @@ | ||
repos: | ||
|
||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.4.0 | ||
hooks: | ||
- id: check-added-large-files | ||
- id: check-case-conflict | ||
- id: check-merge-conflict | ||
- id: check-symlinks | ||
- id: check-yaml | ||
- id: check-xml | ||
- id: requirements-txt-fixer | ||
- id: end-of-file-fixer | ||
- id: mixed-line-ending | ||
- id: trailing-whitespace | ||
|
||
- repo: https://github.com/psf/black | ||
rev: 22.10.0 | ||
rev: 23.3.0 | ||
hooks: | ||
- id: black |
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,21 +1,28 @@ | ||
MIT License | ||
BSD 3-Clause License | ||
|
||
Copyright (c) 2022 Luis Antonio Obis Aparicio | ||
Copyright (c) 2023, Luis Antonio Obis Aparicio | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
1. Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
2. Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
3. Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
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,25 @@ | ||
const { ExecutionContext } = require('./index'); | ||
const yargs = require('yargs'); | ||
|
||
const cli = yargs | ||
.scriptName('hvps') | ||
.usage('$0 <cmd> [args]') | ||
.option('python', { | ||
description: 'Specify the Python path to run HVPS.', | ||
alias: 'p', | ||
type: 'string', | ||
default: 'python', // Set a default string value | ||
}) | ||
.help() | ||
.alias('h', 'help') | ||
.argv; | ||
|
||
// check python is available | ||
const context = new ExecutionContext(cli.python); | ||
context.print(); | ||
|
||
// Get the remaining arguments as a string | ||
const remainingArgs = cli._.join(' '); | ||
// these should be passed to the python code. TODO: not working! | ||
|
||
context.run(remainingArgs); |
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,62 @@ | ||
const { execSync } = require('child_process'); | ||
|
||
|
||
class ExecutionContext { | ||
constructor(pythonPath) { | ||
this.python = pythonPath; | ||
// check if python path is correct and use absolute path | ||
this.python = this.getPythonPath(); | ||
|
||
// check if the hvps package is available | ||
this.getPackageVersion(); | ||
} | ||
|
||
getPythonVersion() { | ||
const command = `${this.python} -c "import sys; print(sys.version)"`; | ||
try { | ||
return execSync(command, { encoding: 'utf-8' }).trim(); | ||
} catch (err) { | ||
console.error(`Error executing command (${command}): ${err}`); | ||
throw err; | ||
} | ||
} | ||
|
||
getPythonPath() { | ||
const command = `${this.python} -c "import sys; print(sys.executable)"`; | ||
try { | ||
return execSync(command, { encoding: 'utf-8' }).trim(); | ||
} catch (err) { | ||
console.error(`Error executing command (${command}): ${err}`); | ||
throw err; | ||
} | ||
} | ||
|
||
getPackageVersion() { | ||
const command = `${this.python} -m hvps --version`; | ||
try { | ||
return execSync(command, { encoding: 'utf-8' }).trim(); | ||
} catch (err) { | ||
throw new Error(`Error executing command (${command}). Please make sure the package is installed.`); | ||
} | ||
} | ||
|
||
print() { | ||
console.log(`Python version: ${this.getPythonVersion()}`); | ||
console.log(`Python path: ${this.getPythonPath()}`); | ||
console.log(`Package version: ${this.getPackageVersion()}`); | ||
} | ||
|
||
// run method should call the python script with the arguments | ||
run(args) { | ||
const command = `${this.python} -m hvps ${args}`; | ||
try { | ||
return execSync(command, { encoding: 'utf-8' }).trim(); | ||
} catch (err) { | ||
throw new Error(`Error executing command (${command}): ${err}`); | ||
} | ||
} | ||
} | ||
|
||
module.exports = { | ||
ExecutionContext, | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "hvps", | ||
"version": "0.0.1", | ||
"description": "Bindings for the HVPS python package", | ||
"main": "index.js", | ||
"bin": { | ||
"hvps": "cli.js" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/lobis/hvps.git" | ||
}, | ||
"author": "Luis Antonio Obis Aparicio (@lobis)", | ||
"license": "BSD-3-Clause", | ||
"bugs": { | ||
"url": "https://github.com/lobis/hvps/issues" | ||
}, | ||
"homepage": "https://github.com/lobis/hvps#readme", | ||
"dependencies": { | ||
"yargs": "^17.7.2" | ||
} | ||
} |
Oops, something went wrong.