Repository: pex-tool/pex

Issue:
Feature Request : Syntax for --platform to refer to the current platform
I'm working on a project where I'm using an OS X development machine to cross build PEX files that need to run both on OS X and on Linux. To do this, I am using `--platform` to define a new platform list for the build that contains both the OS X platform string and the target platform:

`--platform macosx_10.15-x86_64-cp-37-cp37m  --platform manylinux2010-x86_64-cp-37-cp37m`

This works, but it requires explicitly specifying (and knowing) the current platform string. What would be useful to avoid this is a syntax for the `--platform` option that uses the normal defaulting logic to compute the current platform string and adds that to the platform list.

`--platform host-platform --platform manylinux2010-x86_64-cp-37-cp37m`

Alternatively, a programmatic way to query for the current platform string would also work:

`--platform $(find-python-platform-string) --platform manylinux2010-x86_64-cp-37-cp37m`



Discussion:
Aha - Pex does support this but the feature is not documented. You can use `--platform current`. I'll leave this issue open and close it with a CLI help string improvement though to make this clear.

Also though, you can mix interpreter selection strategies as well. So you could acheive the same end in many ways:
1. `--platform current --platform manylinux2010-x86_64-cp-37-cp37m`
2. `--python python37 --platform manylinux2010-x86_64-cp-37-cp37m`
3. `--python /path/to/specific/mac/interpreter --platform manylinux2010-x86_64-cp-37-cp37m`
4. `--interpreter-constraint CPython==3.7.* --platform manylinux2010-x86_64-cp-37-cp37m`

The advantage of 2-4 is they allow better control over which local interpreter to use: 3 is exact and 2 & 4 use $PATH searches. With `--platform current` you get the 1st on your $PATH which may not be a 37 interpreter depending on OS upgrades, etc.




Resolving patch:
diff --git a/pex/bin/pex.py b/pex/bin/pex.py
--- a/pex/bin/pex.py
+++ b/pex/bin/pex.py
@@ -436,13 +436,13 @@ def configure_clp_pex_environment(parser):
       action='callback',
       callback=process_platform,
       help='The platform for which to build the PEX. This option can be passed multiple times '
-           'to create a multi-platform pex. To use wheels for specific interpreter/platform tags'
-           ', you can append them to the platform with hyphens like: PLATFORM-IMPL-PYVER-ABI '
-           '(e.g. "linux_x86_64-cp-27-cp27mu", "macosx_10.12_x86_64-cp-36-cp36m") PLATFORM is '
-           'the host platform e.g. "linux-x86_64", "macosx-10.12-x86_64", etc". IMPL is the '
-           'python implementation abbreviation (e.g. "cp", "pp", "jp"). PYVER is a two-digit '
-           'string representing the python version (e.g. "27", "36"). ABI is the ABI tag '
-           '(e.g. "cp36m", "cp27mu", "abi3", "none"). Default: current platform.')
+           'to create a multi-platform pex. To use the platform corresponding to the current '
+           'interpreter you can pass `current`. To target any other platform you pass a string '
+           'composed of fields: <platform>-<python impl abbr>-<python version>-<abi>. These fields '
+           'stem from wheel name conventions as outlined in '
+           'https://www.python.org/dev/peps/pep-0427#file-name-convention and influenced by '
+           'https://www.python.org/dev/peps/pep-0425. For the current interpreter at {} the full '
+           'platform string is {}'.format(PythonInterpreter.get().binary, Platform.current()))
 
   parser.add_option_group(group)
 


Test patch: