Skip to content

Commit db71b24

Browse files
author
Hamada Gasmallah
committed
feature(pminit): added pminit cli tool to help in modifying or changing package.json for pythonmonkey
1 parent 59642c3 commit db71b24

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

python/pminit/pminit/cli.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import os, sys
2+
import subprocess
3+
import argparse
4+
5+
def execute(cmd: str, cwd: str):
6+
popen = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.STDOUT,
7+
shell = True, text = True, cwd = cwd )
8+
for stdout_line in iter(popen.stdout.readline, ""):
9+
sys.stdout.write(stdout_line)
10+
sys.stdout.flush()
11+
12+
popen.stdout.close()
13+
return_code = popen.wait()
14+
if return_code:
15+
raise subprocess.CalledProcessError(return_code, cmd)
16+
17+
def commandType(value: str):
18+
if value != "npm":
19+
raise argparse.ArgumentTypeError("Value must be npm.")
20+
return value
21+
22+
def main():
23+
parser = argparse.ArgumentParser(description="A tool to enable running npm on the correct package.json location")
24+
parser.add_argument("executable", nargs=1, help="Should be npm.", type=commandType)
25+
parser.add_argument("args", nargs="+", help="Args to pass into npm command", type=str)
26+
args = parser.parse_args()
27+
28+
pythonmonkey_path= os.path.realpath(
29+
os.path.join(
30+
os.path.dirname(__file__),
31+
'..',
32+
'pythonmonkey'
33+
)
34+
)
35+
36+
execute(' '.join( args.executable + args.args ), pythonmonkey_path)
37+
38+
39+
40+

python/pminit/pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ bump = true
2727

2828
[tool.poetry.build]
2929
script = "post-install-hook.py"
30-
generate-setup-file = false
30+
generate-setup-file = false
31+
32+
[tool.poetry.scripts]
33+
pminit = "pminit.cli:main"
3134

3235
[build-system]
3336
requires = ["poetry-core>=1.0.0", "poetry-dynamic-versioning"]

0 commit comments

Comments
 (0)