Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
pip._internal.req.req_uninstall Namespace Reference

Data Structures

class  StashedUninstallPathSet
 
class  UninstallPathSet
 
class  UninstallPthEntries
 

Functions

Generator[str, None, None_script_names (str bin_dir, str script_name, bool is_gui)
 
Callable[..., Generator[Any, None, None]] _unique (Callable[..., Generator[Any, None, None]] fn)
 
Generator[str, None, Noneuninstallation_paths (BaseDistribution dist)
 
Set[str] compact (Iterable[str] paths)
 
Set[str] compress_for_rename (Iterable[str] paths)
 
Tuple[Set[str], Set[str]] compress_for_output_listing (Iterable[str] paths)
 

Variables

 logger = getLogger(__name__)
 

Function Documentation

◆ _script_names()

Generator[str, None, None] _script_names ( str  bin_dir,
str  script_name,
bool   is_gui 
)
protected
Create the fully qualified name of the files created by
{console,gui}_scripts for the given ``dist``.
Returns the list of file names

Definition at line 21 of file req_uninstall.py.

23) -> Generator[str, None, None]:
24 """Create the fully qualified name of the files created by
25 {console,gui}_scripts for the given ``dist``.
26 Returns the list of file names
27 """
28 exe_name = os.path.join(bin_dir, script_name)
29 yield exe_name
30 if not WINDOWS:
31 return
32 yield f"{exe_name}.exe"
33 yield f"{exe_name}.exe.manifest"
34 if is_gui:
35 yield f"{exe_name}-script.pyw"
36 else:
37 yield f"{exe_name}-script.py"
38
39
for i

References i.

Referenced by UninstallPathSet.from_dist().

Here is the caller graph for this function:

◆ _unique()

Callable[..., Generator[Any, None, None]] _unique ( Callable[..., Generator[Any, None, None]]   fn)
protected

Definition at line 40 of file req_uninstall.py.

42) -> Callable[..., Generator[Any, None, None]]:
43 @functools.wraps(fn)
44 def unique(*args: Any, **kw: Any) -> Generator[Any, None, None]:
45 seen: Set[Any] = set()
46 for item in fn(*args, **kw):
47 if item not in seen:
48 seen.add(item)
49 yield item
50
51 return unique
52
53
54@_unique

References i.

◆ compact()

Set[str] compact ( Iterable[str]  paths)
Compact a path set to contain the minimal number of paths
necessary to contain all paths in the set. If /a/path/ and
/a/path/to/a/file.txt are both in the set, leave only the
shorter path.

Definition at line 98 of file req_uninstall.py.

98def compact(paths: Iterable[str]) -> Set[str]:
99 """Compact a path set to contain the minimal number of paths
100 necessary to contain all paths in the set. If /a/path/ and
101 /a/path/to/a/file.txt are both in the set, leave only the
102 shorter path."""
103
104 sep = os.path.sep
105 short_paths: Set[str] = set()
106 for path in sorted(paths, key=len):
107 should_skip = any(
109 and path[len(shortpath.rstrip("*").rstrip(sep))] == sep
110 for shortpath in short_paths
111 )
112 if not should_skip:
113 short_paths.add(path)
114 return short_paths
115
116

References i.

Referenced by UninstallPathSet._allowed_to_proceed(), pip._internal.req.req_uninstall.compress_for_output_listing(), and UninstallPathSet.remove().

Here is the caller graph for this function:

◆ compress_for_output_listing()

Tuple[Set[str], Set[str]] compress_for_output_listing ( Iterable[str]  paths)
Returns a tuple of 2 sets of which paths to display to user

The first set contains paths that would be deleted. Files of a package
are not added and the top-level directory of the package has a '*' added
at the end - to signify that all it's contents are removed.

The second set contains files that would have been skipped in the above
folders.

Definition at line 151 of file req_uninstall.py.

151def compress_for_output_listing(paths: Iterable[str]) -> Tuple[Set[str], Set[str]]:
152 """Returns a tuple of 2 sets of which paths to display to user
153
154 The first set contains paths that would be deleted. Files of a package
155 are not added and the top-level directory of the package has a '*' added
156 at the end - to signify that all it's contents are removed.
157
158 The second set contains files that would have been skipped in the above
159 folders.
160 """
161
162 will_remove = set(paths)
163 will_skip = set()
164
165 # Determine folders and files
166 folders = set()
167 files = set()
168 for path in will_remove:
169 if path.endswith(".pyc"):
170 continue
171 if path.endswith("__init__.py") or ".dist-info" in path:
173 files.add(path)
174
175 # probably this one https://github.com/python/mypy/issues/390
176 _normcased_files = set(map(os.path.normcase, files)) # type: ignore
177
178 folders = compact(folders)
179
180 # This walks the tree using os.walk to not miss extra folders
181 # that might get added.
182 for folder in folders:
183 for dirpath, _, dirfiles in os.walk(folder):
184 for fname in dirfiles:
185 if fname.endswith(".pyc"):
186 continue
187
188 file_ = os.path.join(dirpath, fname)
189 if (
190 os.path.isfile(file_)
191 and os.path.normcase(file_) not in _normcased_files
192 ):
193 # We are skipping this file. Add it to the set.
194 will_skip.add(file_)
195
196 will_remove = files | {os.path.join(folder, "*") for folder in folders}
197
198 return will_remove, will_skip
199
200

References pip._internal.req.req_uninstall.compact(), and i.

Referenced by UninstallPathSet._allowed_to_proceed().

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

◆ compress_for_rename()

Set[str] compress_for_rename ( Iterable[str]  paths)
Returns a set containing the paths that need to be renamed.

This set may include directories when the original sequence of paths
included every file on disk.

Definition at line 117 of file req_uninstall.py.

117def compress_for_rename(paths: Iterable[str]) -> Set[str]:
118 """Returns a set containing the paths that need to be renamed.
119
120 This set may include directories when the original sequence of paths
121 included every file on disk.
122 """
123 case_map = {os.path.normcase(p): p for p in paths}
124 remaining = set(case_map)
125 unchecked = sorted({os.path.split(p)[0] for p in case_map.values()}, key=len)
126 wildcards: Set[str] = set()
127
128 def norm_join(*a: str) -> str:
130
131 for root in unchecked:
132 if any(os.path.normcase(root).startswith(w) for w in wildcards):
133 # This directory has already been handled.
134 continue
135
136 all_files: Set[str] = set()
137 all_subdirs: Set[str] = set()
138 for dirname, subdirs, files in os.walk(root):
139 all_subdirs.update(norm_join(root, dirname, d) for d in subdirs)
140 all_files.update(norm_join(root, dirname, f) for f in files)
141 # If all the files we found are in our remaining set of files to
142 # remove, then remove them from the latter set and add a wildcard
143 # for the directory.
144 if not (all_files - remaining):
146 wildcards.add(root + os.sep)
147
148 return set(map(case_map.__getitem__, remaining)) | wildcards
149
150

References i.

Referenced by UninstallPathSet.remove().

Here is the caller graph for this function:

◆ uninstallation_paths()

Generator[str, None, None] uninstallation_paths ( BaseDistribution  dist)
Yield all the uninstallation paths for dist based on RECORD-without-.py[co]

Yield paths to all the files in RECORD. For each .py file in RECORD, add
the .pyc and .pyo in the same directory.

UninstallPathSet.add() takes care of the __pycache__ .py[co].

If RECORD is not found, raises UninstallationError,
with possible information from the INSTALLER file.

https://packaging.python.org/specifications/recording-installed-packages/

Definition at line 55 of file req_uninstall.py.

55def uninstallation_paths(dist: BaseDistribution) -> Generator[str, None, None]:
56 """
57 Yield all the uninstallation paths for dist based on RECORD-without-.py[co]
58
59 Yield paths to all the files in RECORD. For each .py file in RECORD, add
60 the .pyc and .pyo in the same directory.
61
62 UninstallPathSet.add() takes care of the __pycache__ .py[co].
63
64 If RECORD is not found, raises UninstallationError,
65 with possible information from the INSTALLER file.
66
67 https://packaging.python.org/specifications/recording-installed-packages/
68 """
69 location = dist.location
70 assert location is not None, "not installed"
71
73 if entries is None:
74 msg = "Cannot uninstall {dist}, RECORD file not found.".format(dist=dist)
75 installer = dist.installer
76 if not installer or installer == "pip":
77 dep = "{}=={}".format(dist.raw_name, dist.version)
78 msg += (
79 " You might be able to recover from this via: "
80 "'pip install --force-reinstall --no-deps {}'.".format(dep)
81 )
82 else:
83 msg += " Hint: The package was installed by {}.".format(installer)
84 raise UninstallationError(msg)
85
86 for entry in entries:
87 path = os.path.join(location, entry)
88 yield path
89 if path.endswith(".py"):
90 dn, fn = os.path.split(path)
91 base = fn[:-3]
92 path = os.path.join(dn, base + ".pyc")
93 yield path
94 path = os.path.join(dn, base + ".pyo")
95 yield path
96
97

References i.

Referenced by UninstallPathSet.from_dist().

Here is the caller graph for this function:

Variable Documentation

◆ logger

logger = getLogger(__name__)

Definition at line 18 of file req_uninstall.py.