Skip to content

Commit ffc70f2

Browse files
committed
Replace rmreg with conda command
1 parent 881f002 commit ffc70f2

File tree

3 files changed

+13
-56
lines changed

3 files changed

+13
-56
lines changed

constructor/nsis/_nsis.py

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,8 @@
88
# be tested in an installation.
99

1010
import os
11-
import re
1211
import sys
13-
from os.path import exists, isfile, join
14-
15-
try:
16-
import winreg
17-
except ImportError:
18-
import _winreg as winreg
12+
from os.path import exists, join
1913

2014
ROOT_PREFIX = sys.prefix
2115

@@ -57,36 +51,6 @@ def err(x):
5751
OutputDebugString('_nsis.py: Error: ' + x)
5852

5953

60-
class NSISReg:
61-
def __init__(self, reg_path):
62-
self.reg_path = reg_path
63-
if exists(join(ROOT_PREFIX, '.nonadmin')):
64-
self.main_key = winreg.HKEY_CURRENT_USER
65-
else:
66-
self.main_key = winreg.HKEY_LOCAL_MACHINE
67-
68-
def set(self, name, value):
69-
try:
70-
winreg.CreateKey(self.main_key, self.reg_path)
71-
registry_key = winreg.OpenKey(self.main_key, self.reg_path, 0,
72-
winreg.KEY_WRITE)
73-
winreg.SetValueEx(registry_key, name, 0, winreg.REG_SZ, value)
74-
winreg.CloseKey(registry_key)
75-
return True
76-
except WindowsError:
77-
return False
78-
79-
def get(self, name):
80-
try:
81-
registry_key = winreg.OpenKey(self.main_key, self.reg_path, 0,
82-
winreg.KEY_READ)
83-
value, regtype = winreg.QueryValueEx(registry_key, name)
84-
winreg.CloseKey(registry_key)
85-
return value
86-
except WindowsError:
87-
return None
88-
89-
9054
allusers = (not exists(join(ROOT_PREFIX, '.nonadmin')))
9155
# out('allusers is %s\n' % allusers)
9256

@@ -157,25 +121,9 @@ def add_condabin_to_path():
157121
broadcast_environment_settings_change()
158122

159123

160-
def rm_regkeys():
161-
cmdproc_reg_entry = NSISReg(r'Software\Microsoft\Command Processor')
162-
cmdproc_autorun_val = cmdproc_reg_entry.get('AutoRun')
163-
conda_hook_regex_pat = r'((\s+&\s+)?(if +exist)?(\s*?\"[^\"]*?conda[-_]hook\.bat\"))'
164-
if join(ROOT_PREFIX, 'condabin') in (cmdproc_autorun_val or ''):
165-
cmdproc_autorun_newval = re.sub(conda_hook_regex_pat, '',
166-
cmdproc_autorun_val)
167-
try:
168-
cmdproc_reg_entry.set('AutoRun', cmdproc_autorun_newval)
169-
except Exception:
170-
# Hey, at least we made an attempt to cleanup
171-
pass
172-
173-
174124
def main():
175125
cmd = sys.argv[1].strip()
176-
if cmd == 'rmreg':
177-
rm_regkeys()
178-
elif cmd == 'addpath':
126+
if cmd == 'addpath':
179127
# These checks are probably overkill, but could be useful
180128
# if I forget to update something that uses this code.
181129
if len(sys.argv) > 2:

constructor/nsis/main.nsi.tmpl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1672,7 +1672,16 @@ Section "Uninstall"
16721672
call un.AbortRetryNSExecWait
16731673
${EndIf}
16741674
!insertmacro AbortRetryNSExecWaitLibNsisCmd "rmpath"
1675-
!insertmacro AbortRetryNSExecWaitLibNsisCmd "rmreg"
1675+
{%- if has_conda %}
1676+
# When running conda.bat directly, there is a non-fatal error
1677+
# that DOSKEY (called by conda_hook.bat) is not a valid command.
1678+
# While the operation still succeeds, this error is confusing.
1679+
# Calling via cmd.exe fixes that.
1680+
push '"$CMD_EXE" /D /C "$INSTDIR\condabin\conda.bat" init cmd.exe --reverse'
1681+
push 'Failed to clean AutoRun'
1682+
push 'WithLog'
1683+
call un.AbortRetryNSExecWait
1684+
{%- endif %}
16761685

16771686
${Print} "Removing files and folders..."
16781687
nsExec::Exec 'cmd.exe /D /C RMDIR /Q /S "$INSTDIR"'

news/1069-port-nsispy-cmds-nsis

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
### Enhancements
22

3-
* Port script execution and directory creation functions from `_nsis.py` to NSIS. (#1069)
3+
* Port script execution, AutoRun manipulation, and directory creation functions from `_nsis.py` to NSIS. (#1069)
44

55
### Bug fixes
66

0 commit comments

Comments
 (0)