Repository: pex-tool/pex

Issue:
bdist_pex supresses output on a successful run
If I am trying to build a pex via setup tools and I run
```
python setup.py bdist_pex
```

Where I have a `setup.cfg` with 
```
pex-args = -vv -r requirements.txt --no-build --wheel --no-transitive --inherit-path=false
```

If run this normally
```
python setup.py bdist_pex
```

I see

```
running bdist_pex
Writing git-squash to /Users/zmanji/code/git-squash/dist/git-squash-0.0.1.pex
python ./setup.py bdist_pex  9.65s user 4.25s system 95% cpu 14.487 total
┌─ ~/code/git-squash (master) (venv)                                        
```

If I use `PEX_VERBOSE`

I see:

```
PEX_VERBOSE=10 python ./setup.py bdist_pex
pex: Installed VendorImporter(root='/Users/zmanji/code/git-squash/venv/lib/python3.9/site-packages', importables=(_Importable(module='attr', is_pkg=True, path='pex/vendor/_vendored/attrs', prefix='pex.third_party'), _Importable(module='pyparsing', is_pkg=False, path='pex/vendor/_vendored/packaging', prefix='pex.third_party'), _Importable(module='packaging', is_pkg=True, path='pex/vendor/_vendored/packaging', prefix='pex.third_party'), _Importable(module='pip', is_pkg=True, path='pex/vendor/_vendored/pip', prefix='pex.third_party'), _Importable(module='setuptools', is_pkg=True, path='pex/vendor/_vendored/setuptools', prefix='pex.third_party'), _Importable(module='pkg_resources', is_pkg=True, path='pex/vendor/_vendored/setuptools', prefix='pex.third_party'), _Importable(module='wheel', is_pkg=True, path='pex/vendor/_vendored/wheel', prefix='pex.third_party')))
pex: pex.third_party.attr imported via _Loader(module_name='pex.third_party.attr', vendor_module_name='pex.vendor._vendored.attrs.attr')
pex: pex.third_party.attr.exceptions imported via _Loader(module_name='pex.third_party.attr.exceptions', vendor_module_name='pex.vendor._vendored.attrs.attr.exceptions')
pex: pex.third_party.attr imported via _Loader(module_name='pex.third_party.attr', vendor_module_name='pex.vendor._vendored.attrs.attr')
pex: pex.third_party.packaging imported via _Loader(module_name='pex.third_party.packaging', vendor_module_name='pex.vendor._vendored.packaging.packaging')
pex: pex.third_party.pyparsing imported via _Loader(module_name='pex.third_party.pyparsing', vendor_module_name='pex.vendor._vendored.packaging.pyparsing')
pex: pex.third_party.pkg_resources imported via _Loader(module_name='pex.third_party.pkg_resources', vendor_module_name='pex.vendor._vendored.setuptools.pkg_resources')
pex: pex.third_party.pkg_resources.extern imported via _Loader(module_name='pex.third_party.pkg_resources.extern', vendor_module_name='pex.vendor._vendored.setuptools.pkg_resources.extern')
pex: pex.third_party.pkg_resources.extern.six imported via _Loader(module_name='pex.third_party.pkg_resources.extern.six', vendor_module_name='pex.vendor._vendored.setuptools.pkg_resources.extern.six')
pex: pex.third_party.pkg_resources.extern.six.moves imported via _Loader(module_name='pex.third_party.pkg_resources.extern.six.moves', vendor_module_name='pex.vendor._vendored.setuptools.pkg_resources.extern.six.moves')
pex: pex.third_party.pkg_resources.extern.packaging imported via _Loader(module_name='pex.third_party.pkg_resources.extern.packaging', vendor_module_name='pex.vendor._vendored.setuptools.pkg_resources.extern.packaging')
pex: pex.third_party.pkg_resources.extern.packaging.version imported via _Loader(module_name='pex.third_party.pkg_resources.extern.packaging.version', vendor_module_name='pex.vendor._vendored.setuptools.pkg_resources.extern.packaging.version')
pex: pex.third_party.pkg_resources.extern.packaging.specifiers imported via _Loader(module_name='pex.third_party.pkg_resources.extern.packaging.specifiers', vendor_module_name='pex.vendor._vendored.setuptools.pkg_resources.extern.packaging.specifiers')
pex: pex.third_party.pkg_resources.extern.pyparsing imported via _Loader(module_name='pex.third_party.pkg_resources.extern.pyparsing', vendor_module_name='pex.vendor._vendored.setuptools.pkg_resources.extern.pyparsing')
pex: pex.third_party.pkg_resources.extern.six.moves.urllib imported via _Loader(module_name='pex.third_party.pkg_resources.extern.six.moves.urllib', vendor_module_name='pex.vendor._vendored.setuptools.pkg_resources.extern.six.moves.urllib')
pex: pex.third_party.pkg_resources.extern.packaging.requirements imported via _Loader(module_name='pex.third_party.pkg_resources.extern.packaging.requirements', vendor_module_name='pex.vendor._vendored.setuptools.pkg_resources.extern.packaging.requirements')
pex: pex.third_party.pkg_resources.extern.packaging.markers imported via _Loader(module_name='pex.third_party.pkg_resources.extern.packaging.markers', vendor_module_name='pex.vendor._vendored.setuptools.pkg_resources.extern.packaging.markers')
pex: pex.third_party.pkg_resources imported via _Loader(module_name='pex.third_party.pkg_resources', vendor_module_name='pex.vendor._vendored.setuptools.pkg_resources')
pex: pex.third_party.packaging.specifiers imported via _Loader(module_name='pex.third_party.packaging.specifiers', vendor_module_name='pex.vendor._vendored.packaging.packaging.specifiers')
pex: pex.third_party.packaging.utils imported via _Loader(module_name='pex.third_party.packaging.utils', vendor_module_name='pex.vendor._vendored.packaging.packaging.utils')
pex: pex.third_party.packaging.markers imported via _Loader(module_name='pex.third_party.packaging.markers', vendor_module_name='pex.vendor._vendored.packaging.packaging.markers')
pex: pex.third_party.packaging.version imported via _Loader(module_name='pex.third_party.packaging.version', vendor_module_name='pex.vendor._vendored.packaging.packaging.version')
running bdist_pex
pex: A pyenv installation was found: Pyenv(root="b'/Users/zmanji/.pyenv\\n'")
pex: Searching for pyenv root...: 39.5ms
Writing git-squash to /Users/zmanji/code/git-squash/dist/git-squash-0.0.1.pex
pex: Executing: PYTHONPATH=/Users/zmanji/code/git-squash:/Users/zmanji/.pyenv/versions/3.9.4/lib/python39.zip:/Users/zmanji/.pyenv/versions/3.9.4/lib/python3.9:/Users/zmanji/.pyenv/versions/3.9.4/lib/python3.9/lib-dynload:/Users/zmanji/code/git-squash/venv/lib/python3.9/site-packages /Users/zmanji/code/git-squash/venv/bin/python3 -s -m pex /Users/zmanji/code/git-squash -vv -r requirements.txt --no-build --wheel --no-transitive --inherit-path=false --output-file /Users/zmanji/code/git-squash/dist/git-squash-0.0.1.pex --script git-squash
```


Observe that `-vv` is passed to execution of pex but there is no output.

The only way to get output is to trigger an error, suppose I have some typo in my `requirements.txt`

Then I can see some output on a failed run:
```
pex: Installed VendorImporter(root='/Users/zmanji/code/git-squash/venv/lib/python3.9/site-packages', importables=(_Importable(module='attr', is_pkg=True, path='pex/vendor/_vendored/attrs', prefix='pex.third_party'), _Importable(module='pyparsing', is_pkg=False, path='pex/vendor/_vendored/packaging', prefix='pex.third_party'), _Importable(module='packaging', is_pkg=True, path='pex/vendor/_vendored/packaging', prefix='pex.third_party'), _Importable(module='pip', is_pkg=True, path='pex/vendor/_vendored/pip', prefix='pex.third_party'), _Importable(module='setuptools', is_pkg=True, path='pex/vendor/_vendored/setuptools', prefix='pex.third_party'), _Importable(module='pkg_resources', is_pkg=True, path='pex/vendor/_vendored/setuptools', prefix='pex.third_party'), _Importable(module='wheel', is_pkg=True, path='pex/vendor/_vendored/wheel', prefix='pex.third_party')))
pex: pex.third_party.attr imported via _Loader(module_name='pex.third_party.attr', vendor_module_name='pex.vendor._vendored.attrs.attr')
pex: pex.third_party.attr.exceptions imported via _Loader(module_name='pex.third_party.attr.exceptions', vendor_module_name='pex.vendor._vendored.attrs.attr.exceptions')
pex: pex.third_party.attr imported via _Loader(module_name='pex.third_party.attr', vendor_module_name='pex.vendor._vendored.attrs.attr')
pex: pex.third_party.packaging imported via _Loader(module_name='pex.third_party.packaging', vendor_module_name='pex.vendor._vendored.packaging.packaging')
pex: pex.third_party.pyparsing imported via _Loader(module_name='pex.third_party.pyparsing', vendor_module_name='pex.vendor._vendored.packaging.pyparsing')
pex: pex.third_party.pkg_resources imported via _Loader(module_name='pex.third_party.pkg_resources', vendor_module_name='pex.vendor._vendored.setuptools.pkg_resources')
pex: pex.third_party.pkg_resources.extern imported via _Loader(module_name='pex.third_party.pkg_resources.extern', vendor_module_name='pex.vendor._vendored.setuptools.pkg_resources.extern')
pex: pex.third_party.pkg_resources.extern.six imported via _Loader(module_name='pex.third_party.pkg_resources.extern.six', vendor_module_name='pex.vendor._vendored.setuptools.pkg_resources.extern.six')
pex: pex.third_party.pkg_resources.extern.six.moves imported via _Loader(module_name='pex.third_party.pkg_resources.extern.six.moves', vendor_module_name='pex.vendor._vendored.setuptools.pkg_resources.extern.six.moves')
pex: pex.third_party.pkg_resources.extern.packaging imported via _Loader(module_name='pex.third_party.pkg_resources.extern.packaging', vendor_module_name='pex.vendor._vendored.setuptools.pkg_resources.extern.packaging')
pex: pex.third_party.pkg_resources.extern.packaging.version imported via _Loader(module_name='pex.third_party.pkg_resources.extern.packaging.version', vendor_module_name='pex.vendor._vendored.setuptools.pkg_resources.extern.packaging.version')
pex: pex.third_party.pkg_resources.extern.packaging.specifiers imported via _Loader(module_name='pex.third_party.pkg_resources.extern.packaging.specifiers', vendor_module_name='pex.vendor._vendored.setuptools.pkg_resources.extern.packaging.specifiers')
pex: pex.third_party.pkg_resources.extern.pyparsing imported via _Loader(module_name='pex.third_party.pkg_resources.extern.pyparsing', vendor_module_name='pex.vendor._vendored.setuptools.pkg_resources.extern.pyparsing')
pex: pex.third_party.pkg_resources.extern.six.moves.urllib imported via _Loader(module_name='pex.third_party.pkg_resources.extern.six.moves.urllib', vendor_module_name='pex.vendor._vendored.setuptools.pkg_resources.extern.six.moves.urllib')
pex: pex.third_party.pkg_resources.extern.packaging.requirements imported via _Loader(module_name='pex.third_party.pkg_resources.extern.packaging.requirements', vendor_module_name='pex.vendor._vendored.setuptools.pkg_resources.extern.packaging.requirements')
pex: pex.third_party.pkg_resources.extern.packaging.markers imported via _Loader(module_name='pex.third_party.pkg_resources.extern.packaging.markers', vendor_module_name='pex.vendor._vendored.setuptools.pkg_resources.extern.packaging.markers')
pex: pex.third_party.pkg_resources imported via _Loader(module_name='pex.third_party.pkg_resources', vendor_module_name='pex.vendor._vendored.setuptools.pkg_resources')
pex: pex.third_party.packaging.specifiers imported via _Loader(module_name='pex.third_party.packaging.specifiers', vendor_module_name='pex.vendor._vendored.packaging.packaging.specifiers')
pex: pex.third_party.packaging.utils imported via _Loader(module_name='pex.third_party.packaging.utils', vendor_module_name='pex.vendor._vendored.packaging.packaging.utils')
pex: pex.third_party.packaging.markers imported via _Loader(module_name='pex.third_party.packaging.markers', vendor_module_name='pex.vendor._vendored.packaging.packaging.markers')
pex: pex.third_party.packaging.version imported via _Loader(module_name='pex.third_party.packaging.version', vendor_module_name='pex.vendor._vendored.packaging.packaging.version')
running bdist_pex
pex: A pyenv installation was found: Pyenv(root="b'/Users/zmanji/.pyenv\\n'")
pex: Searching for pyenv root...: 40.6ms
Writing git-squash to /Users/zmanji/code/git-squash/dist/git-squash-0.0.1.pex
pex: Executing: PYTHONPATH=/Users/zmanji/code/git-squash:/Users/zmanji/.pyenv/versions/3.9.4/lib/python39.zip:/Users/zmanji/.pyenv/versions/3.9.4/lib/python3.9:/Users/zmanji/.pyenv/versions/3.9.4/lib/python3.9/lib-dynload:/Users/zmanji/code/git-squash/venv/lib/python3.9/site-packages /Users/zmanji/code/git-squash/venv/bin/python3 -s -m pex /Users/zmanji/code/git-squash -vv -r requirements.txt --no-build --wheel --no-transitive --inherit-path=false --output-file /Users/zmanji/code/git-squash/dist/git-squash-0.0.1.pex --script git-squash
Failed to create pex via /Users/zmanji/code/git-squash/venv/bin/python3 -s -m pex /Users/zmanji/code/git-squash -vv -r requirements.txt --no-build --wheel --no-transitive --inherit-path=false --output-file /Users/zmanji/code/git-squash/dist/git-squash-0.0.1.pex --script git-squash:
pex: Installed VendorImporter(root='/Users/zmanji/code/git-squash/venv/lib/python3.9/site-packages', importables=(_Importable(module='attr', is_pkg=True, path='pex/vendor/_vendored/attrs', prefix='pex.third_party'), _Importable(module='pyparsing', is_pkg=False, path='pex/vendor/_vendored/packaging', prefix='pex.third_party'), _Importable(module='packaging', is_pkg=True, path='pex/vendor/_vendored/packaging', prefix='pex.third_party'), _Importable(module='pip', is_pkg=True, path='pex/vendor/_vendored/pip', prefix='pex.third_party'), _Importable(module='setuptools', is_pkg=True, path='pex/vendor/_vendored/setuptools', prefix='pex.third_party'), _Importable(module='pkg_resources', is_pkg=True, path='pex/vendor/_vendored/setuptools', prefix='pex.third_party'), _Importable(module='wheel', is_pkg=True, path='pex/vendor/_vendored/wheel', prefix='pex.third_party')))
pex: pex.third_party.attr imported via _Loader(module_name='pex.third_party.attr', vendor_module_name='pex.vendor._vendored.attrs.attr')
pex: pex.third_party.attr.exceptions imported via _Loader(module_name='pex.third_party.attr.exceptions', vendor_module_name='pex.vendor._vendored.attrs.attr.exceptions')
pex: pex.third_party.attr imported via _Loader(module_name='pex.third_party.attr', vendor_module_name='pex.vendor._vendored.attrs.attr')
pex: pex.third_party.packaging imported via _Loader(module_name='pex.third_party.packaging', vendor_module_name='pex.vendor._vendored.packaging.packaging')
pex: pex.third_party.pyparsing imported via _Loader(module_name='pex.third_party.pyparsing', vendor_module_name='pex.vendor._vendored.packaging.pyparsing')
pex: pex.third_party.pkg_resources imported via _Loader(module_name='pex.third_party.pkg_resources', vendor_module_name='pex.vendor._vendored.setuptools.pkg_resources')
pex: pex.third_party.pkg_resources.extern imported via _Loader(module_name='pex.third_party.pkg_resources.extern', vendor_module_name='pex.vendor._vendored.setuptools.pkg_resources.extern')
pex: pex.third_party.pkg_resources.extern.six imported via _Loader(module_name='pex.third_party.pkg_resources.extern.six', vendor_module_name='pex.vendor._vendored.setuptools.pkg_resources.extern.six')
pex: pex.third_party.pkg_resources.extern.six.moves imported via _Loader(module_name='pex.third_party.pkg_resources.extern.six.moves', vendor_module_name='pex.vendor._vendored.setuptools.pkg_resources.extern.six.moves')
pex: pex.third_party.pkg_resources.extern.packaging imported via _Loader(module_name='pex.third_party.pkg_resources.extern.packaging', vendor_module_name='pex.vendor._vendored.setuptools.pkg_resources.extern.packaging')
pex: pex.third_party.pkg_resources.extern.packaging.version imported via _Loader(module_name='pex.third_party.pkg_resources.extern.packaging.version', vendor_module_name='pex.vendor._vendored.setuptools.pkg_resources.extern.packaging.version')
pex: pex.third_party.pkg_resources.extern.packaging.specifiers imported via _Loader(module_name='pex.third_party.pkg_resources.extern.packaging.specifiers', vendor_module_name='pex.vendor._vendored.setuptools.pkg_resources.extern.packaging.specifiers')
pex: pex.third_party.pkg_resources.extern.pyparsing imported via _Loader(module_name='pex.third_party.pkg_resources.extern.pyparsing', vendor_module_name='pex.vendor._vendored.setuptools.pkg_resources.extern.pyparsing')
pex: pex.third_party.pkg_resources.extern.six.moves.urllib imported via _Loader(module_name='pex.third_party.pkg_resources.extern.six.moves.urllib', vendor_module_name='pex.vendor._vendored.setuptools.pkg_resources.extern.six.moves.urllib')
pex: pex.third_party.pkg_resources.extern.packaging.requirements imported via _Loader(module_name='pex.third_party.pkg_resources.extern.packaging.requirements', vendor_module_name='pex.vendor._vendored.setuptools.pkg_resources.extern.packaging.requirements')
pex: pex.third_party.pkg_resources.extern.packaging.markers imported via _Loader(module_name='pex.third_party.pkg_resources.extern.packaging.markers', vendor_module_name='pex.vendor._vendored.setuptools.pkg_resources.extern.packaging.markers')
pex: pex.third_party.pkg_resources imported via _Loader(module_name='pex.third_party.pkg_resources', vendor_module_name='pex.vendor._vendored.setuptools.pkg_resources')
pex: pex.third_party.packaging.specifiers imported via _Loader(module_name='pex.third_party.packaging.specifiers', vendor_module_name='pex.vendor._vendored.packaging.packaging.specifiers')
pex: pex.third_party.packaging.utils imported via _Loader(module_name='pex.third_party.packaging.utils', vendor_module_name='pex.vendor._vendored.packaging.packaging.utils')
pex: pex.third_party.packaging.markers imported via _Loader(module_name='pex.third_party.packaging.markers', vendor_module_name='pex.vendor._vendored.packaging.packaging.markers')
pex: pex.third_party.packaging.version imported via _Loader(module_name='pex.third_party.packaging.version', vendor_module_name='pex.vendor._vendored.packaging.packaging.version')
pex: Searching for pyenv root...
pex: A pyenv installation was found: Pyenv(root="b'/Users/zmanji/.pyenv\\n'")
pex: Searching for pyenv root...: 36.9ms
pex: Building pex
pex: Building pex :: Resolving distributions (['/Users/zmanji/code/git-squash', 'requirements.txt'])
pex: Building pex :: Resolving distributions (['/Users/zmanji/code/git-squash', 'requirements.txt']) :: Resolving requirements.
pex: Building pex :: Resolving distributions (['/Users/zmanji/code/git-squash', 'requirements.txt']) :: Resolving requirements. :: Resolving for:
  DistributionTarget(interpreter=PythonInterpreter('/Users/zmanji/code/git-squash/venv/bin/python3', PythonIdentity('/Users/zmanji/code/git-squash/venv/bin/python3', 'cp39', 'cp39', 'macosx_11_0_x86_64', (3, 9, 4))))
pex: Hashing pex
pex: Hashing pex: 61.1ms
pex: Isolating pex
pex: Isolating pex: 0.1ms
ERROR: Could not find a version that satisfies the requirement gitd==4.0.7 (from -r requirements.txt (line 7)) (from versions: none)
ERROR: No matching distribution found for gitd==4.0.7 (from -r requirements.txt (line 7))
pid 61452 -> /Users/zmanji/.pex/venvs/2a89f6e1881e5fafca055d973675d77a45986d75/06c742d842d199f5dff393d6d01a9a6c5b223105/pex --disable-pip-version-check --no-python-version-warning --exists-action a --use-deprecated legacy-resolver --isolated -q --cache-dir /Users/zmanji/.pex download --dest /private/var/folders/1j/9xbcby_57tx1kmn6s8zfsbww0000gn/T/tmp7zbswg9z/Users.zmanji.code.git-squash.venv.bin.python3 --only-binary :all: --no-deps --requirement requirements.txt /Users/zmanji/code/git-squash --index-url https://pypi.org/simple --retries 5 --timeout 15 exited with 1 and STDERR:
None
```

However there is no output in a successful run which is not expected.

The issue lies here:

https://github.com/pantsbuild/pex/blob/6720d4c64fb033e8418b2e14535512baa01b9a2d/pex/commands/bdist_pex.py#L121-L136

Where the contents of stderr are put into a pipe and only printed out on failure. I would expect the output to be printed out regardless.





Discussion:
Fixing this sgtm. Do you want to take a swing @zmanji?

Resolving patch:
diff --git a/pex/commands/bdist_pex.py b/pex/commands/bdist_pex.py
--- a/pex/commands/bdist_pex.py
+++ b/pex/commands/bdist_pex.py
@@ -134,3 +134,10 @@ def run(self):
                     ),
                     result,
                 )
+            else:
+                die(
+                    "Successfully created pex via {}:\n{}".format(
+                        " ".join(cmd), stderr.decode("utf-8")
+                    ),
+                    result,
+                )


Test patch: