From 57b00c6105e63f9143fd269dd3fd79b56c247a50 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Sat, 23 Dec 2023 20:12:17 -0500 Subject: [PATCH 1/2] [Minor] Minor Code Tweaks Officially Deprecates ttkHyperlinkLabel/openurl() function, a few minor code readability updates, and updates dependencies --- l10n.py | 2 +- requirements-dev.txt | 8 ++++---- stats.py | 4 +++- td.py | 2 +- ttkHyperlinkLabel.py | 9 ++++++--- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/l10n.py b/l10n.py index 26be12fc..a34ea0dc 100755 --- a/l10n.py +++ b/l10n.py @@ -25,7 +25,7 @@ from config import config from EDMCLogging import get_main_logger if TYPE_CHECKING: - def _(x: str) -> str: ... + def _(x: str) -> str: return x # Note that this is also done in EDMarketConnector.py, and thus removing this here may not have a desired effect try: diff --git a/requirements-dev.txt b/requirements-dev.txt index 7fb98e50..331a117b 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.0.2 +setuptools==69.0.3 # Static analysis tools flake8==6.1.0 @@ -18,7 +18,7 @@ flake8-noqa==1.3.2 flake8-polyfill==1.0.2 flake8-use-fstring==1.4 -mypy==1.7.1 +mypy==1.8.0 pep8-naming==0.13.3 safety==2.3.5 types-requests==2.31.0.10 @@ -28,7 +28,7 @@ types-pkg-resources==0.1.3 autopep8==2.0.4 # Git pre-commit checking -pre-commit==3.5.0 +pre-commit==3.6.0 # HTML changelogs grip==4.6.2 @@ -40,7 +40,7 @@ py2exe==0.13.0.1; sys_platform == 'win32' # Testing pytest==7.4.3 pytest-cov==4.1.0 # Pytest code coverage support -coverage[toml]==7.3.2 # pytest-cov dep. This is here to ensure that it includes TOML support for pyproject.toml configs +coverage[toml]==7.3.4 # pytest-cov dep. This is here to ensure that it includes TOML support for pyproject.toml configs coverage-conditional-plugin==0.9.0 # For manipulating folder permissions and the like. pywin32==306; sys_platform == 'win32' diff --git a/stats.py b/stats.py index 041e47f3..4351e297 100644 --- a/stats.py +++ b/stats.py @@ -5,6 +5,8 @@ Copyright (c) EDCD, All Rights Reserved Licensed under the GNU General Public License. See LICENSE file. """ +from __future__ import annotations + import csv import json import sys @@ -22,7 +24,7 @@ from monitor import monitor logger = EDMCLogging.get_main_logger() if TYPE_CHECKING: - def _(x: str) -> str: ... + def _(x: str) -> str: return x if sys.platform == 'win32': import ctypes diff --git a/td.py b/td.py index 00dd1736..6a588f57 100644 --- a/td.py +++ b/td.py @@ -32,7 +32,7 @@ def export(data: CAPIData) -> None: with open(data_path / data_filename, 'wb') as h: # Format described here: https://github.com/eyeonus/Trade-Dangerous/wiki/Price-Data h.write('#! trade.py import -\n'.encode('utf-8')) - this_platform = sys.platform == 'darwin' and "Mac OS" or system() + this_platform = "Mac OS" if sys.platform == 'darwin' else system() cmdr_name = data['commander']['name'].strip() h.write( f'# Created by {applongname} {appversion()} on {this_platform} for Cmdr {cmdr_name}.\n'.encode('utf-8') diff --git a/ttkHyperlinkLabel.py b/ttkHyperlinkLabel.py index 24470a93..fcb973ec 100644 --- a/ttkHyperlinkLabel.py +++ b/ttkHyperlinkLabel.py @@ -22,20 +22,21 @@ from __future__ import annotations import sys import tkinter as tk +import warnings import webbrowser from tkinter import font as tk_font from tkinter import ttk from typing import TYPE_CHECKING, Any if TYPE_CHECKING: - def _(x: str) -> str: ... + def _(x: str) -> str: return x # FIXME: Split this into multi-file module to separate the platforms class HyperlinkLabel(sys.platform == 'darwin' and tk.Label or ttk.Label): # type: ignore """Clickable label for HTTP links.""" - def __init__(self, master: tk.Frame | None = None, **kw: Any) -> None: + def __init__(self, master: ttk.Frame | None = None, **kw: Any) -> None: """ Initialize the HyperlinkLabel. @@ -135,7 +136,7 @@ class HyperlinkLabel(sys.platform == 'darwin' and tk.Label or ttk.Label): # typ url = self.url(self['text']) if callable(self.url) else self.url if url: self._leave(event) # Remove underline before we change window to browser - openurl(url) + webbrowser.open(url) def _contextmenu(self, event: tk.Event) -> None: if self['text'] and (self.popup_copy(self['text']) if callable(self.popup_copy) else self.popup_copy): @@ -183,4 +184,6 @@ def openurl(url: str) -> None: ended up using `webbrowser.open()` *anyway*. :param url: URL to open. """ + warnings.warn("This function is deprecated. " + "Please use `webbrowser.open() instead.", DeprecationWarning, stacklevel=2) webbrowser.open(url) From f7a23b5b6f67d316d1ba18579f042d2810079871 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Sat, 23 Dec 2023 20:12:34 -0500 Subject: [PATCH 2/2] [Minor] Bump Python Version, Update GitIgnore --- .gitignore | 1 + .python-version | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 4283fcb0..a7da806e 100644 --- a/.gitignore +++ b/.gitignore @@ -52,6 +52,7 @@ htmlcov/ .coverage pylintrc pylint.txt +.pylintrc # Ignore Submodule data directory coriolis-data/ diff --git a/.python-version b/.python-version index 371cfe35..d4b278f0 100644 --- a/.python-version +++ b/.python-version @@ -1 +1 @@ -3.11.1 +3.11.7