Skip to content

Commit 0f9e5d9

Browse files
committed
https://github.com/pyinvoke/invoke/pull/661
Have to wait for this to be merged, or work around the issue. pyinvoke/invoke#660 (comment) claims v1.2.0 works As of right now: https://giant.gfycat.com/BabyishAggravatingGoldeneye.webm
1 parent 603c7c0 commit 0f9e5d9

File tree

2 files changed

+38
-12
lines changed

2 files changed

+38
-12
lines changed

install.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,21 @@
3939

4040

4141
def atask_default(ctx):
42-
ctx.run("echo Works")
4342
print("Running script...")
4443

4544
def atask_install_scoop(ctx):
4645
from invoke.watchers import Responder
46+
breakpoint()
4747
ctx.run(
48-
command='"Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned"',
48+
command="Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned",
4949
watchers=[
5050
Responder(
5151
pattern=r".*default is \"N\".*",
5252
response="A\n",
5353
)
5454
],
5555
)
56+
sys.exit(1)
5657
ctx.run('powershell "iwr -useb https://get.scoop.sh | iex"')
5758
#ctx.run("""powershell "$env:Path = [System.Environment]::GetEnvironmentVariable('Path','Machine') + ';' + [System.Environment]::GetEnvironmentVariable('Path','User')\"""")
5859
ctx.run("scoop install git aria2")
@@ -183,7 +184,7 @@ def global_defaults():
183184
overrides = {
184185
"tasks": {"collection_name": PROG_NAME},
185186
"run": {
186-
#"shell": "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
187+
"shell": "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
187188
"echo": True,
188189
"debug": True,
189190
},
@@ -194,15 +195,18 @@ def global_defaults():
194195
name=PROG_NAME, namespace=namespace, config_class=SetupConfig, version="0.0.1"
195196
)
196197
# NOTE: Debug
197-
from subprocess import Popen
198-
def Popen_print(*args, **kwargs):
199-
if "command" in kwargs:
200-
print(kwargs["command"])
201-
else:
202-
print(args[0])
203-
return Popen(*args, **kwargs)
204-
with patch("invoke.runners.Popen", new=Popen_print):
205-
program.run()
198+
# This uses the Python auditing framework in Python 3.8+
199+
if sys.version_info>=(3,8):
200+
print("auditing enabled")
201+
202+
def print_popen(*args, **kwargs) -> None:
203+
if args[0] == "subprocess.Popen":
204+
# sys.audit("subprocess.Popen", executable, args, cwd, env)
205+
# ("subprocess.Popen", (executable, args, cwd, env))
206+
print(f"{args[1][0]} -> {args[1][1]}")
207+
208+
sys.addaudithook(print_popen)
209+
program.run()
206210

207211

208212
if __name__ == "__main__":

minimized_bug_example.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import sys
2+
from invoke import run
3+
from invoke.exceptions import UnexpectedExit
4+
from time import sleep
5+
6+
assert sys.version_info>=(3,8)
7+
8+
def p(*args):
9+
if args[0] == "subprocess.Popen":
10+
print(f"shell: {args[1][0]}\nargs: {args[1][1]}")
11+
12+
sys.addaudithook(p)
13+
14+
while True:
15+
try:
16+
run("echo Does work", shell="C:\\WINDOWS\\system32\\cmd.exe")
17+
run('Write-Host -ForegroundColor Red "Works intermittently"', shell="C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe")
18+
print("yup")
19+
except UnexpectedExit:
20+
print("nope")
21+
22+
sleep(1)

0 commit comments

Comments
 (0)