Skip to content

Commit

Permalink
Expose method to bring down dynamic UI (#10234)
Browse files Browse the repository at this point in the history
### Problem

In some cases, most notably when pants prints the results of the `test` goal to stderr, we do this printing while the dynamic UI is still active. This means that when the dynamic UI is deactivated, the lines in the terminal corresponding to where the dynamic UI swimlanes were being animated vanish suddenly, which results in the terminal scrolling to some distance beyond where the last output was when a pants run is complete. This is undesirable. We'd like to be able to have a pants rule explicitly disable the dynamic UI when the rule knows it has no more work to do other than printing output.

### Solution

This commit exposes a method on the Python `Console` class `teardown_dynamic_ui()` that proxies to the extant `maybe_teardown_display` method, that will disable the dynamic UI for the remainder of the pants run.

### Result

Fixes #10005
  • Loading branch information
gshuflin committed Jul 7, 2020
1 parent e5eed25 commit 5c357d5
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/python/pants/core/goals/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ async def run_tests(
)

exit_code = PANTS_SUCCEEDED_EXIT_CODE

for result in results:
if result.test_result.status == Status.FAILURE:
exit_code = PANTS_FAILED_EXIT_CODE
Expand Down
8 changes: 6 additions & 2 deletions src/python/pants/engine/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ def flush(self):

class NativeStdOut(NativeWriter):
def write(self, payload: str) -> None:
self.native.write_stdout(self.scheduler_session.session, payload)
scheduler = self.scheduler_session.scheduler._scheduler
session = self.scheduler_session.session
self.native.write_stdout(scheduler, session, payload, teardown_ui=True)


class NativeStdErr(NativeWriter):
def write(self, payload: str) -> None:
self.native.write_stderr(self.scheduler_session.session, payload)
scheduler = self.scheduler_session.scheduler._scheduler
session = self.scheduler_session.session
self.native.write_stderr(scheduler, session, payload, teardown_ui=True)


@side_effecting
Expand Down
11 changes: 9 additions & 2 deletions src/python/pants/engine/internals/native.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,19 @@ def write_log(self, msg: str, *, level: int, target: str):
"""Proxy a log message to the Rust logging faculties."""
return self.lib.write_log(msg, level, target)

def write_stdout(self, session, msg: str):
def write_stdout(self, scheduler, session, msg: str, teardown_ui: bool):
if teardown_ui:
self.teardown_dynamic_ui(scheduler, session)
return self.lib.write_stdout(session, msg)

def write_stderr(self, session, msg: str):
def write_stderr(self, scheduler, session, msg: str, teardown_ui: bool):
if teardown_ui:
self.teardown_dynamic_ui(scheduler, session)
return self.lib.write_stderr(session, msg)

def teardown_dynamic_ui(self, scheduler, session):
self.lib.teardown_dynamic_ui(scheduler, session)

def flush_log(self):
return self.lib.flush_log()

Expand Down
24 changes: 24 additions & 0 deletions src/rust/engine/src/externs/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ py_module_initializer!(native_engine, |py, m| {
"write_stderr",
py_fn!(py, write_stderr(a: PySession, b: String)),
)?;
m.add(
py,
"teardown_dynamic_ui",
py_fn!(py, teardown_dynamic_ui(a: PyScheduler, b: PySession)),
)?;

m.add(py, "set_panic_handler", py_fn!(py, set_panic_handler()))?;

Expand Down Expand Up @@ -1686,6 +1691,25 @@ fn write_stderr(py: Python, session_ptr: PySession, msg: String) -> PyUnitResult
})
}

fn teardown_dynamic_ui(
py: Python,
scheduler_ptr: PyScheduler,
session_ptr: PySession,
) -> PyUnitResult {
with_scheduler(py, scheduler_ptr, |_scheduler| {
with_session(py, session_ptr, |session| {
let _ = block_in_place_and_wait(py, || {
session
.maybe_display_teardown()
.unit_error()
.boxed_local()
.compat()
});
Ok(None)
})
})
}

fn flush_log(py: Python) -> PyUnitResult {
py.allow_threads(|| {
LOGGER.flush();
Expand Down
3 changes: 1 addition & 2 deletions src/rust/engine/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl Session {
}
}

async fn maybe_display_teardown(&self) {
pub async fn maybe_display_teardown(&self) {
if let Some(display) = &self.0.display {
let teardown = {
let mut display = display.lock();
Expand Down Expand Up @@ -497,7 +497,6 @@ impl Scheduler {
.core
.executor
.block_on(session.maybe_display_teardown());

result
}

Expand Down

0 comments on commit 5c357d5

Please sign in to comment.