From 2c4ef2969997b21243bdf3c508d5df78f7308141 Mon Sep 17 00:00:00 2001 From: Romain Marcadier-Muller Date: Tue, 22 Oct 2019 12:06:58 +0200 Subject: [PATCH] fix(pacmak/python): improve detection of twine (#845) Attempt to check for `twine` using `which`, and only fall back to `pip3 show` if that fails. This should hopefully improve detection in contexts where a Python virtual environment is activated that does not have `twine` installed in it, causing `pip3 show` to (presumably) not see it. --- packages/jsii-pacmak/lib/targets/python.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/jsii-pacmak/lib/targets/python.ts b/packages/jsii-pacmak/lib/targets/python.ts index fbf26d3fca..744429c3aa 100644 --- a/packages/jsii-pacmak/lib/targets/python.ts +++ b/packages/jsii-pacmak/lib/targets/python.ts @@ -33,13 +33,18 @@ export default class Python extends Target { + 'Run `pip3 install twine` to enable distribution package validation.'); } - // Approximating existence check using `pip3 show`. If that fails, assume twine is not there. + // Approximating existence check using `which`, falling back on `pip3 show`. If that fails, assume twine is not there. async function twineIsPresent(): Promise { try { - const output = await shell('pip3', ['show', 'twine'], { cwd: sourceDir }); - return output.trim() !== ''; + await shell('which', ['twine'], { cwd: sourceDir }); + return true; } catch { - return false; + try { + const output = await shell('pip3', ['show', 'twine'], { cwd: sourceDir }); + return output.trim() !== ''; + } catch { + return false; + } } } }