From b0e682f66c0fa157a5f8cab54b78966a2e2d0b3b Mon Sep 17 00:00:00 2001 From: Bruno Marques Date: Sun, 9 Jun 2024 18:40:03 +0100 Subject: [PATCH 1/5] Enabled DeprecationWarning by default and fixed references --- EDMCLogging.py | 3 +++ config/__init__.py | 21 +++++++++++---------- l10n.py | 10 +++++----- myNotebook.py | 5 +++-- prefs.py | 7 +++---- 5 files changed, 25 insertions(+), 21 deletions(-) diff --git a/EDMCLogging.py b/EDMCLogging.py index 74b439f9..b6d4b353 100644 --- a/EDMCLogging.py +++ b/EDMCLogging.py @@ -42,6 +42,7 @@ import logging.handlers import os import pathlib import tempfile +import warnings from contextlib import suppress from fnmatch import fnmatch # So that any warning about accessing a protected member is only in one place. @@ -99,6 +100,8 @@ logging.Logger.trace = lambda self, message, *args, **kwargs: self._log( # type # MAGIC-CONT: See MAGIC tagged comment in Logger.__init__() logging.Formatter.converter = gmtime +warnings.simplefilter('default', DeprecationWarning) + def _trace_if(self: logging.Logger, condition: str, message: str, *args, **kwargs) -> None: if any(fnmatch(condition, p) for p in config_mod.trace_on): diff --git a/config/__init__.py b/config/__init__.py index fe258475..9636d49a 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -41,7 +41,6 @@ import pathlib import re import subprocess import sys -import traceback import warnings from abc import abstractmethod from typing import Any, Callable, Type, TypeVar @@ -329,8 +328,7 @@ class AbstractConfig(abc.ABC): :raises OSError: On Windows, if a Registry error occurs. :return: The data or the default. """ - warnings.warn(DeprecationWarning('get is Deprecated. use the specific getter for your type')) - logger.debug('Attempt to use Deprecated get() method\n' + ''.join(traceback.format_stack())) + warnings.warn('get is Deprecated. use the specific getter for your type', DeprecationWarning, stacklevel=2) if (a_list := self._suppress_call(self.get_list, ValueError, key, default=None)) is not None: return a_list @@ -388,8 +386,7 @@ class AbstractConfig(abc.ABC): See get_int for its replacement. :raises OSError: On Windows, if a Registry error occurs. """ - warnings.warn(DeprecationWarning('getint is Deprecated. Use get_int instead')) - logger.debug('Attempt to use Deprecated getint() method\n' + ''.join(traceback.format_stack())) + warnings.warn('getint is Deprecated. Use get_int instead', DeprecationWarning, stacklevel=2) return self.get_int(key, default=default) @@ -448,15 +445,15 @@ class AbstractConfig(abc.ABC): def get_password(self, account: str) -> None: """Legacy password retrieval.""" - warnings.warn("password subsystem is no longer supported", DeprecationWarning) + warnings.warn("password subsystem is no longer supported", DeprecationWarning, stacklevel=2) def set_password(self, account: str, password: str) -> None: """Legacy password setting.""" - warnings.warn("password subsystem is no longer supported", DeprecationWarning) + warnings.warn("password subsystem is no longer supported", DeprecationWarning, stacklevel=2) def delete_password(self, account: str) -> None: """Legacy password deletion.""" - warnings.warn("password subsystem is no longer supported", DeprecationWarning) + warnings.warn("password subsystem is no longer supported", DeprecationWarning, stacklevel=2) def get_config(*args, **kwargs) -> AbstractConfig: @@ -489,5 +486,9 @@ def get_update_feed() -> str: return 'https://raw.githubusercontent.com/EDCD/EDMarketConnector/releases/edmarketconnector.xml' -# WARNING: update_feed is deprecated, and will be removed in 6.0 or later. Please migrate to get_update_feed() -update_feed = get_update_feed() +def __getattr__(name: str): + if name == 'update_feed': + warnings.warn('update_feed is deprecated, and will be removed in 6.0 or later. ' + 'Please migrate to get_update_feed()', DeprecationWarning, stacklevel=2) + return get_update_feed() + raise AttributeError(name=name) diff --git a/l10n.py b/l10n.py index 27cd95c5..79bab04a 100755 --- a/l10n.py +++ b/l10n.py @@ -263,15 +263,15 @@ class _Locale: """Locale holds a few utility methods to convert data to and from localized versions.""" def stringFromNumber(self, number: float | int, decimals: int | None = None) -> str: # noqa: N802 - warnings.warn(DeprecationWarning('use _Locale.string_from_number instead.')) + warnings.warn('use _Locale.string_from_number instead.', DeprecationWarning, stacklevel=2) return self.string_from_number(number, decimals) # type: ignore def numberFromString(self, string: str) -> int | float | None: # noqa: N802 - warnings.warn(DeprecationWarning('use _Locale.number_from_string instead.')) + warnings.warn('use _Locale.number_from_string instead.', DeprecationWarning, stacklevel=2) return self.number_from_string(string) def preferredLanguages(self) -> Iterable[str]: # noqa: N802 - warnings.warn(DeprecationWarning('use _Locale.preferred_languages instead.')) + warnings.warn('use _Locale.preferred_languages instead.', DeprecationWarning, stacklevel=2) return self.preferred_languages() def string_from_number(self, number: float | int, decimals: int = 5) -> str: @@ -367,8 +367,8 @@ translations = Translations() # Begin Deprecation Zone class _Translations(Translations): def __init__(self): - logger.warning(DeprecationWarning('Translations and _Translations() are deprecated. ' - 'Please use translations and Translations() instead.')) + warnings.warn('Translations and _Translations() are deprecated. ' + 'Please use translations and Translations() instead.', DeprecationWarning, stacklevel=2) super().__init__() diff --git a/myNotebook.py b/myNotebook.py index 0b083c23..d8b2b41b 100644 --- a/myNotebook.py +++ b/myNotebook.py @@ -11,6 +11,7 @@ from __future__ import annotations import sys import tkinter as tk +import warnings from tkinter import ttk, messagebox from PIL import ImageGrab from l10n import translations as tr @@ -124,8 +125,8 @@ class EntryMenu(ttk.Entry): class Entry(EntryMenu): """Custom ttk.Entry class to fix some display issues.""" - # DEPRECATED: Migrate to EntryMenu. Will remove in 6.0 or later. def __init__(self, master: ttk.Frame | None = None, **kw): + warnings.warn('Migrate to EntryMenu. Will remove in 6.0 or later.', DeprecationWarning, stacklevel=2) EntryMenu.__init__(self, master, **kw) @@ -142,8 +143,8 @@ class Button(ttk.Button): class ColoredButton(tk.Button): """Custom tk.Button class to fix some display issues.""" - # DEPRECATED: Migrate to tk.Button. Will remove in 6.0 or later. def __init__(self, master: ttk.Frame | None = None, **kw): + warnings.warn('Migrate to tk.Button. Will remove in 6.0 or later.', DeprecationWarning, stacklevel=2) tk.Button.__init__(self, master, **kw) diff --git a/prefs.py b/prefs.py index 7f217ac8..136b52de 100644 --- a/prefs.py +++ b/prefs.py @@ -9,6 +9,7 @@ import subprocess import sys import tempfile import tkinter as tk +import warnings from os import system from os.path import expanduser, expandvars, join, normpath from tkinter import colorchooser as tkColorChooser # type: ignore # noqa: N812 @@ -40,10 +41,8 @@ logger = get_main_logger() def help_open_log_folder() -> None: """Open the folder logs are stored in.""" - logger.warning( - DeprecationWarning("This function is deprecated, use open_log_folder instead. " - "This function will be removed in 6.0 or later") - ) + warnings.warn('prefs.help_open_log_folder is deprecated, use open_log_folder instead. ' + 'This function will be removed in 6.0 or later', DeprecationWarning, stacklevel=2) open_folder(pathlib.Path(tempfile.gettempdir()) / appname) From 192ba5f8f27f12b5b5365f031eb176c893432446 Mon Sep 17 00:00:00 2001 From: Bruno Marques Date: Sun, 9 Jun 2024 20:07:13 +0100 Subject: [PATCH 2/5] Adding pkg_resources exception to DeprecationWarning --- EDMCLogging.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/EDMCLogging.py b/EDMCLogging.py index b6d4b353..ab53dbec 100644 --- a/EDMCLogging.py +++ b/EDMCLogging.py @@ -101,6 +101,8 @@ logging.Logger.trace = lambda self, message, *args, **kwargs: self._log( # type logging.Formatter.converter = gmtime warnings.simplefilter('default', DeprecationWarning) +# TODO remove after infi.systray drops pkg_resources +warnings.filterwarnings('ignore', '.*pkg_resources', DeprecationWarning) def _trace_if(self: logging.Logger, condition: str, message: str, *args, **kwargs) -> None: From 13e74f2c575ae56731e2e4a1e8ff68dba4536786 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Sun, 9 Jun 2024 15:28:27 -0400 Subject: [PATCH 3/5] [2255] Replace Infi Systray with simplesystray --- EDMCLogging.py | 2 -- EDMarketConnector.py | 4 ++-- requirements-dev.txt | 2 +- requirements.txt | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/EDMCLogging.py b/EDMCLogging.py index ab53dbec..b6d4b353 100644 --- a/EDMCLogging.py +++ b/EDMCLogging.py @@ -101,8 +101,6 @@ logging.Logger.trace = lambda self, message, *args, **kwargs: self._log( # type logging.Formatter.converter = gmtime warnings.simplefilter('default', DeprecationWarning) -# TODO remove after infi.systray drops pkg_resources -warnings.filterwarnings('ignore', '.*pkg_resources', DeprecationWarning) def _trace_if(self: logging.Logger, condition: str, message: str, *args, **kwargs) -> None: diff --git a/EDMarketConnector.py b/EDMarketConnector.py index e1524b00..cd76ccc0 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -396,7 +396,7 @@ if TYPE_CHECKING: from logging import TRACE # type: ignore # noqa: F401 # Needed to update mypy if sys.platform == 'win32': - from infi.systray import SysTrayIcon + from simplesystray import SysTrayIcon # isort: on @@ -452,7 +452,7 @@ class AppWindow: self.prefsdialog = None if sys.platform == 'win32': - from infi.systray import SysTrayIcon + from simplesystray import SysTrayIcon def open_window(systray: 'SysTrayIcon') -> None: self.w.deiconify() diff --git a/requirements-dev.txt b/requirements-dev.txt index 19e55b66..7c8e1ef5 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -5,7 +5,7 @@ wheel # We can't rely on just picking this up from either the base (not venv), # or venv-init-time version. Specify here so that dependabot will prod us # about new versions. -setuptools==69.2.0 +setuptools==70.0.0 # Static analysis tools flake8==7.0.0 diff --git a/requirements.txt b/requirements.txt index 83fa9c0d..22f0a360 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ requests==2.32.3 pillow==10.3.0 watchdog==4.0.0 -infi.systray==0.1.12; sys_platform == 'win32' +simplesystray==0.1.0; sys_platform == 'win32' semantic-version==2.10.0 From 7d5fdb2b84de93900c5732672762763eec2ee8e8 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Sun, 9 Jun 2024 15:52:44 -0400 Subject: [PATCH 4/5] [2255] Update Dep Comment Format --- config/__init__.py | 5 +++++ l10n.py | 15 ++++++++------- myNotebook.py | 2 ++ prefs.py | 2 +- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/config/__init__.py b/config/__init__.py index 9636d49a..b4dec93a 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -328,6 +328,7 @@ class AbstractConfig(abc.ABC): :raises OSError: On Windows, if a Registry error occurs. :return: The data or the default. """ + # DEPRECATED: Migrate to specific type getters. Will remove in 6.0 or later. warnings.warn('get is Deprecated. use the specific getter for your type', DeprecationWarning, stacklevel=2) if (a_list := self._suppress_call(self.get_list, ValueError, key, default=None)) is not None: @@ -386,6 +387,7 @@ class AbstractConfig(abc.ABC): See get_int for its replacement. :raises OSError: On Windows, if a Registry error occurs. """ + # DEPRECATED: Migrate to get_int. Will remove in 6.0 or later. warnings.warn('getint is Deprecated. Use get_int instead', DeprecationWarning, stacklevel=2) return self.get_int(key, default=default) @@ -443,6 +445,7 @@ class AbstractConfig(abc.ABC): """Close this config and release any associated resources.""" raise NotImplementedError +# DEPRECATED: Password system doesn't do anything. Will remove in 6.0 or later. def get_password(self, account: str) -> None: """Legacy password retrieval.""" warnings.warn("password subsystem is no longer supported", DeprecationWarning, stacklevel=2) @@ -454,6 +457,7 @@ class AbstractConfig(abc.ABC): def delete_password(self, account: str) -> None: """Legacy password deletion.""" warnings.warn("password subsystem is no longer supported", DeprecationWarning, stacklevel=2) +# End Dep Zone def get_config(*args, **kwargs) -> AbstractConfig: @@ -486,6 +490,7 @@ def get_update_feed() -> str: return 'https://raw.githubusercontent.com/EDCD/EDMarketConnector/releases/edmarketconnector.xml' +# DEPRECATED: Migrate to get_update_feed(). Will remove in 6.0 or later. def __getattr__(name: str): if name == 'update_feed': warnings.warn('update_feed is deprecated, and will be removed in 6.0 or later. ' diff --git a/l10n.py b/l10n.py index 79bab04a..5798a1af 100755 --- a/l10n.py +++ b/l10n.py @@ -86,8 +86,7 @@ class Translations: Use when translation is not desired or not available """ self.translations = {None: {}} - # WARNING: '_' is Deprecated. Will be removed in 6.0 or later. - # Migrate to calling translations.translate or tr.tl directly. + # DEPRECATED: Migrate to translations.translate or tr.tl. Will remove in 6.0 or later. builtins.__dict__['_'] = lambda x: str(x).replace(r'\"', '"').replace('{CR}', '\n') def install(self, lang: str | None = None) -> None: # noqa: CCR001 @@ -131,8 +130,7 @@ class Translations: except Exception: logger.exception(f'Exception occurred while parsing {lang}.strings in plugin {plugin}') - # WARNING: '_' is Deprecated. Will be removed in 6.0 or later. - # Migrate to calling translations.translate or tr.tl directly. + # DEPRECATED: Migrate to translations.translate or tr.tl. Will remove in 6.0 or later. builtins.__dict__['_'] = self.translate def contents(self, lang: str, plugin_path: str | None = None) -> dict[str, str]: @@ -262,14 +260,17 @@ class Translations: class _Locale: """Locale holds a few utility methods to convert data to and from localized versions.""" - def stringFromNumber(self, number: float | int, decimals: int | None = None) -> str: # noqa: N802 + # DEPRECATED: Migrate to _Locale.string_from_number. Will remove in 6.0 or later. + def stringFromNumber(self, number: float | int, decimals: int | None = None) -> str: # noqa: warnings.warn('use _Locale.string_from_number instead.', DeprecationWarning, stacklevel=2) return self.string_from_number(number, decimals) # type: ignore + # DEPRECATED: Migrate to _Locale.number_from_string. Will remove in 6.0 or later. def numberFromString(self, string: str) -> int | float | None: # noqa: N802 warnings.warn('use _Locale.number_from_string instead.', DeprecationWarning, stacklevel=2) return self.number_from_string(string) + # DEPRECATED: Migrate to _Locale.preferred_languages. Will remove in 6.0 or later. def preferredLanguages(self) -> Iterable[str]: # noqa: N802 warnings.warn('use _Locale.preferred_languages instead.', DeprecationWarning, stacklevel=2) return self.preferred_languages() @@ -362,8 +363,8 @@ Locale = _Locale() translations = Translations() -# WARNING: 'Translations' singleton is deprecated. Will be removed in 6.0 or later. -# Migrate to importing 'translations'. +# DEPRECATED: Migrate to `translations`. Will be removed in 6.0 or later. +# 'Translations' singleton is deprecated. # Begin Deprecation Zone class _Translations(Translations): def __init__(self): diff --git a/myNotebook.py b/myNotebook.py index d8b2b41b..c57a6deb 100644 --- a/myNotebook.py +++ b/myNotebook.py @@ -125,6 +125,7 @@ class EntryMenu(ttk.Entry): class Entry(EntryMenu): """Custom ttk.Entry class to fix some display issues.""" + # DEPRECATED: Migrate to EntryMenu. Will remove in 6.0 or later. def __init__(self, master: ttk.Frame | None = None, **kw): warnings.warn('Migrate to EntryMenu. Will remove in 6.0 or later.', DeprecationWarning, stacklevel=2) EntryMenu.__init__(self, master, **kw) @@ -143,6 +144,7 @@ class Button(ttk.Button): class ColoredButton(tk.Button): """Custom tk.Button class to fix some display issues.""" + # DEPRECATED: Migrate to tk.Button. Will remove in 6.0 or later. def __init__(self, master: ttk.Frame | None = None, **kw): warnings.warn('Migrate to tk.Button. Will remove in 6.0 or later.', DeprecationWarning, stacklevel=2) tk.Button.__init__(self, master, **kw) diff --git a/prefs.py b/prefs.py index 136b52de..9f2062f4 100644 --- a/prefs.py +++ b/prefs.py @@ -38,7 +38,7 @@ logger = get_main_logger() # May be imported by plugins - +# DEPRECATED: Migrate to open_log_folder. Will remove in 6.0 or later. def help_open_log_folder() -> None: """Open the folder logs are stored in.""" warnings.warn('prefs.help_open_log_folder is deprecated, use open_log_folder instead. ' From f56302e5077c213b63d5f584ce584651f4689c39 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Sun, 9 Jun 2024 15:56:44 -0400 Subject: [PATCH 5/5] [2255] Fix Removed Comment --- l10n.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/l10n.py b/l10n.py index 5798a1af..8613244f 100755 --- a/l10n.py +++ b/l10n.py @@ -261,7 +261,7 @@ class _Locale: """Locale holds a few utility methods to convert data to and from localized versions.""" # DEPRECATED: Migrate to _Locale.string_from_number. Will remove in 6.0 or later. - def stringFromNumber(self, number: float | int, decimals: int | None = None) -> str: # noqa: + def stringFromNumber(self, number: float | int, decimals: int | None = None) -> str: # noqa: N802 warnings.warn('use _Locale.string_from_number instead.', DeprecationWarning, stacklevel=2) return self.string_from_number(number, decimals) # type: ignore