diff --git a/.all-contributorsrc b/.all-contributorsrc index 7dcd0d9258..a0092aa7a9 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1466,6 +1466,15 @@ "contributions": [ "bug" ] + }, + { + "login": "jmalins", + "name": "Jeff Malins", + "avatar_url": "https://avatars.githubusercontent.com/u/2001356?v=4", + "profile": "https://github.com/jmalins", + "contributions": [ + "code" + ] } ], "repoType": "github", diff --git a/README.md b/README.md index 5fcd7d82f0..f8601f87ae 100644 --- a/README.md +++ b/README.md @@ -137,114 +137,115 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Jason Fulghum

🤔 📆 👀 +
Jeff Malins

💻
Jerry Kindall

📖 🤔
Jimmy Gaussen

🤔
Johannes Weber

📖
Jon Steinich

🐛 🤔 💻
Joseph Lawson

👀
Joseph Martin

🐛 -
Junix

🐛 +
Junix

🐛
Justin Frahm

🐛
Justin Taylor

🐛
Kaizen Conroy

💻 🐛
Kaizen Conroy

💻
Kaushik Borra

🐛
Kyle Thomson

💻 👀 -
Leandro Padua

🐛 +
Leandro Padua

🐛
Liang Zhou

🐛 💻
Madeline Kusters

💻 🐛
Maja S Bratseth

🐛
Marcos Diez

🐛
Mark Nielsen

💻
Matthew Bonig

🐛 📝 -
Matthew Pirocchi

💻 🤔 👀 +
Matthew Pirocchi

💻 🤔 👀
Meng Xin Zhu

🐛
Michael Neil

🚧
Mike Lane

🐛
Mitch Garnaat

🐛 💻 🤔 👀
Mitchell Valine

🐛 💻 🤔 🚧 👀
Mohamad Soufan

📖 -
Mykola Mogylenko

🐛 +
Mykola Mogylenko

🐛
Naumel

👀
Neta Nir

💻 🤔 🚧 👀
Nick Lynch

🐛 💻 🚧 👀
Niranjan Jayakar

🐛 💻 🤔 🚧 👀
Noah Litov

💻 🚧 👀
Otavio Macedo

💻 🐛 -
PIDZ - Bart

🤔 +
PIDZ - Bart

🤔
Peter Woodworth

🚧
Petr Kacer

🐛
Petra Barus

💻
Philip Cali

🤔
Quentin Loos

🤔
Raphael

🐛 -
Richard H Boyd

🐛 +
Richard H Boyd

🐛
Rico Huijbers

🐛 💻 🤔 🚧 👀
Romain Marcadier

🐛 💻 🎨 🤔 🚧 👀 📝
SADIK KUZU

👀
SK

🤔
Sam Fink

💻 👀
Sam Goodwin

👀 -
Sebastian Korfmann

🐛 💻 🤔 +
Sebastian Korfmann

🐛 💻 🤔
Sepehr Laal

🐛
Shane Witbeck

🤔
Shiv Lakshminarayan

💻 🚧 👀
Somaya

💻 🤔 🚧 👀
Stephen Kuenzli

📖
Takahiro Sugiura

📖 -
The Gitter Badger

💻 🚧 +
The Gitter Badger

💻 🚧
Thomas Poignant

🐛
Thomas Steinbach

🐛
Thorsten Hoeger

💻
Tim Wagner

🐛 🤔
Tobias Lidskog

💻
Ty Coghlan

🐛 -
Tyler van Hensbergen

🤔 +
Tyler van Hensbergen

🤔
Vlad Hrybok

🐛
Vladimir Shchur

🐛
Yan Zhulanow

💻
Yigong Liu

🐛 🤔
Zach Bienenfeld

🐛
ajnarang

🤔 -
aniljava

💻 +
aniljava

💻
arnogeurts-sqills

🐛 💻
cn-cit

🐛
deccy-mcc

🐛
dependabot-preview[bot]

🐛 🚧
dependabot[bot]

🚧
dheffx

🐛 -
gregswdl

🐛 +
gregswdl

🐛
guyroberts21

📖
mattBrzezinski

📖
mergify

🚧
mergify[bot]

🚧
nathannaveen

🚧
seiyashima42

🐛 💻 📖 -
sullis

💻 +
sullis

💻
vaneek

🐛
wendysophie

🐛 diff --git a/packages/@jsii/kernel/src/kernel.test.ts b/packages/@jsii/kernel/src/kernel.test.ts index c87bde929c..045b2feafe 100644 --- a/packages/@jsii/kernel/src/kernel.test.ts +++ b/packages/@jsii/kernel/src/kernel.test.ts @@ -2144,10 +2144,27 @@ defineTest('invokeBinScript() return output', (sandbox) => { script: 'calc', }); - expect(result.stdout).toEqual('Hello World!\n'); - expect(result.stderr).toEqual(''); - expect(result.status).toEqual(0); - expect(result.signal).toBeNull(); + expect(result).toMatchObject({ + status: 0, + stdout: 'Hello World!\n', + stderr: '', + signal: null, + }); +}); + +defineTest('invokeBinScript() accepts arguments', (sandbox) => { + const result = sandbox.invokeBinScript({ + assembly: 'jsii-calc', + script: 'calc', + args: ['arg1', 'arg2'], + }); + + expect(result).toMatchObject({ + status: 0, + stdout: 'Hello World!\n arguments: arg1, arg2\n', + stderr: '', + signal: null, + }); }); // ================================================================================================= diff --git a/packages/@jsii/python-runtime/src/jsii/_runtime.py b/packages/@jsii/python-runtime/src/jsii/_runtime.py index fafbac565f..80bbdd708e 100644 --- a/packages/@jsii/python-runtime/src/jsii/_runtime.py +++ b/packages/@jsii/python-runtime/src/jsii/_runtime.py @@ -1,9 +1,10 @@ import abc import os +import sys import attr -from typing import cast, Any, Callable, List, Optional, Mapping, Type, TypeVar +from typing import Sequence, cast, Any, Callable, List, Optional, Mapping, Type, TypeVar from . import _reference_map from ._compat import importlib_resources @@ -47,10 +48,23 @@ def load(cls, *args, _kernel=kernel, **kwargs) -> "JSIIAssembly": @classmethod def invokeBinScript( - cls, pkgname: str, script: str, *args: str, _kernel=kernel - ) -> None: + cls, + pkgname: str, + script: str, + args: Optional[Sequence[str]] = None, + _kernel=kernel, + ) -> int: + if args is None: + args = [] + response = _kernel.invokeBinScript(pkgname, script, args) - print(response.stdout) + if response.stdout: + print(response.stdout) + + if response.stderr: + print(response.stderr, file=sys.stderr) + + return response.status class JSIIMeta(_ClassPropertyMeta, type): diff --git a/packages/@jsii/python-runtime/tests/test_invoke_bin.py b/packages/@jsii/python-runtime/tests/test_invoke_bin.py new file mode 100644 index 0000000000..0589d8e699 --- /dev/null +++ b/packages/@jsii/python-runtime/tests/test_invoke_bin.py @@ -0,0 +1,38 @@ +import platform +import subprocess +import sys +import pytest + + +class TestInvokeBinScript: + @pytest.mark.skipif( + platform.system() == "Windows", + reason="jsii-pacmak does not generate windows scripts", + ) + def test_invoke_script(self) -> None: + result = run_script("calc") + + assert result.returncode == 0 + assert result.stdout == b"Hello World!\n\n" + assert result.stderr == b"" + + @pytest.mark.skipif( + platform.system() == "Windows", + reason="jsii-pacmak does not generate windows scripts", + ) + def test_invoke_script_with_args(self) -> None: + result = run_script("calc", "arg1", "arg2") + + assert result.returncode == 0 + assert result.stdout == b"Hello World!\n arguments: arg1, arg2\n\n" + assert result.stderr == b"" + + +def run_script(script_name: str, *args: str) -> subprocess.CompletedProcess: + if platform.system() == "Windows": + # currently not used, the calling semantics have not been defined for bin scripts on windows + script_path = f".env\\Scripts\\{script_name}" + return subprocess.run([sys.executable, script_path, *args], capture_output=True) + else: + script_path = f".env/bin/{script_name}" + return subprocess.run([script_path, *args], capture_output=True) diff --git a/packages/jsii-calc/bin/run.ts b/packages/jsii-calc/bin/run.ts index 296a77b93d..1535529035 100755 --- a/packages/jsii-calc/bin/run.ts +++ b/packages/jsii-calc/bin/run.ts @@ -3,3 +3,8 @@ /* eslint-disable no-console */ console.info('Hello World!'); + +const args = process.argv.slice(2); +if (args.length > 0) { + console.info(` arguments: ${args.join(', ')}`); +} diff --git a/packages/jsii-pacmak/lib/targets/python.ts b/packages/jsii-pacmak/lib/targets/python.ts index 048a6b5cd7..9dbd7a48de 100644 --- a/packages/jsii-pacmak/lib/targets/python.ts +++ b/packages/jsii-pacmak/lib/targets/python.ts @@ -1792,7 +1792,7 @@ class PythonModule implements PythonType { code.line(); emitList( code, - '__jsii_assembly__.invokeBinScript(', + 'exit_code = __jsii_assembly__.invokeBinScript(', [ JSON.stringify(this.assembly.name), JSON.stringify(name), @@ -1800,6 +1800,7 @@ class PythonModule implements PythonType { ], ')', ); + code.line('exit(exit_code)'); code.closeFile(script_file); scripts.push(script_file.replace(/\\/g, '/')); } diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.js.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.js.snap index 41546e4ee8..9fc66018c9 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.js.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.js.snap @@ -11297,7 +11297,8 @@ __jsii_assembly__ = jsii.JSIIAssembly.load( "jsii-calc", "3.20.120", "jsii_calc", "jsii-calc@3.20.120.jsii.tgz" ) -__jsii_assembly__.invokeBinScript("jsii-calc", "calc", sys.argv[1:]) +exit_code = __jsii_assembly__.invokeBinScript("jsii-calc", "calc", sys.argv[1:]) +exit(exit_code) `;