Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/manage/pep514utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,18 +224,20 @@ def _is_tag_managed(company_key, tag_name, *, creating=False, allow_warn=True):
def _split_root(root_name):
if not root_name:
LOGGER.verbose("Skipping registry shortcuts as PEP 514 registry root is not set.")
return
return None, None
hive_name, _, name = root_name.partition("\\")
try:
hive = getattr(winreg, hive_name.upper())
except AttributeError:
LOGGER.verbose("Skipping registry shortcuts as %s\\%s is not a valid key", root_name)
return
LOGGER.verbose("Skipping registry shortcuts as %s\\%s is not a valid key", root_name, hive_name)
return None, None
return hive, name


def update_registry(root_name, install, data, warn_for=[]):
hive, name = _split_root(root_name)
if not hive or not name:
return
with winreg.CreateKey(hive, name) as root:
allow_warn = install_matches_any(install, warn_for)
if _is_tag_managed(root, data["Key"], creating=True, allow_warn=allow_warn):
Expand All @@ -258,6 +260,8 @@ def update_registry(root_name, install, data, warn_for=[]):
def cleanup_registry(root_name, keep, warn_for=[]):
LOGGER.debug("Cleaning up registry entries")
hive, name = _split_root(root_name)
if not hive or not name:
return
with _reg_open(hive, name, writable=True) as root:
for company_name in list(_iter_keys(root)):
any_left = False
Expand Down
3 changes: 2 additions & 1 deletion src/manage/uninstall_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ def execute(cmd):
_do_purge_global_dir(cmd.global_dir, warn_msg.format("global commands"))
LOGGER.info("Purging all shortcuts")
for _, cleanup in SHORTCUT_HANDLERS.values():
cleanup(cmd, [])
if cleanup:
cleanup(cmd, [])
LOGGER.debug("END uninstall_command.execute")
return

Expand Down
13 changes: 9 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,16 @@ def localserver():
p.wait(5)


REG_TEST_ROOT = r"Software\Python\PyManagerTesting"


class FakeConfig:
def __init__(self, global_dir, installs=[]):
self.root = global_dir.parent if global_dir else None
self.global_dir = global_dir
self.root = global_dir.parent if global_dir else None
self.download_dir = self.root / "_cache" if self.root else None
self.start_folder = self.root / "_start" if self.root else None
self.pep514_root = REG_TEST_ROOT
self.confirm = False
self.installs = list(installs)
self.shebang_can_run_anything = True
Expand All @@ -175,15 +181,14 @@ def get_install_to_run(self, tag, *, windowed=False):
return [i for i in self.installs
if (not tag or i["tag"] == tag) and (not company or i["company"] == company)][0]

def ask_yn(self, question):
return False if self.confirm else True

@pytest.fixture
def fake_config(tmp_path):
return FakeConfig(tmp_path / "bin")


REG_TEST_ROOT = r"Software\Python\PyManagerTesting"


class RegistryFixture:
def __init__(self, hive, root):
self.hive = hive
Expand Down
8 changes: 8 additions & 0 deletions tests/test_uninstall_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,11 @@ def test_purge_global_dir(monkeypatch, registry, tmp_path):
assert registry.getvalueandkind("", "Path") == (
rf"C:\A;{tmp_path}\X;C:\B;%PTH%;C:\%D%\E", winreg.REG_SZ)
assert not list(tmp_path.iterdir())


def test_null_purge(fake_config):
cmd = fake_config
cmd.args = ["--purge"]
cmd.confirm = False
cmd.purge = True
UC.execute(cmd)
Loading