8000 remove unused utils.py functions, compat with Python-3.14 by stonebig · Pull Request #1365 · winpython/winpython · GitHub
[go: up one dir, main page]

Skip to content

remove unused utils.py functions, compat with Python-3.14 #1365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 29, 2024
Merged
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
8000 Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion make.py
Original file line number Diff line number Diff line change
Expand Up @@ -1670,7 +1670,7 @@ def make(
) # Create/re-create the WinPython base directory
self._print(f"Creating WinPython {my_winpydir} base directory")
if Path(self.winpydir).is_dir() and remove_existing and not self.simulation:
shutil.rmtree(self.winpydir, onerror=utils.onerror)
shutil.rmtree(self.winpydir, onexc=utils.onerror)
if not Path(self.winpydir).is_dir():
os.mkdir(self.winpydir)
if remove_existing and not self.simulation:
Expand Down
4 changes: 2 additions & 2 deletions winpython/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
-----------------------------------------

Copyright (c) 2012-2013 Pierre Raybaut
Copyright (c) 2014-2023+ The Winpython development team https://github.com/winpython/
Copyright (c) 2014-2024+ The Winpython development team https://github.com/winpython/

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
Expand All @@ -28,6 +28,6 @@
OTHER DEALINGS IN THE SOFTWARE.
"""

__version__ = '9.0.20240623'
__version__ = '9.0.20240629'
__license__ = __doc__
__project_url__ = 'http://winpython.github.io/'
69 changes: 5 additions & 64 deletions winpython/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def onerror(function, path, excinfo):
attempts to add write permission and then retries.
If the error is for another reason, it re-raises the error.

Usage: `shutil.rmtree(path, onerror=onerror)"""
Usage: `shutil.rmtree(path, onexc=onerror)"""
if not os.access(path, os.W_OK):
# Is the error an access error?
os.chmod(path, stat.S_IWUSR)
Expand All @@ -63,65 +63,6 @@ def onerror(function, path, excinfo):
raise



# =============================================================================
# Environment variables
# =============================================================================
def get_env(name, current=True):
"""Return HKCU/HKLM environment variable name and value

For example, get_user_env('PATH') may returns:
('Path', u'C:\\Program Files\\Intel\\WiFi\\bin\\')"""
root = (
winreg.HKEY_CURRENT_USER
if current
else winreg.HKEY_LOCAL_MACHINE
)
key = winreg.OpenKey(root, "Environment")
for index in range(0, winreg.QueryInfoKey(key)[1]):
try:
value = winreg.EnumValue(key, index)
if value[0].lower() == name.lower():
# Return both value[0] and value[1] because value[0] could be
# different from name (lowercase/uppercase)
return value[0], value[1]
except:
break


def set_env(name, value, current=True):
"""Set HKCU/HKLM environment variables"""
root = (
winreg.HKEY_CURRENT_USER
if current
else winreg.HKEY_LOCAL_MACHINE
)
key = winreg.OpenKey(root, "Environment")
try:
_x, key_type = winreg.QueryValueEx(key, name)
except WindowsError:
key_type = winreg.REG_EXPAND_SZ
key = winreg.OpenKey(
root, "Environment", 0, winreg.KEY_SET_VALUE
)
winreg.SetValueEx(key, name, 0, key_type, value)
from win32gui import SendMessageTimeout
from win32con import (
HWND_BROADCAST,
WM_SETTINGCHANGE,
SMTO_ABORTIFHUNG,
)

SendMessageTimeout(
HWND_BROADCAST,
WM_SETTINGCHANGE,
0,
"Environment",
SMTO_ABORTIFHUNG,
5000,
)


#==============================================================================
# https://stackoverflow.com/questions/580924/how-to-access-a-files-properties-on-windows
def getFileProperties(fname):
Expand Down Expand Up @@ -210,7 +151,7 @@ def remove_winpython_start_menu_folder(current=True):
path = get_winpython_start_menu_folder(current=current)
if Path(path).is_dir():
try:
shutil.rmtree(path, onerror=onerror)
shutil.rmtree(path, onexc=onerror)
except WindowsError:
print(
f"Directory {path} could not be removed",
Expand All @@ -222,7 +163,7 @@ def create_winpython_start_menu_folder(current=True):
path = get_winpython_start_menu_folder(current=current)
if Path(path).is_dir():
try:
shutil.rmtree(path, onerror=onerror)
shutil.rmtree(path, onexc=onerror)
except WindowsError:
print(
f"Directory {path} could not be removed",
Expand Down Expand Up @@ -629,7 +570,7 @@ def _create_temp_dir():
"""Create a temporary directory and remove it at exit"""
tmpdir = tempfile.mkdtemp(prefix='wppm_')
atexit.register(
lambda path: shutil.rmtree(path, onerror=onerror),
lambda path: shutil.rmtree(path, onexc=onerror),
tmpdir,
)
return tmpdir
Expand Down Expand Up @@ -744,7 +685,7 @@ def buildflit_wininst(
)
)
# remove tempo dir 'root' no more needed
shutil.rmtree(root, onerror=onerror)
shutil.rmtree(root, onexc=onerror)
return dst_fname


Expand Down
2 changes: 1 addition & 1 deletion winpython/wppm.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def clean_up(self):
"""Remove directories which couldn't be removed when building"""
for path in self.to_be_removed:
try:
shutil.rmtree(p 4C15 ath, onerror=utils.onerror)
shutil.rmtree(path, onexc=utils.onerror)
except WindowsError:
print(
f"Directory {path} could not be removed",
Expand Down
0