Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
inspect.py
Go to the documentation of this file.
1
import
logging
2
from
optparse
import
Values
3
from
typing
import
Any, Dict, List
4
5
from
pip._vendor.packaging.markers
import
default_environment
6
from
pip._vendor.rich
import
print_json
7
8
from
pip
import
__version__
9
from
pip._internal.cli
import
cmdoptions
10
from
pip._internal.cli.req_command
import
Command
11
from
pip._internal.cli.status_codes
import
SUCCESS
12
from
pip._internal.metadata
import
BaseDistribution, get_environment
13
from
pip._internal.utils.compat
import
stdlib_pkgs
14
from
pip._internal.utils.urls
import
path_to_url
15
16
logger =
logging.getLogger
(__name__)
17
18
19
class
InspectCommand
(
Command
):
20
"""
21
Inspect the content of a Python environment and produce a report in JSON format.
22
"""
23
24
ignore_require_venv =
True
25
usage =
"""
26
%prog [options]"""
27
28
def
add_options
(self) -> None:
29
self.
cmd_opts
cmd_opts
.
add_option
(
30
"--local"
,
31
action=
"store_true"
,
32
default=
False
,
33
help=(
34
"If in a virtualenv that has global access, do not list "
35
"globally-installed packages."
36
),
37
)
38
self.
cmd_opts
cmd_opts
.
add_option
(
39
"--user"
,
40
dest=
"user"
,
41
action=
"store_true"
,
42
default=
False
,
43
help=
"Only output packages installed in user-site."
,
44
)
45
self.
cmd_opts
cmd_opts
.
add_option
(
cmdoptions.list_path
())
46
self.
parser
.insert_option_group(0, self.
cmd_opts
cmd_opts
)
47
48
def
run
(self, options: Values, args: List[str]) -> int:
49
cmdoptions.check_list_path_option
(options)
50
dists = get_environment(
options.path
).iter_installed_distributions(
51
local_only=
options.local
,
52
user_only=
options.user
,
53
skip=set(stdlib_pkgs),
54
)
55
output = {
56
"version"
:
"1"
,
57
"pip_version"
: __version__,
58
"installed"
: [self.
_dist_to_dict
(dist)
for
dist
in
dists],
59
"environment"
: default_environment(),
60
# TODO tags? scheme?
61
}
62
print_json(data=output)
63
return
SUCCESS
64
65
def
_dist_to_dict
(self, dist: BaseDistribution) -> Dict[str, Any]:
66
res: Dict[str, Any] = {
67
"metadata"
:
dist.metadata_dict
,
68
"metadata_location"
:
dist.info_location
,
69
}
70
# direct_url. Note that we don't have download_info (as in the installation
71
# report) since it is not recorded in installed metadata.
72
direct_url =
dist.direct_url
73
if
direct_url
is
not
None
:
74
res[
"direct_url"
] =
direct_url.to_dict
()
75
else
:
76
# Emulate direct_url for legacy editable installs.
77
editable_project_location =
dist.editable_project_location
78
if
editable_project_location
is
not
None
:
79
res[
"direct_url"
] = {
80
"url"
: path_to_url(editable_project_location),
81
"dir_info"
: {
82
"editable"
:
True
,
83
},
84
}
85
# installer
86
installer =
dist.installer
87
if
dist.installer
:
88
res[
"installer"
] = installer
89
# requested
90
if
dist.installed_with_dist_info
:
91
res[
"requested"
] =
dist.requested
92
return
res
pip._internal.cli.base_command.Command
Definition
base_command.py:45
pip._internal.cli.base_command.Command.cmd_opts
cmd_opts
Definition
base_command.py:68
pip._internal.cli.base_command.Command.parser
parser
Definition
base_command.py:54
pip._internal.commands.inspect.InspectCommand
Definition
inspect.py:19
pip._internal.commands.inspect.InspectCommand.add_options
None add_options(self)
Definition
inspect.py:28
pip._internal.commands.inspect.InspectCommand._dist_to_dict
Dict[str, Any] _dist_to_dict(self, BaseDistribution dist)
Definition
inspect.py:65
pip._internal.commands.inspect.InspectCommand.cmd_opts
cmd_opts
Definition
inspect.py:46
pip._internal.commands.inspect.InspectCommand.run
int run(self, Values options, List[str] args)
Definition
inspect.py:48
pip._internal.cli.req_command
Definition
req_command.py:1
pip._internal.cli.status_codes
Definition
status_codes.py:1
pip._internal.cli
Definition
__init__.py:1
pip._internal.metadata
Definition
__init__.py:1
pip._internal.utils.compat
Definition
compat.py:1
pip._internal.utils.urls
Definition
urls.py:1
pip._vendor.packaging.markers
Definition
markers.py:1
pip._vendor.rich
Definition
__init__.py:1
i
for i
Definition
prime_search.m:10
venv
lib
python3.12
site-packages
pip
_internal
commands
inspect.py
Generated by
1.9.8