Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
CacheCommand Class Reference
Inheritance diagram for CacheCommand:
Collaboration diagram for CacheCommand:

Public Member Functions

None add_options (self)
 
int run (self, Values options, List[str] args)
 
None get_cache_dir (self, Values options, List[Any] args)
 
None get_cache_info (self, Values options, List[Any] args)
 
None list_cache_items (self, Values options, List[Any] args)
 
None format_for_human (self, List[str] files)
 
None format_for_abspath (self, List[str] files)
 
None remove_cache_items (self, Values options, List[Any] args)
 
None purge_cache (self, Values options, List[Any] args)
 
- Public Member Functions inherited from Command
None __init__ (self, str name, str summary, bool isolated=False)
 
None handle_pip_version_check (self, Values options)
 
Tuple[Values, List[str]] parse_args (self, List[str] args)
 
int main (self, List[str] args)
 
- Public Member Functions inherited from CommandContextMixIn
Generator[None, None, Nonemain_context (self)
 
_T enter_context (self, ContextManager[_T] context_provider)
 

Data Fields

 cmd_opts
 
 get_cache_dir
 
 get_cache_info
 
 list_cache_items
 
 remove_cache_items
 
 purge_cache
 
- Data Fields inherited from Command
 name
 
 summary
 
 parser
 
 cmd_opts
 
 tempdir_registry
 
 verbosity
 

Static Public Attributes

bool ignore_require_venv = True
 
str usage
 
- Static Public Attributes inherited from Command
str usage = ""
 
bool ignore_require_venv = False
 

Protected Member Functions

str _cache_dir (self, Values options, str subdir)
 
List[str] _find_http_files (self, Values options)
 
List[str] _find_wheels (self, Values options, str pattern)
 
- Protected Member Functions inherited from Command
int _main (self, List[str] args)
 

Additional Inherited Members

- Protected Attributes inherited from CommandContextMixIn
 _in_main_context
 
 _main_context
 

Detailed Description

Inspect and manage pip's wheel cache.

Subcommands:

- dir: Show the cache directory.
- info: Show information about the cache.
- list: List filenames of packages stored in the cache.
- remove: Remove one or more package from the cache.
- purge: Remove all items from the cache.

``<pattern>`` can be a glob expression or a package name.

Definition at line 15 of file cache.py.

Member Function Documentation

◆ _cache_dir()

str _cache_dir (   self,
Values  options,
str  subdir 
)
protected

Definition at line 194 of file cache.py.

194 def _cache_dir(self, options: Values, subdir: str) -> str:
195 return os.path.join(options.cache_dir, subdir)
196
for i

References i.

Referenced by CacheCommand._find_http_files(), CacheCommand._find_wheels(), and CacheCommand.get_cache_info().

Here is the caller graph for this function:

◆ _find_http_files()

List[str] _find_http_files (   self,
Values  options 
)
protected

Definition at line 197 of file cache.py.

197 def _find_http_files(self, options: Values) -> List[str]:
198 http_dir = self._cache_dir(options, "http")
199 return filesystem.find_files(http_dir, "*")
200

References CacheCommand._cache_dir(), and i.

Referenced by CacheCommand.get_cache_info(), and CacheCommand.remove_cache_items().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _find_wheels()

List[str] _find_wheels (   self,
Values  options,
str  pattern 
)
protected

Definition at line 201 of file cache.py.

201 def _find_wheels(self, options: Values, pattern: str) -> List[str]:
202 wheel_dir = self._cache_dir(options, "wheels")
203
204 # The wheel filename format, as specified in PEP 427, is:
205 # {distribution}-{version}(-{build})?-{python}-{abi}-{platform}.whl
206 #
207 # Additionally, non-alphanumeric values in the distribution are
208 # normalized to underscores (_), meaning hyphens can never occur
209 # before `-{version}`.
210 #
211 # Given that information:
212 # - If the pattern we're given contains a hyphen (-), the user is
213 # providing at least the version. Thus, we can just append `*.whl`
214 # to match the rest of it.
215 # - If the pattern we're given doesn't contain a hyphen (-), the
216 # user is only providing the name. Thus, we append `-*.whl` to
217 # match the hyphen before the version, followed by anything else.
218 #
219 # PEP 427: https://www.python.org/dev/peps/pep-0427/
220 pattern = pattern + ("*.whl" if "-" in pattern else "-*.whl")
221
222 return filesystem.find_files(wheel_dir, pattern)

References CacheCommand._cache_dir(), and i.

Referenced by CacheCommand.get_cache_info(), CacheCommand.list_cache_items(), and CacheCommand.remove_cache_items().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_options()

None add_options (   self)

Reimplemented from Command.

Definition at line 39 of file cache.py.

39 def add_options(self) -> None:
40 self.cmd_opts.add_option(
41 "--format",
42 action="store",
43 dest="list_format",
44 default="human",
45 choices=("human", "abspath"),
46 help="Select the output format among: human (default) or abspath",
47 )
48
49 self.parser.insert_option_group(0, self.cmd_opts)
50

References Command.cmd_opts, CacheCommand.cmd_opts, CompletionCommand.cmd_opts, ConfigurationCommand.cmd_opts, DebugCommand.cmd_opts, DownloadCommand.cmd_opts, FreezeCommand.cmd_opts, HashCommand.cmd_opts, IndexCommand.cmd_opts, InspectCommand.cmd_opts, InstallCommand.cmd_opts, ListCommand.cmd_opts, SearchCommand.cmd_opts, ShowCommand.cmd_opts, UninstallCommand.cmd_opts, WheelCommand.cmd_opts, and i.

◆ format_for_abspath()

None format_for_abspath (   self,
List[str]  files 
)

Definition at line 153 of file cache.py.

153 def format_for_abspath(self, files: List[str]) -> None:
154 if not files:
155 return
156
157 results = []
158 for filename in files:
159 results.append(filename)
160
161 logger.info("\n".join(sorted(results)))
162

References i.

Referenced by CacheCommand.list_cache_items().

Here is the caller graph for this function:

◆ format_for_human()

None format_for_human (   self,
List[str]  files 
)

Definition at line 140 of file cache.py.

140 def format_for_human(self, files: List[str]) -> None:
141 if not files:
142 logger.info("No locally built wheels cached.")
143 return
144
145 results = []
146 for filename in files:
147 wheel = os.path.basename(filename)
148 size = filesystem.format_file_size(filename)
149 results.append(f" - {wheel} ({size})")
150 logger.info("Cache contents:\n")
151 logger.info("\n".join(sorted(results)))
152

References i.

Referenced by CacheCommand.list_cache_items().

Here is the caller graph for this function:

◆ get_cache_dir()

None get_cache_dir (   self,
Values  options,
List[Any]  args 
)

Definition at line 83 of file cache.py.

83 def get_cache_dir(self, options: Values, args: List[Any]) -> None:
84 if args:
85 raise CommandError("Too many arguments")
86
88

References i.

◆ get_cache_info()

None get_cache_info (   self,
Values  options,
List[Any]  args 
)

Definition at line 89 of file cache.py.

89 def get_cache_info(self, options: Values, args: List[Any]) -> None:
90 if args:
91 raise CommandError("Too many arguments")
92
93 num_http_files = len(self._find_http_files(options))
94 num_packages = len(self._find_wheels(options, "*"))
95
96 http_cache_location = self._cache_dir(options, "http")
97 wheels_cache_location = self._cache_dir(options, "wheels")
98 http_cache_size = filesystem.format_directory_size(http_cache_location)
99 wheels_cache_size = filesystem.format_directory_size(wheels_cache_location)
100
101 message = (
103 """
104 Package index page cache location: {http_cache_location}
105 Package index page cache size: {http_cache_size}
106 Number of HTTP files: {num_http_files}
107 Locally built wheels location: {wheels_cache_location}
108 Locally built wheels size: {wheels_cache_size}
109 Number of locally built wheels: {package_count}
110 """
111 )
112 .format(
113 http_cache_location=http_cache_location,
114 http_cache_size=http_cache_size,
115 num_http_files=num_http_files,
116 wheels_cache_location=wheels_cache_location,
117 package_count=num_packages,
118 wheels_cache_size=wheels_cache_size,
119 )
120 .strip()
121 )
122
123 logger.info(message)
124

References CacheCommand._cache_dir(), CacheCommand._find_http_files(), CacheCommand._find_wheels(), and i.

Here is the call graph for this function:

◆ list_cache_items()

None list_cache_items (   self,
Values  options,
List[Any]  args 
)

Definition at line 125 of file cache.py.

125 def list_cache_items(self, options: Values, args: List[Any]) -> None:
126 if len(args) > 1:
127 raise CommandError("Too many arguments")
128
129 if args:
130 pattern = args[0]
131 else:
132 pattern = "*"
133
134 files = self._find_wheels(options, pattern)
135 if options.list_format == "human":
136 self.format_for_human(files)
137 else:
138 self.format_for_abspath(files)
139

References CacheCommand._find_wheels(), CacheCommand.format_for_abspath(), CacheCommand.format_for_human(), and i.

Here is the call graph for this function:

◆ purge_cache()

None purge_cache (   self,
Values  options,
List[Any]  args 
)

Definition at line 188 of file cache.py.

188 def purge_cache(self, options: Values, args: List[Any]) -> None:
189 if args:
190 raise CommandError("Too many arguments")
191
192 return self.remove_cache_items(options, ["*"])
193

References CacheCommand.remove_cache_items, and CacheCommand.remove_cache_items().

Here is the call graph for this function:

◆ remove_cache_items()

None remove_cache_items (   self,
Values  options,
List[Any]  args 
)

Definition at line 163 of file cache.py.

163 def remove_cache_items(self, options: Values, args: List[Any]) -> None:
164 if len(args) > 1:
165 raise CommandError("Too many arguments")
166
167 if not args:
168 raise CommandError("Please provide a pattern")
169
170 files = self._find_wheels(options, args[0])
171
172 no_matching_msg = "No matching packages"
173 if args[0] == "*":
174 # Only fetch http files if no specific pattern given
175 files += self._find_http_files(options)
176 else:
177 # Add the pattern to the log message
178 no_matching_msg += ' for pattern "{}"'.format(args[0])
179
180 if not files:
181 logger.warning(no_matching_msg)
182
183 for filename in files:
184 os.unlink(filename)
185 logger.verbose("Removed %s", filename)
186 logger.info("Files removed: %s", len(files))
187

References CacheCommand._find_http_files(), CacheCommand._find_wheels(), and i.

Referenced by CacheCommand.purge_cache().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

int run (   self,
Values  options,
List[str]  args 
)

Reimplemented from Command.

Definition at line 51 of file cache.py.

51 def run(self, options: Values, args: List[str]) -> int:
52 handlers = {
53 "dir": self.get_cache_dir,
54 "info": self.get_cache_info,
55 "list": self.list_cache_items,
56 "remove": self.remove_cache_items,
57 "purge": self.purge_cache,
58 }
59
60 if not options.cache_dir:
61 logger.error("pip cache commands can not function since cache is disabled.")
62 return ERROR
63
64 # Determine action
65 if not args or args[0] not in handlers:
67 "Need an action (%s) to perform.",
68 ", ".join(sorted(handlers)),
69 )
70 return ERROR
71
72 action = args[0]
73
74 # Error handling happens here, not in the action-handlers.
75 try:
76 handlers[action](options, args[1:])
77 except PipError as e:
79 return ERROR
80
81 return SUCCESS
82

Field Documentation

◆ cmd_opts

◆ get_cache_dir

get_cache_dir

Definition at line 53 of file cache.py.

◆ get_cache_info

get_cache_info

Definition at line 54 of file cache.py.

◆ ignore_require_venv

bool ignore_require_venv = True
static

Definition at line 30 of file cache.py.

◆ list_cache_items

list_cache_items

Definition at line 55 of file cache.py.

◆ purge_cache

purge_cache

Definition at line 57 of file cache.py.

◆ remove_cache_items

remove_cache_items

Definition at line 56 of file cache.py.

Referenced by CacheCommand.purge_cache().

◆ usage

str usage
static
Initial value:
= """
%prog dir
%prog info
%prog list [<pattern>] [--format=[human, abspath]]
%prog remove <pattern>
%prog purge
"""

Definition at line 31 of file cache.py.


The documentation for this class was generated from the following file: