Skip to content

Commit 474524a

Browse files
committed
fix #15
1 parent 5cfff41 commit 474524a

File tree

4 files changed

+57
-6
lines changed

4 files changed

+57
-6
lines changed

django_routines/management/commands/routine.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -220,18 +220,21 @@ def _subprocess(self, command: RCommand):
220220
"_actions",
221221
[],
222222
)
223+
expected_opts = len(command.options)
223224
for opt, value in command.options.items():
224225
for action in actions:
225226
opt_strs = getattr(action, "option_strings", [])
226227
if opt == getattr(action, "dest", None) and opt_strs:
227228
if isinstance(value, bool):
228-
if value:
229+
if value is not getattr(action, "default", None):
229230
options.append(opt_strs[-1])
231+
else:
232+
expected_opts -= 1
230233
else:
231234
options.append(f"--{opt}={str(value)}")
232235
break
233236

234-
if len(options) != len(command.options):
237+
if len(options) != expected_opts:
235238
raise CommandError(
236239
_(
237240
"Failed to convert {command} options to CLI format: {unconverted}"
@@ -259,10 +262,7 @@ def _subprocess(self, command: RCommand):
259262
if self.verbosity > 0:
260263
self.secho(" ".join(args), fg="cyan")
261264

262-
# todo make this async
263-
result = subprocess.run(args, env=os.environ.copy(), capture_output=True)
264-
self.stdout.write(result.stdout.decode())
265-
self.stderr.write(result.stderr.decode())
265+
result = subprocess.run(args, env=os.environ.copy())
266266
if result.returncode > 0:
267267
raise CommandError(
268268
_(

doc/source/changelog.rst

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ v1.3.0 (2024-02-18)
88

99
* Implemented `Remove support for python 3.8 <https://github.com/bckohan/django-render-static/issues/30>`_
1010
* Implemented `Upgrade to django-typer 3.x <https://github.com/bckohan/django-render-static/issues/29>`_
11+
* Implemented `stdout/stderr streaming from subprocesses <https://github.com/bckohan/django-render-static/issues/15>`_
1112

1213
v1.2.1 (2024-08-26)
1314
===================

tests/settings_option_toggle.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from .base_settings import *
2+
from django_routines import routine, RoutineCommand
3+
4+
5+
routine(
6+
"option-on",
7+
"Test what happens when supplied command option is toggled on.",
8+
RoutineCommand("collectstatic", options={"interactive": False}),
9+
)
10+
11+
routine(
12+
"option-off",
13+
"Test what happens when supplied command option is toggled off.",
14+
RoutineCommand("collectstatic", options={"interactive": True}),
15+
)

tests/test_runs.py

+35
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import subprocess
88
from django.core.management import call_command
99
from django.test import TestCase
10+
import pexpect
1011

1112

1213
class TestDeploy(TestCase):
@@ -56,3 +57,37 @@ def test_subprocess_opt_error():
5657
"CommandError: Failed to convert collectstatic options to CLI format: {'not-an-option': False}"
5758
in result.stderr
5859
)
60+
61+
62+
def test_option_toggle():
63+
child = pexpect.spawn(
64+
" ".join(
65+
[
66+
sys.executable,
67+
"./manage.py",
68+
"routine",
69+
"--settings",
70+
"tests.settings_option_toggle",
71+
"option-on",
72+
"--subprocess",
73+
]
74+
)
75+
)
76+
child.expect("static files copied.")
77+
78+
child = pexpect.spawn(
79+
" ".join(
80+
[
81+
sys.executable,
82+
"./manage.py",
83+
"routine",
84+
"--settings",
85+
"tests.settings_option_toggle",
86+
"option-off",
87+
"--subprocess",
88+
]
89+
)
90+
)
91+
child.expect("Type 'yes' to continue, or 'no' to cancel:")
92+
child.sendline("yes")
93+
child.expect("static files copied.")

0 commit comments

Comments
 (0)