Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support more verbose output for interpreter info. #1347

Merged
merged 2 commits into from
May 8, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions pex/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ def supported_tags(self):

@property
def env_markers(self):
# type: () -> Dict[str, str]
return dict(self._env_markers)

@property
Expand All @@ -263,6 +264,7 @@ def interpreter(self):

@property
def requirement(self):
# type: () -> Requirement
return self.distribution.as_requirement()

@property
Expand Down Expand Up @@ -1070,10 +1072,8 @@ def version_string(self):

@property
def platform(self):
"""The most specific platform of this interpreter.

:rtype: :class:`Platform`
"""
# type: () -> Platform
"""The most specific platform of this interpreter."""
return next(self._identity.iter_supported_platforms())

@property
Expand Down
2 changes: 1 addition & 1 deletion pex/tools/commands/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def _create_dependency_graph(pex):
),
)
marker_environment = pex.interpreter.identity.env_markers.copy()
marker_environment["extra"] = []
marker_environment["extra"] = ""
present_dists = frozenset(dist.project_name for dist in pex.resolve())
for dist in pex.resolve():
graph.add_node(
Expand Down
39 changes: 27 additions & 12 deletions pex/tools/commands/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from pex.variables import ENV

if TYPE_CHECKING:
from typing import Iterator
from typing import Any, Dict, Iterator

logger = logging.getLogger(__name__)

Expand All @@ -35,8 +35,15 @@ def add_arguments(self, parser):
parser.add_argument(
"-v",
"--verbose",
action="store_true",
help="Print the interpreter requirement in addition to it's path.",
action="count",
default=0,
help=(
"Provide more information about the interpreter in json format.\n"
"Once: include the interpreter requirement and platform in addition to it's path.\n"
"Twice: include the interpreter's supported tags.\n"
"Thrice: include the interpreter's environment markers and it's venv affiliation "
"if any."
),
)
self.add_json_options(parser, entity="verbose output")

Expand Down Expand Up @@ -75,15 +82,23 @@ def run(
try:
for interpreter in self._find_interpreters(pex, all=options.all):
if options.verbose:
self.dump_json(
options,
{
"path": interpreter.binary,
"requirement": str(interpreter.identity.requirement),
"platform": str(interpreter.platform),
},
out,
)
interpreter_info = {
"path": interpreter.binary,
"requirement": str(interpreter.identity.requirement),
"platform": str(interpreter.platform),
} # type: Dict[str, Any]
if options.verbose >= 2:
interpreter_info["supported_tags"] = [
str(tag) for tag in interpreter.identity.supported_tags
]
if options.verbose >= 3:
interpreter_info["env_markers"] = interpreter.identity.env_markers
interpreter_info["venv"] = interpreter.is_venv
if interpreter.is_venv:
interpreter_info[
"base_interpreter"
] = interpreter.resolve_base_interpreter().binary
self.dump_json(options, interpreter_info, out)
else:
out.write(interpreter.binary)
out.write("\n")
Expand Down