From 4e2e3d8f61ca35cb7873dc53199d71b69baf00bd Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sat, 4 Oct 2025 01:50:31 +1000 Subject: [PATCH 01/84] [Bugfix] Fix race starting journal monitor Fixes a race identified where long plugin init times can result in the following error being thrown in the journal monitor thread, requiring a preferences reload to have journals continuing to be processed: ``` Exception in thread Journal worker: Traceback (most recent call last): File "/home/testing/.pyenv/versions/3.11.9/lib/python3.11/threading.py", line 1045, in _bootstrap_inner self.run() File "/home/testing/.pyenv/versions/3.11.9/lib/python3.11/threading.py", line 982, in run self._target(*self._args, **self._kwargs) File "/home/testing/gitstuff/EDMarketConnector/monitor.py", line 461, in worker self.root.event_generate('<>', when="tail") File "/home/testing/.pyenv/versions/3.11.9/lib/python3.11/tkinter/__init__.py", line 1933, in event_generate self.tk.call(args) RuntimeError: main thread is not in main loop ``` --- EDMarketConnector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 1b45225a..54d84ef8 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -754,7 +754,7 @@ class AppWindow: config.delete('username', suppress=True) config.delete('password', suppress=True) config.delete('logdir', suppress=True) - self.postprefs(False) # Companion login happens in callback from monitor + self.w.after_idle(lambda: self.postprefs(False)) # Companion login happens in callback from monitor self.toggle_suit_row(visible=False) if args.start_min: logger.warning("Trying to start minimized") From 13487ff7630851f0b9105d3eb97c96da47ec95dd Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sat, 4 Oct 2025 21:58:21 +1000 Subject: [PATCH 02/84] [Bugfix] Fix EDDN queue not processing at startup Workaround the `.after()` queue being cleared (or invalidated) when the widget that call was made through is destroyed after that call is made, which in this case resulted in the EDDN queue not being processed until some other action re-triggered processing of the EDDN queue. --- plugins/eddn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/eddn.py b/plugins/eddn.py index 39ecf147..028c29c5 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -183,7 +183,7 @@ class EDDNSender: f"First queue run scheduled for {self.eddn.REPLAY_STARTUP_DELAY}ms from now" ) if not os.getenv("EDMC_NO_UI"): - self.eddn.parent.after(self.eddn.REPLAY_STARTUP_DELAY, self.queue_check_and_send, True) + self.eddn.parent.winfo_toplevel().after(self.eddn.REPLAY_STARTUP_DELAY, self.queue_check_and_send, True) def sqlite_queue_v1(self) -> sqlite3.Connection: """ From cbc2f02f6e0baac091b8e603b6734a426b6b8721 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 1 Nov 2025 17:00:44 +0000 Subject: [PATCH 03/84] Bump actions/download-artifact from 5 to 6 Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 5 to 6. - [Release notes](https://github.com/actions/download-artifact/releases) - [Commits](https://github.com/actions/download-artifact/compare/v5...v6) --- updated-dependencies: - dependency-name: actions/download-artifact dependency-version: '6' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/windows-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml index 1d43c3c7..b1ccb182 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -155,7 +155,7 @@ jobs: steps: - name: Download binary - uses: actions/download-artifact@v5 + uses: actions/download-artifact@v6 with: name: Built files path: ./ From 5a50af3dade11f65ca7c9be94fc0767e4fb7af33 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 1 Nov 2025 17:00:48 +0000 Subject: [PATCH 04/84] Bump github/codeql-action from 3 to 4 Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3 to 4. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/v3...v4) --- updated-dependencies: - dependency-name: github/codeql-action dependency-version: '4' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/codeql.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index c1713fd7..a9e5e523 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -63,7 +63,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v3 + uses: github/codeql-action/init@v4 with: languages: ${{ matrix.language }} build-mode: ${{ matrix.build-mode }} @@ -90,6 +90,6 @@ jobs: exit 1 - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v3 + uses: github/codeql-action/analyze@v4 with: category: "/language:${{matrix.language}}" From 47d2508f173c6bf410356e29a85fc7592b29149a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 1 Nov 2025 17:00:51 +0000 Subject: [PATCH 05/84] Bump actions/upload-artifact from 4 to 5 Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4 to 5. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/v4...v5) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-version: '5' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/windows-build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml index 1d43c3c7..8be6b9d9 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -62,7 +62,7 @@ jobs: mv "../EDMarketConnector-release-${{ needs.variables.outputs.sem_ver }}.tar.gz" . - name: Upload build files - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v5 with: name: built-files-linux path: | @@ -131,7 +131,7 @@ jobs: Get-ChildItem -Path . -Filter "EDMarketConnector_Installer_*.exe" | Rename-Item -NewName {"EDMarketConnector_Installer_Unsigned_$($_.Name -replace '^EDMarketConnector_Installer_', '')"} - name: Upload build files - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v5 with: name: built-files-windows path: | @@ -142,7 +142,7 @@ jobs: needs: [ windows_build, linux_build ] steps: - name: Merge Artifacts - uses: actions/upload-artifact/merge@v4 + uses: actions/upload-artifact/merge@v5 with: name: Built files pattern: built-files-* From 33333e33100a12ae5c40eef60e38bc65d10e8077 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 1 Nov 2025 17:01:01 +0000 Subject: [PATCH 06/84] Bump pytest-cov from 6.1.1 to 7.0.0 Bumps [pytest-cov](https://github.com/pytest-dev/pytest-cov) from 6.1.1 to 7.0.0. - [Changelog](https://github.com/pytest-dev/pytest-cov/blob/master/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest-cov/compare/v6.1.1...v7.0.0) --- updated-dependencies: - dependency-name: pytest-cov dependency-version: 7.0.0 dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index ef9c84c0..95d06f43 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -35,7 +35,7 @@ py2exe==0.13.0.2; sys_platform == 'win32' # Testing pytest==8.4.2 -pytest-cov==6.1.1 # Pytest code coverage support +pytest-cov==7.0.0 # Pytest code coverage support coverage[toml]==7.11.0 # pytest-cov dep. This is here to ensure that it includes TOML support for pyproject.toml configs coverage-conditional-plugin==0.9.0 From eac3f1fb209f7d82d8de736ad6b3caab30103bd3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 1 Nov 2025 17:01:04 +0000 Subject: [PATCH 07/84] Bump psutil from 7.1.0 to 7.1.2 Bumps [psutil](https://github.com/giampaolo/psutil) from 7.1.0 to 7.1.2. - [Changelog](https://github.com/giampaolo/psutil/blob/master/HISTORY.rst) - [Commits](https://github.com/giampaolo/psutil/compare/release-7.1.0...release-7.1.2) --- updated-dependencies: - dependency-name: psutil dependency-version: 7.1.2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 05a05733..0f5e497a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,4 @@ simplesystray==0.1.0; sys_platform == 'win32' semantic-version==2.10.0 # For manipulating folder permissions and the like. pywin32==310; sys_platform == 'win32' -psutil==7.1.0 +psutil==7.1.2 From 003690fa34e12477103e4bd6b1aa35deb13f7626 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 1 Nov 2025 17:01:07 +0000 Subject: [PATCH 08/84] Bump types-setuptools from 80.9.0.20250529 to 80.9.0.20250822 Bumps [types-setuptools](https://github.com/typeshed-internal/stub_uploader) from 80.9.0.20250529 to 80.9.0.20250822. - [Commits](https://github.com/typeshed-internal/stub_uploader/commits) --- updated-dependencies: - dependency-name: types-setuptools dependency-version: 80.9.0.20250822 dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index ef9c84c0..6eb38014 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -18,7 +18,7 @@ mypy==1.18.2 pep8-naming==0.15.1 safety==3.6.2 types-requests==2.32.0.20250328 -types-setuptools==80.9.0.20250529 +types-setuptools==80.9.0.20250822 # Code formatting tools autopep8==2.3.2 From cf5a05136a1635ef27635d2c5c45f1b82737cf1a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 1 Nov 2025 17:01:11 +0000 Subject: [PATCH 09/84] Bump pre-commit from 4.2.0 to 4.3.0 Bumps [pre-commit](https://github.com/pre-commit/pre-commit) from 4.2.0 to 4.3.0. - [Release notes](https://github.com/pre-commit/pre-commit/releases) - [Changelog](https://github.com/pre-commit/pre-commit/blob/main/CHANGELOG.md) - [Commits](https://github.com/pre-commit/pre-commit/compare/v4.2.0...v4.3.0) --- updated-dependencies: - dependency-name: pre-commit dependency-version: 4.3.0 dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index ef9c84c0..d386f4cf 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -24,7 +24,7 @@ types-setuptools==80.9.0.20250529 autopep8==2.3.2 # Git pre-commit checking -pre-commit==4.2.0 +pre-commit==4.3.0 # HTML changelogs mistune==3.1.3 From f1c180caf19dcc3d566985444bd2957e68b540fb Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Sun, 9 Nov 2025 12:43:32 -0500 Subject: [PATCH 10/84] [#2113] Update Python Version to 3.13 --- .pre-commit-config.yaml | 2 +- .python-version | 2 +- ChangeLog.md | 2 +- requirements-dev.txt | 19 +++++++++---------- requirements.txt | 4 ++-- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 27544fce..8339f184 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -77,7 +77,7 @@ repos: always_run: true default_language_version: - python: python3.11 + python: python3.13 default_stages: [ pre-commit, pre-push ] diff --git a/.python-version b/.python-version index 2c073331..24ee5b1b 100644 --- a/.python-version +++ b/.python-version @@ -1 +1 @@ -3.11 +3.13 diff --git a/ChangeLog.md b/ChangeLog.md index b30b82b7..8bab3370 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,6 +1,6 @@ This is the master changelog for Elite Dangerous Market Connector. Entries are in reverse chronological order (latest first). --- -* We currently test against, and package with, Python 3.11, 32-bit. +* We currently test against, and package with, Python 3.13, 32-bit. * As a result, we do not support Windows 7, 8, or 8.1. * Developers can check the contents of the `.python-version` file in the source (not distributed with the Windows installer) for the diff --git a/requirements-dev.txt b/requirements-dev.txt index c64cac64..7ad17560 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -4,39 +4,38 @@ setuptools==80.9.0 # Static analysis tools -flake8==7.2.0 +flake8==7.3.0 flake8-annotations-coverage==0.0.6 flake8-cognitive-complexity==0.1.0 -flake8-comprehensions==3.16.0 +flake8-comprehensions==3.17.0 flake8-docstrings==1.7.0 flake8-json==24.4.0 flake8-noqa==1.4.0 -flake8-polyfill==1.0.2 flake8-use-fstring==1.4 mypy==1.18.2 pep8-naming==0.15.1 -safety==3.6.2 -types-requests==2.32.0.20250328 +safety==3.7.0 +types-requests==2.32.4.20250913 types-setuptools==80.9.0.20250822 # Code formatting tools autopep8==2.3.2 # Git pre-commit checking -pre-commit==4.3.0 +pre-commit==4.4.0 # HTML changelogs -mistune==3.1.3 +mistune==3.1.4 # Packaging # We only need py2exe on windows. -py2exe==0.13.0.2; sys_platform == 'win32' +py2exe==0.14.0.0; sys_platform == 'win32' # Testing -pytest==8.4.2 +pytest==9.0.0 pytest-cov==7.0.0 # Pytest code coverage support -coverage[toml]==7.11.0 # pytest-cov dep. This is here to ensure that it includes TOML support for pyproject.toml configs +coverage[toml]==7.11.2 # pytest-cov dep. This is here to ensure that it includes TOML support for pyproject.toml configs coverage-conditional-plugin==0.9.0 diff --git a/requirements.txt b/requirements.txt index 0f5e497a..10b4ac67 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,5 +4,5 @@ watchdog==6.0.0 simplesystray==0.1.0; sys_platform == 'win32' semantic-version==2.10.0 # For manipulating folder permissions and the like. -pywin32==310; sys_platform == 'win32' -psutil==7.1.2 +pywin32==311; sys_platform == 'win32' +psutil==7.1.3 From 26db3ad0995882e57aaf0d46c82c5e0ed947d1c2 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Sun, 9 Nov 2025 13:37:14 -0500 Subject: [PATCH 11/84] [2113] Initiate ProtocolHandler, refactor WndProc for x64 --- protocol.py | 296 +++++++++++++++++++++++++++++----------------------- 1 file changed, 166 insertions(+), 130 deletions(-) diff --git a/protocol.py b/protocol.py index 58ee9fa3..cec4333a 100644 --- a/protocol.py +++ b/protocol.py @@ -5,6 +5,7 @@ Copyright (c) EDCD, All Rights Reserved Licensed under the GNU General Public License. See LICENSE file. """ + from __future__ import annotations import os @@ -23,8 +24,8 @@ logger = get_main_logger() is_wine = False -if sys.platform == 'win32': - is_wine = bool(os.getenv('WINEPREFIX')) +if sys.platform == "win32": + is_wine = bool(os.getenv("WINEPREFIX")) class GenericProtocolHandler: @@ -32,10 +33,10 @@ class GenericProtocolHandler: def __init__(self) -> None: self.redirect = protocolhandler_redirect # Base redirection URL - self.master: 'tkinter.Tk' = None # type: ignore + self.master: tkinter.Tk = None # type: ignore self.lastpayload: str | None = None - def start(self, master: 'tkinter.Tk') -> None: + def start(self, master: tkinter.Tk) -> None: """Start Protocol Handler.""" self.master = master @@ -46,29 +47,50 @@ class GenericProtocolHandler: """Generate an auth event.""" self.lastpayload = url - logger.trace_if('frontier-auth', f'Payload: {self.lastpayload}') + logger.trace_if("frontier-auth", f"Payload: {self.lastpayload}") if not config.shutting_down: logger.debug('event_generate("<>")') - self.master.event_generate('<>', when="tail") + self.master.event_generate("<>", when="tail") -if (config.auth_force_edmc_protocol # noqa: C901 - or ( - sys.platform == 'win32' - and getattr(sys, 'frozen', False) - and not is_wine - and not config.auth_force_localserver - )): +if config.auth_force_edmc_protocol or ( # noqa: C901 + sys.platform == "win32" + and getattr(sys, "frozen", False) + and not is_wine + and not config.auth_force_localserver +): # This could be false if you use auth_force_edmc_protocol, but then you get to keep the pieces - if sys.platform != 'win32': + if sys.platform != "win32": raise EnvironmentError("This code is for Windows only.") # spell-checker: words HBRUSH HICON WPARAM wstring WNDCLASS HMENU HGLOBAL from ctypes import ( # type: ignore - windll, POINTER, WINFUNCTYPE, Structure, byref, c_long, c_void_p, create_unicode_buffer, wstring_at + windll, + POINTER, + WINFUNCTYPE, + Structure, + byref, + c_long, + c_void_p, + create_unicode_buffer, + wstring_at, ) from ctypes.wintypes import ( - ATOM, BOOL, HBRUSH, HGLOBAL, HICON, HINSTANCE, HWND, INT, LPARAM, LPCWSTR, LPMSG, LPVOID, LPWSTR, - MSG, UINT, WPARAM + ATOM, + BOOL, + HBRUSH, + HGLOBAL, + HICON, + HINSTANCE, + HWND, + INT, + LPARAM, + LPCWSTR, + LPMSG, + LPVOID, + LPWSTR, + MSG, + UINT, + WPARAM, ) import win32gui import win32api @@ -83,16 +105,16 @@ if (config.auth_force_edmc_protocol # noqa: C901 """ _fields_ = [ - ('style', UINT), - ('lpfnWndProc', WINFUNCTYPE(c_long, HWND, UINT, WPARAM, LPARAM)), - ('cbClsExtra', INT), - ('cbWndExtra', INT), - ('hInstance', HINSTANCE), - ('hIcon', HICON), - ('hCursor', c_void_p), - ('hbrBackground', HBRUSH), - ('lpszMenuName', LPCWSTR), - ('lpszClassName', LPCWSTR) + ("style", UINT), + ("lpfnWndProc", WINFUNCTYPE(c_long, HWND, UINT, WPARAM, LPARAM)), + ("cbClsExtra", INT), + ("cbWndExtra", INT), + ("hInstance", HINSTANCE), + ("hIcon", HICON), + ("hCursor", c_void_p), + ("hbrBackground", HBRUSH), + ("lpszMenuName", LPCWSTR), + ("lpszClassName", LPCWSTR), ] CW_USEDEFAULT = 0x80000000 @@ -140,52 +162,58 @@ if (config.auth_force_edmc_protocol # noqa: C901 # Windows Message handler stuff (IPC) # https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/ms633573(v=vs.85) @WINFUNCTYPE(c_long, HWND, UINT, WPARAM, LPARAM) - def WndProc(hwnd: HWND, message: UINT, wParam: WPARAM, lParam: LPARAM) -> c_long: # noqa: N803 N802 + def WndProc(hwnd: HWND, message: UINT, wParam: WPARAM, lParam: LPARAM) -> int: # noqa: N803 N802 """ - Deal with DDE requests. + Windows message procedure for handling DDE requests. - :param hwnd: Window handle - :param message: The message being sent - :param wParam: Additional Message Information (depends on message type) - :param lParam: Also additional message information - :return: ??? + This routine responds to WM_DDE_INITIATE messages for the application's + DDE service (the app name) and topic ("System"). It sends an ACK if the + incoming atoms match the expected values. + + Returns int due to Python 3.11+ CTYPES Callback - decorator changes to c_long """ - if message != WM_DDE_INITIATE: - # Not a DDE init message, bail and tell windows to do the default - # https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-defwindowproca?redirectedfrom=MSDN - return win32gui.DefWindowProc(hwnd, message, wParam, lParam) + try: + if message != WM_DDE_INITIATE: + # Let Windows handle all other messages normally + return win32gui.DefWindowProc(hwnd, message, wParam, lParam) - service = create_unicode_buffer(256) - topic = create_unicode_buffer(256) - # Note that lParam is 32 bits, and broken into two 16 bit words. This will break on 64bit as the math is - # wrong - # if nonzero, the target application for which a conversation is requested - lparam_low = lParam & 0xFFFF # type: ignore - # if nonzero, the topic of said conversation - lparam_high = lParam >> 16 # type: ignore + # --- Decode the 64-bit lParam into LOWORD/HIWORD safely --- + # These helper functions handle pointer-sized values correctly on 64-bit builds + lparam_low = win32api.LOWORD(lParam) + lparam_high = win32api.HIWORD(lParam) - # if either of the words are nonzero, they contain - # atoms https://docs.microsoft.com/en-us/windows/win32/dataxchg/about-atom-tables - # which we can read out as shown below, and then compare. + service = create_unicode_buffer(256) + topic = create_unicode_buffer(256) - target_is_valid = lparam_low == 0 or ( - GlobalGetAtomNameW(lparam_low, service, 256) and service.value == appname - ) - - topic_is_valid = lparam_high == 0 or ( - GlobalGetAtomNameW(lparam_high, topic, 256) and topic.value.lower() == 'system' - ) - - if target_is_valid and topic_is_valid: - # if everything is happy, send an acknowledgement of the DDE request - SendMessageW( - wParam, WM_DDE_ACK, hwnd, PackDDElParam(WM_DDE_ACK, GlobalAddAtomW(appname), GlobalAddAtomW('System')) + # --- Retrieve atom names --- + target_is_valid = lparam_low == 0 or ( + GlobalGetAtomNameW(lparam_low, service, 256) + and service.value == appname ) - # It works as a constructor as per - return c_long(0) + topic_is_valid = lparam_high == 0 or ( + GlobalGetAtomNameW(lparam_high, topic, 256) + and topic.value.lower() == "system" + ) - return c_long(1) # This is an utter guess -Ath + if target_is_valid and topic_is_valid: + # Send acknowledgment of successful DDE handshake + SendMessageW( + wParam, + WM_DDE_ACK, + hwnd, + PackDDElParam( + WM_DDE_ACK, GlobalAddAtomW(appname), GlobalAddAtomW("System") + ), + ) + return 0 # Success + + return 1 # Not handled / invalid DDE initiation + + except Exception as e: + # Log unexpected exceptions but don’t crash the message loop + logger.error(f"WndProc error: {e}", exc_info=True) + return win32gui.DefWindowProc(hwnd, message, wParam, lParam) class WindowsProtocolHandler(GenericProtocolHandler): """ @@ -199,10 +227,10 @@ if (config.auth_force_edmc_protocol # noqa: C901 super().__init__() self.thread: threading.Thread | None = None - def start(self, master: 'tkinter.Tk') -> None: + def start(self, master: tkinter.Tk) -> None: """Start the DDE thread.""" super().start(master) - self.thread = threading.Thread(target=self.worker, name='DDE worker') + self.thread = threading.Thread(target=self.worker, name="DDE worker") self.thread.daemon = True self.thread.start() @@ -226,41 +254,33 @@ if (config.auth_force_edmc_protocol # noqa: C901 wndclass.hCursor = None wndclass.hbrBackground = None wndclass.lpszMenuName = None - wndclass.lpszClassName = 'DDEServer' + wndclass.lpszClassName = "DDEServer" if not RegisterClassW(byref(wndclass)): - print('Failed to register Dynamic Data Exchange for cAPI') + print("Failed to register Dynamic Data Exchange for cAPI") return # https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-createwindowexw hwnd = win32gui.CreateWindowEx( - 0, # dwExStyle - 'DDEServer', # lpClassName (use string directly as win32gui expects it) - "DDE Server", # lpWindowName - 0, # dwStyle - win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, - win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, # X, Y, nWidth, nHeight + 0, # dwExStyle + "DDEServer", # lpClassName (use string directly as win32gui expects it) + "DDE Server", # lpWindowName + 0, # dwStyle + win32con.CW_USEDEFAULT, + win32con.CW_USEDEFAULT, + win32con.CW_USEDEFAULT, + win32con.CW_USEDEFAULT, # X, Y, nWidth, nHeight self.master.winfo_id(), # hWndParent - 0, # hMenu (use 0 instead of None for win32gui) - wndclass.hInstance, # hInstance - None # lpParam + 0, # hMenu (use 0 instead of None for win32gui) + wndclass.hInstance, # hInstance + None, # lpParam ) msg = MSG() - # Calls GetMessageW: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getmessagew - # Something is off with the return from this, meaning you'll see: - # Exception ignored on converting result of ctypes callback function: - # Traceback (most recent call last): - # File "C:\Users\Athan\Documents\Devel\EDMarketConnector\protocol.py", line 323, in worker - # while int(GetMessageW(byref(msg), None, 0, 0)) != 0: - # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - # TypeError: 'c_long' object cannot be interpreted as an integer - # - # But it does actually work. Either getting a non-0 value and - # entering the loop, or getting 0 and exiting it. while GetMessageW(byref(msg), None, 0, 0) != 0: - logger.trace_if('frontier-auth.windows', f'DDE message of type: {msg.message}') + logger.trace_if( + "frontier-auth.windows", f"DDE message of type: {msg.message}" + ) if msg.message == WM_DDE_EXECUTE: # GlobalLock does some sort of "please dont move this?" # https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globallock @@ -268,28 +288,41 @@ if (config.auth_force_edmc_protocol # noqa: C901 GlobalUnlock(msg.lParam) # Unlocks the GlobalLock-ed object if args.lower().startswith('open("') and args.endswith('")'): - logger.trace_if('frontier-auth.windows', f'args are: {args}') + logger.trace_if("frontier-auth.windows", f"args are: {args}") url = parse.unquote(args[6:-2]).strip() if url.startswith(self.redirect): - logger.debug(f'Message starts with {self.redirect}') + logger.debug(f"Message starts with {self.redirect}") self.event(url) # Send back a WM_DDE_ACK. this is _required_ with WM_DDE_EXECUTE - win32gui.SetForegroundWindow(win32gui.GetParent(self.master.winfo_id())) - PostMessageW(msg.wParam, WM_DDE_ACK, hwnd, PackDDElParam(WM_DDE_ACK, 0x80, msg.lParam)) + win32gui.SetForegroundWindow( + win32gui.GetParent(self.master.winfo_id()) + ) + PostMessageW( + msg.wParam, + WM_DDE_ACK, + hwnd, + PackDDElParam(WM_DDE_ACK, 0x80, msg.lParam), + ) else: # Send back a WM_DDE_ACK. this is _required_ with WM_DDE_EXECUTE - PostMessageW(msg.wParam, WM_DDE_ACK, hwnd, PackDDElParam(WM_DDE_ACK, 0, msg.lParam)) + PostMessageW( + msg.wParam, + WM_DDE_ACK, + hwnd, + PackDDElParam(WM_DDE_ACK, 0, msg.lParam), + ) elif msg.message == WM_DDE_TERMINATE: win32gui.PostMessage(msg.wParam, WM_DDE_TERMINATE, hwnd, 0) else: - TranslateMessage(byref(msg)) # "Translates virtual key messages into character messages" ??? + TranslateMessage( + byref(msg) + ) # "Translates virtual key messages into character messages" ??? DispatchMessageW(byref(msg)) - else: # Linux / Run from source from http.server import BaseHTTPRequestHandler, HTTPServer @@ -303,17 +336,17 @@ else: # Linux / Run from source def __init__(self) -> None: super().__init__() - self.httpd = HTTPServer(('localhost', 0), HTTPRequestHandler) - self.redirect = f'http://localhost:{self.httpd.server_port}/auth' + self.httpd = HTTPServer(("localhost", 0), HTTPRequestHandler) + self.redirect = f"http://localhost:{self.httpd.server_port}/auth" if not os.getenv("EDMC_NO_UI"): - logger.info(f'Web server listening on {self.redirect}') + logger.info(f"Web server listening on {self.redirect}") self.thread: threading.Thread | None = None - def start(self, master: 'tkinter.Tk') -> None: + def start(self, master: tkinter.Tk) -> None: """Start the HTTP server thread.""" GenericProtocolHandler.start(self, master) - self.thread = threading.Thread(target=self.worker, name='OAuth worker') + self.thread = threading.Thread(target=self.worker, name="OAuth worker") self.thread.daemon = True self.thread.start() @@ -321,20 +354,20 @@ else: # Linux / Run from source """Shutdown the HTTP server thread.""" thread = self.thread if thread: - logger.debug('Thread') + logger.debug("Thread") self.thread = None if self.httpd: - logger.info('Shutting down httpd') + logger.info("Shutting down httpd") self.httpd.shutdown() - logger.info('Joining thread') + logger.info("Joining thread") thread.join() # Wait for it to quit else: - logger.debug('No thread') + logger.debug("No thread") - logger.debug('Done.') + logger.debug("Done.") def worker(self) -> None: """HTTP Worker.""" @@ -346,10 +379,12 @@ else: # Linux / Run from source def parse(self) -> bool: """Parse a request.""" - logger.trace_if('frontier-auth.http', f'Got message on path: {self.path}') + logger.trace_if("frontier-auth.http", f"Got message on path: {self.path}") url = parse.unquote(self.path) - if url.startswith('/auth'): - logger.debug('Request starts with /auth, sending to protocolhandler.event()') + if url.startswith("/auth"): + logger.debug( + "Request starts with /auth, sending to protocolhandler.event()" + ) protocolhandler.event(url) self.send_response(200) return True @@ -364,14 +399,14 @@ else: # Linux / Run from source def do_GET(self) -> None: # noqa: N802 # Required to override """Handle GET Request.""" if self.parse(): - self.send_header('Content-Type', 'text/html') + self.send_header("Content-Type", "text/html") self.end_headers() self.wfile.write(self._generate_auth_response().encode()) else: self.send_response(404) self.end_headers() - def log_request(self, code: int | str = '-', size: int | str = '-') -> None: + def log_request(self, code: int | str = "-", size: int | str = "-") -> None: """Override to prevent logging.""" def _generate_auth_response(self) -> str: @@ -381,21 +416,21 @@ else: # Linux / Run from source :return: The HTML content of the authentication response. """ return ( - '' - '' - 'Authentication successful - Elite: Dangerous' - '' - '' - '' - '

Authentication successful

' - '

Thank you for authenticating.

' - '

Please close this browser tab now.

' - '' - '' + "h1 { text-align: center; margin-top: 100px; }" + "p { text-align: center; }" + "" + "" + "" + "

Authentication successful

" + "

Thank you for authenticating.

" + "

Please close this browser tab now.

" + "" + "" ) @@ -405,9 +440,10 @@ def get_handler_impl() -> Type[GenericProtocolHandler]: :return: An instantiatable GenericProtocolHandler """ - if ( - (sys.platform == 'win32' and config.auth_force_edmc_protocol) - or (getattr(sys, 'frozen', False) and not is_wine and not config.auth_force_localserver) + if (sys.platform == "win32" and config.auth_force_edmc_protocol) or ( + getattr(sys, "frozen", False) + and not is_wine + and not config.auth_force_localserver ): return WindowsProtocolHandler @@ -415,4 +451,4 @@ def get_handler_impl() -> Type[GenericProtocolHandler]: # *late init* singleton -protocolhandler: GenericProtocolHandler +protocolhandler: GenericProtocolHandler = None # type: ignore From 6d474abd016e3e6e0181db8c420c6448a5189df2 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Sun, 9 Nov 2025 13:40:04 -0500 Subject: [PATCH 12/84] Update Dep Warnings using Python 3.13 Syntax --- config/__init__.py | 22 +++++++++------------- l10n.py | 11 ++++------- myNotebook.py | 6 ++---- plugins/eddn.py | 3 ++- prefs.py | 4 +--- 5 files changed, 18 insertions(+), 28 deletions(-) diff --git a/config/__init__.py b/config/__init__.py index 2c1d35fc..be4841a8 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -335,6 +335,7 @@ class AbstractConfig(abc.ABC): return None + @warnings.deprecated("get() is Deprecated. use the specific getter for your type. Will remove in 6.0") def get( self, key: str, default: list | str | bool | int | None = None @@ -347,9 +348,6 @@ 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: return a_list @@ -399,6 +397,7 @@ class AbstractConfig(abc.ABC): """ raise NotImplementedError + @warnings.deprecated("Migrate to get_int. Will remove in 6.0 or later.") def getint(self, key: str, *, default: int = 0) -> int: """ Getint is a Deprecated getter method. @@ -406,9 +405,6 @@ 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) @abstractmethod @@ -464,18 +460,20 @@ 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. + @warnings.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) + pass + @warnings.deprecated("Password system doesn't do anything. Will remove in 6.0 or later.") def set_password(self, account: str, password: str) -> None: """Legacy password setting.""" - warnings.warn("password subsystem is no longer supported", DeprecationWarning, stacklevel=2) + pass + @warnings.deprecated("Password system doesn't do anything. Will remove in 6.0 or later.") def delete_password(self, account: str) -> None: """Legacy password deletion.""" - warnings.warn("password subsystem is no longer supported", DeprecationWarning, stacklevel=2) + pass # End Dep Zone @@ -509,10 +507,8 @@ 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. +@warnings.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. ' - '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 81faed21..b9c8ab97 100755 --- a/l10n.py +++ b/l10n.py @@ -262,17 +262,17 @@ def _wszarray_to_list(array): 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. + @warnings.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: N802 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. + @warnings.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. + @warnings.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() @@ -354,13 +354,10 @@ Locale = _Locale() translations = Translations() -# DEPRECATED: Migrate to `translations`. Will be removed in 6.0 or later. -# 'Translations' singleton is deprecated. +@warnings.deprecated("Migrate to `translations`. Will be removed in 6.0 or later.") # Begin Deprecation Zone class _Translations(Translations): def __init__(self): - 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 c57a6deb..02a7bef6 100644 --- a/myNotebook.py +++ b/myNotebook.py @@ -125,9 +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. + @warnings.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) @@ -144,9 +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. + @warnings.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/plugins/eddn.py b/plugins/eddn.py index 39ecf147..29caa6b2 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -29,6 +29,7 @@ import pathlib import re import sqlite3 import tkinter as tk +import warnings from platform import system from textwrap import dedent from threading import Lock @@ -221,9 +222,9 @@ class EDDNSender: return db_conn + @warnings.deprecated("Legacy files no longer used as of 5.6.0. Will remove in 6.0 or later.") def convert_legacy_file(self): """Convert a legacy file's contents into the sqlite3 db.""" - # DEPRECATED: Legacy files no longer used as of 5.6.0. Will remove in 6.0 or later. filename = config.app_dir_path / 'replay.jsonl' if not filename.exists(): return diff --git a/prefs.py b/prefs.py index 762d9a27..e0660c9f 100644 --- a/prefs.py +++ b/prefs.py @@ -37,11 +37,9 @@ logger = get_main_logger() # May be imported by plugins -# DEPRECATED: Migrate to open_log_folder. Will remove in 6.0 or later. +@warnings.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. ' - 'This function will be removed in 6.0 or later', DeprecationWarning, stacklevel=2) open_folder(Path(config.app_dir_path / 'logs')) From 5f70a8d7a456e4383104cebf7d6dfe7cd5a28266 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Sun, 9 Nov 2025 13:41:07 -0500 Subject: [PATCH 13/84] [Minor] Replace Dep'd Functions, Minor Type Hinting --- ChangeLog.md | 2 +- companion.py | 2 +- monitor.py | 4 ++-- util_ships.py | 3 ++- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 8bab3370..ca780790 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1637,7 +1637,7 @@ updated to using Python 3.9.8. - When the new option is not active, the application will minimize to the taskbar as normal. -Bug Fixex +Bug Fixes --- * If a CAPI query failed in such a way that no `requests.Response` object diff --git a/companion.py b/companion.py index 384dcdd5..19f12a14 100644 --- a/companion.py +++ b/companion.py @@ -821,7 +821,7 @@ class Session: capi_data = CAPIData(capi_json, capi_host, capi_endpoint, monitor.cmdr) self.capi_raw_data.record_endpoint( capi_endpoint, r.content.decode(encoding='utf-8'), - datetime.datetime.utcnow() + datetime.datetime.now(datetime.timezone.utc) ) except requests.ConnectionError as e: diff --git a/monitor.py b/monitor.py index 91cf3375..3df0f85c 100644 --- a/monitor.py +++ b/monitor.py @@ -67,7 +67,7 @@ class EDLogs(FileSystemEventHandler): def __init__(self) -> None: # TODO(A_D): A bunch of these should be switched to default values (eg '' for strings) and no longer be Optional FileSystemEventHandler.__init__(self) # futureproofing - not need for current version of watchdog - self.root: 'tkinter.Tk' = None # type: ignore # Don't use Optional[] - mypy thinks no methods + self.root: tkinter.Tk = None # type: ignore # Don't use Optional[] - mypy thinks no methods self.currentdir: str | None = None # The actual logdir that we're monitoring self.logfile: str | None = None self.observer: BaseObserver | None = None @@ -188,7 +188,7 @@ class EDLogs(FileSystemEventHandler): }, } - def start(self, root: 'tkinter.Tk') -> bool: # noqa: CCR001 + def start(self, root: tkinter.Tk) -> bool: # noqa: CCR001 """ Start journal monitoring. diff --git a/util_ships.py b/util_ships.py index b2105106..8abbe20f 100644 --- a/util_ships.py +++ b/util_ships.py @@ -5,6 +5,7 @@ Copyright (c) EDCD, All Rights Reserved Licensed under the GNU General Public License. See LICENSE file. """ +import os from pathlib import Path from edmc_data import ship_name_map @@ -17,7 +18,7 @@ def ship_file_name(ship_name: str, ship_type: str) -> str: name = Path(name).with_suffix("").name # Check if the name is a reserved filename - if Path(name).is_reserved(): + if os.path.isreserved(name): name += "_" return name.translate( From 8c88ee7d75da87519baba2d3f0f94a52b5073845 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Sun, 9 Nov 2025 14:02:35 -0500 Subject: [PATCH 14/84] [#2437] Add Catch for "en" as the set language --- l10n.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/l10n.py b/l10n.py index b9c8ab97..236d65f4 100755 --- a/l10n.py +++ b/l10n.py @@ -126,7 +126,7 @@ class Translations: def contents(self, lang: str, plugin_path: pathlib.Path | None = None) -> dict[str, str]: """Load all the translations from a translation file.""" - if lang not in self.available(): + if lang not in self.available() and lang != self.FALLBACK: # Because "en" doesn't appear in self.available() raise KeyError(f'Language {lang} not available') translations = {} From ea5d9263a28e75c6b391f7f0fa22d11dd6c63b10 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Sun, 9 Nov 2025 14:14:34 -0500 Subject: [PATCH 15/84] [Minor] Update Winsparkle --- .github/workflows/windows-build.yml | 4 ++-- build.py | 4 ++-- docs/Releasing.md | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml index e8d21e83..3bffb6bd 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -113,9 +113,9 @@ jobs: - name: Download winsparkle run: | - Invoke-Webrequest -UseBasicParsing https://github.com/vslavik/winsparkle/releases/download/v0.9.0/WinSparkle-0.9.0.zip -OutFile out.zip + Invoke-Webrequest -UseBasicParsing https://github.com/vslavik/winsparkle/releases/download/v0.9.2/WinSparkle-0.9.2.zip -OutFile out.zip Expand-Archive out.zip - Move-Item 'out\WinSparkle-0.9.0\Release\*' '.\' + Move-Item 'out\WinSparkle-0.9.2\Release\*' '.\' - name: Build EDMC run: | diff --git a/build.py b/build.py index 94585461..71486210 100644 --- a/build.py +++ b/build.py @@ -38,8 +38,8 @@ def iss_build(template_path: str, output_file: str) -> None: def system_check(dist_dir: pathlib.Path) -> str: """Check if the system is able to build.""" - if sys.version_info < (3, 11): - sys.exit(f"Unexpected Python version {sys.version}") + if sys.version_info < (3, 13): + sys.exit(f"EDMC cannot build on Python {sys.version}. Minimum version: 3.13") if sys.platform != "win32": sys.exit(f"Unsupported platform {sys.platform}") diff --git a/docs/Releasing.md b/docs/Releasing.md index 74151752..1edc281c 100644 --- a/docs/Releasing.md +++ b/docs/Releasing.md @@ -389,7 +389,7 @@ When changing the Python version (Major.Minor.Patch) used: 1. Any version change: 1. `ChangeLog.md` - The `We now test against, and package with, Python - M.m.P.` line. + M.m.` line. 1. Major or Minor level changes: From ec67b434d3bb4c8967046ed1d6f8d6c5fd83f77e Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Sun, 9 Nov 2025 15:25:51 -0500 Subject: [PATCH 16/84] [Minor] Reduce Privilege Request for Checking Same User --- .pre-commit-config.yaml | 8 ++++---- EDMarketConnector.py | 2 +- debug_webserver.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8339f184..d227a688 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,7 +7,7 @@ repos: # - id: identity - repo: https://github.com/pre-commit/pre-commit-hooks - rev: 'v4.1.0' + rev: 'v6.0.0' hooks: - id: check-merge-conflict - id: debug-statements @@ -21,7 +21,7 @@ repos: # - id: autopep8 - repo: https://github.com/PyCQA/flake8 - rev: 7.1.2 + rev: 7.3.0 hooks: - id: flake8 @@ -36,7 +36,7 @@ repos: # mypy - static type checking # mypy --follow-imports skip - repo: https://github.com/pre-commit/mirrors-mypy - rev: 'v1.15.0' + rev: 'v1.18.2' hooks: - id: mypy # verbose: true @@ -58,7 +58,7 @@ repos: # safety.exe check -r requirements.txt - repo: https://github.com/Lucas-C/pre-commit-hooks-safety - rev: 'v1.4.0' + rev: 'v1.4.2' hooks: - id: python-safety-dependencies-check entry: safety diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 92f34a48..2a932f60 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -281,7 +281,7 @@ if __name__ == '__main__': # noqa: C901 # Get thread and process IDs _, process_id = win32process.GetWindowThreadProcessId(hwnd) # Get the process handle - return win32api.OpenProcess(win32con.PROCESS_ALL_ACCESS, False, process_id) + return win32api.OpenProcess(win32con.PROCESS_QUERY_LIMITED_INFORMATION, False, process_id) except Exception: return None diff --git a/debug_webserver.py b/debug_webserver.py index 1471ec7d..0edffe99 100644 --- a/debug_webserver.py +++ b/debug_webserver.py @@ -15,7 +15,7 @@ from EDMCLogging import get_main_logger logger = get_main_logger() output_lock = threading.Lock() -output_data_path = pathlib.Path(config.app_dir_path / 'logs' / 'http_debug') +output_data_path = pathlib.Path(config.app_dir_path / 'logs' / 'http_debug') # type: ignore SAFE_TRANSLATE = str.maketrans(dict.fromkeys("!@#$%^&*()./\\\r\n[]-+='\";:?<>,~`", '_')) From 368df55a72088abb67cb6628b2fac6b1c855c350 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Sun, 9 Nov 2025 15:40:40 -0500 Subject: [PATCH 17/84] [#1805] Fix Prototyping for Font Theme --- theme.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/theme.py b/theme.py index 99ccb158..20ffe51f 100644 --- a/theme.py +++ b/theme.py @@ -35,11 +35,13 @@ if sys.platform == 'win32': from ctypes.wintypes import DWORD, LPCVOID, LPCWSTR import win32gui AddFontResourceEx = ctypes.windll.gdi32.AddFontResourceExW - AddFontResourceEx.restypes = [LPCWSTR, DWORD, LPCVOID] # type: ignore + AddFontResourceEx.argtypes = [LPCWSTR, DWORD, LPCVOID] + AddFontResourceEx.restype = ctypes.c_int FR_PRIVATE = 0x10 FR_NOT_ENUM = 0x20 - font_path = config.respath_path / 'EUROCAPS.TTF' - AddFontResourceEx(str(font_path), FR_PRIVATE, 0) + font_path = str(config.respath_path / 'EUROCAPS.TTF') + if not AddFontResourceEx(font_path, FR_PRIVATE, None): + raise RuntimeError(f"Failed to load font {font_path}") elif sys.platform == 'linux': # pyright: reportUnboundVariable=false From be0c6b7677f70164b6b1049f608e584171bc1531 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Sun, 9 Nov 2025 15:54:59 -0500 Subject: [PATCH 18/84] Begin Pre-Staging 3.14. --- ChangeLog.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/ChangeLog.md b/ChangeLog.md index ca780790..5dd6be67 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -6,6 +6,30 @@ This is the master changelog for Elite Dangerous Market Connector. Entries are in the source (not distributed with the Windows installer) for the currently used version. --- +Release 5.14.0 +=== + +This is the WORK IN PROGRESS changelog for upcoming release 5.14. All features are subject to change. + +**Changes and Enhancements** +* Updated Python minimum version to 3.13. +* Updated a number of under-the-hood dependencies +* Updated WinSparkle updater +* Updated EDMC:// protocol handler to use process handles with least-privilege access for improved security and reliability. +* Updated prototyping for proper 32/64-bit font loading +* Updated WndProc callbacks for proper 32/64-bit handling +* Changed some functions to use non-deprecated alternatives +* Set new deprecation warnings using Python 3.13's new Deprecation decorator. +* Fixed a bug where "en" would not be included as a valid language and raise a KeyError + +**Plugin Developers** +* nb.Entry is deprecated, and is slated for removal in 6.0 or later. Please migrate to nb.EntryMenu +* nb.ColoredButton is deprecated, and is slated for removal in 6.0 or later. Please migrate to tk.Button +* Calling internal translations with `_()` is deprecated, and is slated for removal in 6.0 or later. Please migrate to importing `translations` and calling `translations.translate` or `translations.tl` directly +* `Translations` as the translate system singleton is deprecated, and is slated for removal in 6.0 or later. Please migrate to the `translations` singleton +* `help_open_log_folder()` is deprecated, and is slated for removal in 6.0 or later. Please migrate to open_folder() +* `update_feed` is deprecated, and is slated for removal in 6.0 or later. Please migrate to `get_update_feed()` + Release 5.13.2 === This release contains an update to a series of behind-the-scenes tools, as well as adding Corsair, Cobra Mk V, From 715553207faa6230c706facbaeb15cc85db04035 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Sun, 9 Nov 2025 18:00:50 -0500 Subject: [PATCH 19/84] [#2430] First-Pass EDAstro Core Plugin --- L10n/en.template | 3 + build.py | 1 + plugins/edastro_core.py | 213 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 217 insertions(+) create mode 100644 plugins/edastro_core.py diff --git a/L10n/en.template b/L10n/en.template index 559dbb82..98ae2ba9 100644 --- a/L10n/en.template +++ b/L10n/en.template @@ -827,3 +827,6 @@ /* ttkHyperlinkLabel.py: Copy the Inara SLEF Format of the active ship to the clipboard; */ "Copy Inara SLEF" = "Copy Inara SLEF"; + +/* edastro_core.py: Settings>EDAstro - Label on checkbox for 'send data'; */ +"Send data to EDAstro" = "Send data to EDAstro"; diff --git a/build.py b/build.py index 71486210..374562e2 100644 --- a/build.py +++ b/build.py @@ -121,6 +121,7 @@ def build() -> None: "plugins/edsy.py", "plugins/inara.py", "plugins/spansh_core.py", + "plugins/edastro_core.py", "plugins/common_coreutils.py" ] options: dict = { diff --git a/plugins/edastro_core.py b/plugins/edastro_core.py new file mode 100644 index 00000000..6a580bd6 --- /dev/null +++ b/plugins/edastro_core.py @@ -0,0 +1,213 @@ +""" +edastro_core.py - Exporting Data to EDAstro. + +Copyright (c) EDCD, All Rights Reserved +Licensed under the GNU General Public License. +See LICENSE file. + +This is an EDMC 'core' plugin. +All EDMC plugins are *dynamically* loaded at run-time. + +We build for Windows using `py2exe`. +`py2exe` can't possibly know about anything in the dynamically loaded core plugins. + +Thus, you **MUST** check if any imports you add in this file are only +referenced in this file (or only in any other core plugin), and if so... + + YOU MUST ENSURE THAT PERTINENT ADJUSTMENTS ARE MADE IN + `build.py` TO ENSURE THE FILES ARE ACTUALLY PRESENT + IN AN END-USER INSTALLATION ON WINDOWS. +""" + +import json +from typing import Any +from tkinter import ttk +import requests +import tkinter as tk +from l10n import translations as tr +from config import config +from ttkHyperlinkLabel import HyperlinkLabel +import myNotebook as nb # noqa: N813 +from EDMCLogging import get_main_logger + +from plugins.common_coreutils import PADX, PADY, BUTTONX + +logger = get_main_logger() + + +class This: + """Holds module globals.""" + + app_name = "EDAstro" + edastro_push = "https://edastro.com/api/journal" + + event_filters = { + "CarrierStats": [ + "timestamp", + "event", + "Callsign", + "Name", + "CarrierID", + "AllowNotorious", + "PendingDecommission", + "DockingAccess", + "FuelLevel", + ], + "CarrierJumpRequest": [ + "timestamp", + "event", + "SystemName", + "SystemAddress", + "CarrierID", + ], + } + + def __init__(self): + self.log: tk.IntVar | None = None + self.log_button: ttk.Checkbutton | None = None + + +this = This() + + +def set_config_first_run() -> None: + """Enable EDAstro if the config key does not exist.""" + if not config.get_bool("edastro_send"): + logger.info("EDAstro First Run. Enabling") + config.set("edastro_send", 1) + + +# Plugin callbacks +def plugin_start3(plugin_dir: str) -> str: + """ + Start this plugin. + + :param plugin_dir: `str` - The full path to this plugin's directory. + :return: `str` - Name of this plugin to use in UI. + """ + set_config_first_run() + return "EDAstro" + + +def plugin_prefs(parent, cmdr: str, is_beta: bool) -> nb.Frame: + """ + Set up Preferences pane for this plugin. + + :param parent: tkinter parent to attach to. + :param cmdr: `str` - Name of current Cmdr. + :param is_beta: `bool` - True if this is a beta version of the Game. + :return: The tkinter frame we created. + """ + edastroframe = nb.Frame(parent) + edastroframe.columnconfigure(0, weight=1) + + cur_row = 0 + HyperlinkLabel( + edastroframe, + text="Elite Dangerous Astronomy", + background=nb.Label().cget("background"), + url="https://edastro.com", + underline=True, + ).grid( + row=cur_row, padx=PADX, pady=PADY, sticky=tk.W + ) # Don't translate + cur_row += 1 + this.log = tk.IntVar(value=config.get_int("edastro_send") and 1) + this.log_button = nb.Checkbutton( + edastroframe, + # LANG: Settings>EDAstro - Label on checkbox for 'send data' + text=tr.tl("Send data to EDAstro"), + variable=this.log, + ) + if this.log_button: + this.log_button.grid( + row=cur_row, columnspan=2, padx=BUTTONX, pady=PADY, sticky=tk.W + ) + cur_row += 1 + + return edastroframe + + +def prefs_changed(cmdr: str, is_beta: bool) -> None: + """ + Handle any changes to Settings once the dialog is closed. + + :param cmdr: Name of Commander. + :param is_beta: Whether game beta was detected. + """ + if this.log: + config.set("edastro_send", this.log.get()) + + +def filter_event_data(entry) -> dict[str, Any]: + """Format Journal Data for EDAstro.""" + if entry["event"] in this.event_filters: + return { + key: entry[key] + for key in this.event_filters[entry["event"]] + if key in entry + } + return entry + + +def edastro_update(system, entry, state): + """Send a processed event to EDAstro.""" + event_name = str(entry["event"]) + filtered_entry = filter_event_data(entry) + app_header = { + "appName": this.app_name, + "odyssey": state.get("Odyssey"), + "system": system, + } + event_object = [app_header, filtered_entry] + event_data = json.dumps(event_object) + try: + json_header = {"Content-Type": "application/json"} + response = requests.post( + url=this.edastro_push, headers=json_header, data=event_data, timeout=20 + ) + if response.status_code == 200: + edastro = json.loads(response.text) + if str(edastro["status"]) == "200" or str(edastro["status"]) == "401": + # 200 = at least one event accepted, 401 = none were accepted, but no errors either + logger.info(f"EDAstro: Data sent! ({event_name})") + else: + logger.debug( + f"Error Response:\nRequest: {this.edastro_push}\n " + f'Response ({edastro["status"]}): \n{edastro["message"]}' + ) + else: + logger.debug( + f"Unexpected Response:\nRequest: {this.edastro_push}\n " + f"Response ({response.status_code}):\n{response.text}" + ) + except Exception as ex: + logger.warning( + f"Failed to submit EDAstro data:\nRequest: {this.edastro_push}", + exc_info=ex, + ) + + +def journal_entry( + cmdr: str, + is_beta: bool, + system: str, + station: str, + entry: dict[str, Any], + state: dict[str, Any], +) -> str | None: + """ + Handle a new Journal event. + + :param cmdr: Name of Commander. + :param is_beta: Whether game beta was detected. + :param system: Name of current tracked system. + :param station: Name of current tracked station location. + :param entry: The journal event. + :param state: `monitor.state` + :return: None if no error, else an error string. + """ + if this.log and entry["event"] in ["CarrierStats", "CarrierJumpRequest"]: + edastro_update(system, entry, state) + + return None From 23c1ec8262858ae829ab2cbbbadca567eb5fd484 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Sun, 9 Nov 2025 18:54:01 -0500 Subject: [PATCH 20/84] [Minor] Improve Safety of Subprocess Call --- config/__init__.py | 43 +++++++++++++++++++++---------------------- edshipyard.py | 2 +- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/config/__init__.py b/config/__init__.py index be4841a8..30f15998 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -82,37 +82,36 @@ def git_shorthash_from_head() -> str | None: """ Determine short hash for current git HEAD. - Includes `.DIRTY` if any changes have been made from HEAD + Includes `.DIRTY` if any changes have been made from HEAD. :return: str | None: None if we couldn't determine the short hash. """ - shorthash: str | None = None - try: - git_cmd = subprocess.Popen( - "git rev-parse --short HEAD".split(), - stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, + result = subprocess.run( + ["git", "rev-parse", "--short", "HEAD"], + capture_output=True, + text=True, + check=True, ) - out, err = git_cmd.communicate() - + shorthash = result.stdout.strip() except (subprocess.CalledProcessError, FileNotFoundError) as e: logger.info(f"Couldn't run git command for short hash: {e!r}") + return None - else: - shorthash = out.decode().rstrip('\n') - if re.match(r'^[0-9a-f]{7,}$', shorthash) is None: - logger.error(f"'{shorthash}' doesn't look like a valid git short hash, forcing to None") - shorthash = None + if not re.fullmatch(r"[0-9a-f]{7,}", shorthash): + logger.error(f"'{shorthash}' doesn't look like a valid git short hash, forcing to None") + return None - if shorthash is not None: - with contextlib.suppress(Exception): - result = subprocess.run('git diff --stat HEAD'.split(), capture_output=True) - if len(result.stdout) > 0: - shorthash += '.DIRTY' - - if len(result.stderr) > 0: - logger.warning(f'Data from git on stderr:\n{str(result.stderr)}') + with contextlib.suppress(Exception): + diff_result = subprocess.run( + ["git", "diff", "--stat", "HEAD"], + capture_output=True, + check=True + ) + if diff_result.stdout: + shorthash += ".DIRTY" + if diff_result.stderr: + logger.warning(f"Data from git on stderr:\n{diff_result.stderr.decode()}") return shorthash diff --git a/edshipyard.py b/edshipyard.py index 28e6dc2f..f7bceb75 100644 --- a/edshipyard.py +++ b/edshipyard.py @@ -106,7 +106,7 @@ def export(data, filename=None) -> None: # noqa: C901, CCR001 else: name = module['name'] # type: ignore - if name == 'Frame Shift Drive' or name == 'Frame Shift Drive (SCO)': + if name in ['Frame Shift Drive', 'Frame Shift Drive (SCO)']: fsd = module # save for range calculation if mods.get('OutfittingFieldType_FSDOptimalMass'): From f8f81c58b0522ffc413d8845542ec2bd4829e461 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Tue, 11 Nov 2025 12:10:15 -0500 Subject: [PATCH 21/84] [Fix] Fix Import for Debug Webserver --- debug_webserver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debug_webserver.py b/debug_webserver.py index 0edffe99..c4be2be3 100644 --- a/debug_webserver.py +++ b/debug_webserver.py @@ -9,7 +9,7 @@ import zlib from http import server from typing import Any, Callable, Literal from urllib.parse import parse_qs -import config +from config import config from EDMCLogging import get_main_logger logger = get_main_logger() From f9ccba3aa1a225dc0e491ab568c884cfc9ba1197 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Tue, 11 Nov 2025 19:07:28 -0500 Subject: [PATCH 22/84] [2430] Add ScanOrganic --- plugins/edastro_core.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/plugins/edastro_core.py b/plugins/edastro_core.py index 6a580bd6..a6929217 100644 --- a/plugins/edastro_core.py +++ b/plugins/edastro_core.py @@ -52,6 +52,7 @@ class This: "PendingDecommission", "DockingAccess", "FuelLevel", + "Crew", ], "CarrierJumpRequest": [ "timestamp", @@ -59,7 +60,23 @@ class This: "SystemName", "SystemAddress", "CarrierID", + "Body", + "BodyID" + "DepartureTime" ], + "ScanOrganic": [ + "timestamp", + "ScanType", + "Genus_Localised", + "Species_Localised", + "Genus", + "event", + "Body", + "Species", + "Variant", + "SystemAddress", + "Variant_Localised", + ] } def __init__(self): @@ -207,7 +224,7 @@ def journal_entry( :param state: `monitor.state` :return: None if no error, else an error string. """ - if this.log and entry["event"] in ["CarrierStats", "CarrierJumpRequest"]: + if this.log and entry["event"] in ["CarrierStats", "CarrierJumpRequest", "ScanOrganic"]: edastro_update(system, entry, state) return None From 119d09f1878d0b4425c73a7e8a867703ffc4f18b Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Tue, 11 Nov 2025 19:12:02 -0500 Subject: [PATCH 23/84] [#1256] Add Skip-JournalLock Argument --- EDMarketConnector.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 2a932f60..0bdfb8c9 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -194,6 +194,12 @@ if __name__ == '__main__': # noqa: C901 help='Skips the Time Delta check for processed events', action='store_true' ) + + parser.add_argument( + '--skip-journallock', + help='Allows EDMC to continue even if journal lock could not be acquired', + action='store_true', + ) ########################################################################### args: argparse.Namespace = parser.parse_args() @@ -337,6 +343,12 @@ if __name__ == '__main__': # noqa: C901 # Ref: win32gui.EnumWindows(enumwindowsproc, 0) + def skip_journallock_popup(): + """Create the "skipping Journal Lock" popup.""" + from tkinter import messagebox + lockmsg = "Ignoring failed Journal Lock. Continuing at your own risk.\nConsider also using a debug sender." + messagebox.showwarning(title=appname, message=lockmsg) + def already_running_popup(): """Create the "already running" popup.""" from tkinter import messagebox @@ -352,9 +364,15 @@ if __name__ == '__main__': # noqa: C901 handle_edmc_callback_or_foregrounding() - if locked == JournalLockResult.ALREADY_LOCKED: - # There's a copy already running. + if locked == JournalLockResult.ALREADY_LOCKED and args.skip_journallock: + # There may be a copy already running. We are intentionally ignoring it. + logger.info("Intentionally skipping Journal Lock check. This may have unintended consequences") + # To be sure the user knows, we need a popup + if not args.edmc: + skip_journallock_popup() + if locked == JournalLockResult.ALREADY_LOCKED and not args.skip_journallock: + # There's a copy already running. logger.info("An EDMarketConnector.exe process was already running, exiting.") # To be sure the user knows, we need a popup From c3f9247cd11b2bc044ea5af31fdf9b3c53f7c924 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Tue, 11 Nov 2025 20:24:58 -0500 Subject: [PATCH 24/84] [#2116] Hand more things to TTK --- myNotebook.py | 32 ++++++++++----------- outfitting.py | 4 +-- plugins/eddn.py | 55 +++++++++++++++++++------------------ plugins/inara.py | 6 ++-- stats.py | 2 +- tests/config/test_config.py | 4 +-- 6 files changed, 51 insertions(+), 52 deletions(-) diff --git a/myNotebook.py b/myNotebook.py index 02a7bef6..b488916a 100644 --- a/myNotebook.py +++ b/myNotebook.py @@ -41,23 +41,23 @@ class Frame(ttk.Frame): """Custom ttk.Frame class to fix some display issues.""" def __init__(self, master: ttk.Notebook | None = None, **kw): - if sys.platform == 'win32': - ttk.Frame.__init__(self, master, style='nb.TFrame', **kw) - ttk.Frame(self).grid(pady=5) # top spacer - else: - ttk.Frame.__init__(self, master, **kw) - ttk.Frame(self).grid(pady=5) # top spacer - self.configure(takefocus=1) # let the frame take focus so that no particular child is focused + style = 'nb.TFrame' if sys.platform == 'win32' else None + super().__init__(master, style=style, **kw) # type: ignore + ttk.Frame(self).grid(pady=5) # Top spacer + self.configure(takefocus=1) # let the frame take focus so that no particular child is focused -class Label(tk.Label): - """Custom tk.Label class to fix some display issues.""" +class Label(ttk.Label): + """Custom ttk.Label class to fix some display issues.""" def __init__(self, master: ttk.Frame | None = None, **kw): - kw['foreground'] = kw.pop('foreground', PAGEFG if sys.platform == 'win32' - else ttk.Style().lookup('TLabel', 'foreground')) - kw['background'] = kw.pop('background', PAGEBG if sys.platform == 'win32' - else ttk.Style().lookup('TLabel', 'background')) + style = ttk.Style() + if sys.platform == 'win32': + custom_style = 'nb.TLabel' # Create or update a style to emulate the tk.Label colors + style.configure(custom_style, foreground=PAGEFG, background=PAGEBG) + else: + custom_style = 'TLabel' # Use the platform default ttk style + kw.setdefault('style', custom_style) super().__init__(master, **kw) @@ -134,10 +134,8 @@ class Button(ttk.Button): """Custom ttk.Button class to fix some display issues.""" def __init__(self, master: ttk.Frame | None = None, **kw): - if sys.platform == 'win32': - ttk.Button.__init__(self, master, style='nb.TButton', **kw) - else: - ttk.Button.__init__(self, master, **kw) + style = 'nb.TButton' if sys.platform == 'win32' else None + super().__init__(master, style=style, **kw) # type: ignore class ColoredButton(tk.Button): diff --git a/outfitting.py b/outfitting.py index 207c4883..4b014e48 100644 --- a/outfitting.py +++ b/outfitting.py @@ -302,8 +302,8 @@ def export(data, filename) -> None: try: m = lookup(v, ship_name_map) if m: - h.write(f'{rowheader}, {m["category"]}, {m["name"]}, {m.get("mount","")},' - f'{m.get("guidance","")}, {m.get("ship","")}, {m["class"]}, {m["rating"]},' + h.write(f'{rowheader}, {m["category"]}, {m["name"]}, {m.get("mount", "")},' + f'{m.get("guidance", "")}, {m.get("ship", "")}, {m["class"]}, {m["rating"]},' f'{m["id"]}, {data["timestamp"]}\n') except ValueError as e: diff --git a/plugins/eddn.py b/plugins/eddn.py index bdf0c96e..2e37e1bf 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -29,6 +29,7 @@ import pathlib import re import sqlite3 import tkinter as tk +from tkinter import ttk import warnings from platform import system from textwrap import dedent @@ -115,15 +116,15 @@ class This: # Tracking UI self.ui: tk.Frame - self.ui_system_name: tk.Label - self.ui_system_address: tk.Label - self.ui_j_body_name: tk.Label - self.ui_j_body_id: tk.Label - self.ui_j_body_type: tk.Label - self.ui_s_body_name: tk.Label - self.ui_station_name: tk.Label - self.ui_station_type: tk.Label - self.ui_station_marketid: tk.Label + self.ui_system_name: ttk.Label + self.ui_system_address: ttk.Label + self.ui_j_body_name: ttk.Label + self.ui_j_body_id: ttk.Label + self.ui_j_body_type: ttk.Label + self.ui_s_body_name: ttk.Label + self.ui_station_name: ttk.Label + self.ui_station_type: ttk.Label + self.ui_station_marketid: ttk.Label this = This() @@ -2027,15 +2028,15 @@ def plugin_app(parent: tk.Tk) -> tk.Frame | None: # System ####################################################################### # SystemName - system_name_label = tk.Label(this.ui, text="J:SystemName:") + system_name_label = ttk.Label(this.ui, text="J:SystemName:") system_name_label.grid(row=row, column=0, sticky=tk.W) - this.ui_system_name = tk.Label(this.ui, name='eddn_track_system_name', anchor=tk.W) + this.ui_system_name = ttk.Label(this.ui, name='eddn_track_system_name', anchor=tk.W) this.ui_system_name.grid(row=row, column=1, sticky=tk.E) row += 1 # SystemAddress - system_address_label = tk.Label(this.ui, text="J:SystemAddress:") + system_address_label = ttk.Label(this.ui, text="J:SystemAddress:") system_address_label.grid(row=row, column=0, sticky=tk.W) - this.ui_system_address = tk.Label(this.ui, name='eddn_track_system_address', anchor=tk.W) + this.ui_system_address = ttk.Label(this.ui, name='eddn_track_system_address', anchor=tk.W) this.ui_system_address.grid(row=row, column=1, sticky=tk.E) row += 1 ####################################################################### @@ -2044,27 +2045,27 @@ def plugin_app(parent: tk.Tk) -> tk.Frame | None: # Body ####################################################################### # Body Name from Journal - journal_body_name_label = tk.Label(this.ui, text="J:BodyName:") + journal_body_name_label = ttk.Label(this.ui, text="J:BodyName:") journal_body_name_label.grid(row=row, column=0, sticky=tk.W) - this.ui_j_body_name = tk.Label(this.ui, name='eddn_track_j_body_name', anchor=tk.W) + this.ui_j_body_name = ttk.Label(this.ui, name='eddn_track_j_body_name', anchor=tk.W) this.ui_j_body_name.grid(row=row, column=1, sticky=tk.E) row += 1 # Body ID from Journal - journal_body_id_label = tk.Label(this.ui, text="J:BodyID:") + journal_body_id_label = ttk.Label(this.ui, text="J:BodyID:") journal_body_id_label.grid(row=row, column=0, sticky=tk.W) - this.ui_j_body_id = tk.Label(this.ui, name='eddn_track_j_body_id', anchor=tk.W) + this.ui_j_body_id = ttk.Label(this.ui, name='eddn_track_j_body_id', anchor=tk.W) this.ui_j_body_id.grid(row=row, column=1, sticky=tk.E) row += 1 # Body Type from Journal - journal_body_type_label = tk.Label(this.ui, text="J:BodyType:") + journal_body_type_label = ttk.Label(this.ui, text="J:BodyType:") journal_body_type_label.grid(row=row, column=0, sticky=tk.W) - this.ui_j_body_type = tk.Label(this.ui, name='eddn_track_j_body_type', anchor=tk.W) + this.ui_j_body_type = ttk.Label(this.ui, name='eddn_track_j_body_type', anchor=tk.W) this.ui_j_body_type.grid(row=row, column=1, sticky=tk.E) row += 1 # Body Name from Status.json - status_body_name_label = tk.Label(this.ui, text="S:BodyName:") + status_body_name_label = ttk.Label(this.ui, text="S:BodyName:") status_body_name_label.grid(row=row, column=0, sticky=tk.W) - this.ui_s_body_name = tk.Label(this.ui, name='eddn_track_s_body_name', anchor=tk.W) + this.ui_s_body_name = ttk.Label(this.ui, name='eddn_track_s_body_name', anchor=tk.W) this.ui_s_body_name.grid(row=row, column=1, sticky=tk.E) row += 1 ####################################################################### @@ -2073,21 +2074,21 @@ def plugin_app(parent: tk.Tk) -> tk.Frame | None: # Station ####################################################################### # Name - status_station_name_label = tk.Label(this.ui, text="J:StationName:") + status_station_name_label = ttk.Label(this.ui, text="J:StationName:") status_station_name_label.grid(row=row, column=0, sticky=tk.W) - this.ui_station_name = tk.Label(this.ui, name='eddn_track_station_name', anchor=tk.W) + this.ui_station_name = ttk.Label(this.ui, name='eddn_track_station_name', anchor=tk.W) this.ui_station_name.grid(row=row, column=1, sticky=tk.E) row += 1 # Type - status_station_type_label = tk.Label(this.ui, text="J:StationType:") + status_station_type_label = ttk.Label(this.ui, text="J:StationType:") status_station_type_label.grid(row=row, column=0, sticky=tk.W) - this.ui_station_type = tk.Label(this.ui, name='eddn_track_station_type', anchor=tk.W) + this.ui_station_type = ttk.Label(this.ui, name='eddn_track_station_type', anchor=tk.W) this.ui_station_type.grid(row=row, column=1, sticky=tk.E) row += 1 # MarketID - status_station_marketid_label = tk.Label(this.ui, text="J:StationID:") + status_station_marketid_label = ttk.Label(this.ui, text="J:StationID:") status_station_marketid_label.grid(row=row, column=0, sticky=tk.W) - this.ui_station_marketid = tk.Label(this.ui, name='eddn_track_station_id', anchor=tk.W) + this.ui_station_marketid = ttk.Label(this.ui, name='eddn_track_station_id', anchor=tk.W) this.ui_station_marketid.grid(row=row, column=1, sticky=tk.E) row += 1 ####################################################################### diff --git a/plugins/inara.py b/plugins/inara.py index 7bc31a30..e398a3f3 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -122,11 +122,11 @@ class This: self.station_marketid = None # Prefs UI - self.log: 'tk.IntVar' + self.log: tk.IntVar self.log_button: nb.Checkbutton self.label: HyperlinkLabel self.apikey: nb.EntryMenu - self.apikey_label: tk.Label + self.apikey_label: ttk.Label self.events: dict[Credentials, Deque[Event]] = defaultdict(deque) self.event_lock: Lock = threading.Lock() # protects events, for use when rewriting events @@ -1610,7 +1610,7 @@ def handle_api_error(data: Mapping[str, Any], status: int, reply: dict[str, Any] """ error_message = reply['header'].get('eventStatusText', "") logger.warning(f'Inara\t{status} {error_message}') - logger.debug(f'JSON data:\n{json.dumps(data, indent=2, separators = (",", ": "))}') + logger.debug(f'JSON data:\n{json.dumps(data, indent=2, separators=(",", ": "))}') # LANG: INARA API returned some kind of error (error message will be contained in {MSG}) plug.show_error(tr.tl('Error: Inara {MSG}').format(MSG=error_message)) diff --git a/stats.py b/stats.py index 4c4b0e3d..c16ec880 100644 --- a/stats.py +++ b/stats.py @@ -457,7 +457,7 @@ class StatsResults(tk.Toplevel): # label = HyperlinkLabel(parent, text=col_content, popup_copy=True) label = nb.Label(parent, text=col_content) if with_copy: - label.bind('', self.copy_callback(label, col_content)) + label.bind('', self.copy_callback(label, col_content)) # type: ignore if i == 0: label.grid(padx=10, sticky=tk.W) diff --git a/tests/config/test_config.py b/tests/config/test_config.py index e839afc7..642da5c2 100644 --- a/tests/config/test_config.py +++ b/tests/config/test_config.py @@ -117,7 +117,7 @@ class TestNewConfig: @mark.parametrize("lst", _build_test_list(list_tests, _get_fuzz(list))) def test_list(self, lst: list[str]) -> None: """Save a list and then ask for it back.""" - name = f'list_test_{ hash("".join(lst)) }' + name = f'list_test_{hash("".join(lst))}' config.set(name, lst) config.save() @@ -222,7 +222,7 @@ class TestOldNewConfig: # So insert those spaces here, to ensure that it works otherwise. lst = [e if len(e) > 0 else ' ' for e in lst] - name = self.KEY_PREFIX + f'list_test_{ hash("".join(lst)) }' + name = self.KEY_PREFIX + f'list_test_{hash("".join(lst))}' old_config.set(name, lst) old_config.save() From 29784a3e78e2bc1538742f7b7181961c9a5b73a4 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Tue, 11 Nov 2025 20:31:50 -0500 Subject: [PATCH 25/84] [Docs] Update Documentation --- docs/Releasing.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/Releasing.md b/docs/Releasing.md index 1edc281c..033f0a2b 100644 --- a/docs/Releasing.md +++ b/docs/Releasing.md @@ -38,8 +38,8 @@ You will need several pieces of software installed, or the files from their auto-select some others). NB: If you have need to uninstall this it's "Windows Software Development Kit - Windows 10.0.19041.1" in "Apps & Features", *not* "Windows SDK AddOn". -1. [Python](https://python.org): 32-bit version of Python 3.10 for Windows. - [v3.10.3](https://www.python.org/downloads/release/python-3103/) is the most +1. [Python](https://python.org): 32-bit version of Python 3.13 for Windows. + [v3.13.9](https://www.python.org/downloads/release/python-3139/) is the most recently tested version. You need the `Windows x86 executable installer` file, for the 32-bit version. Double-check the version against the `.python.version` file, as it should always contain the intended version. From 0994f1351b3763c0baf24ec026393d3bcc755b66 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Tue, 11 Nov 2025 21:47:02 -0500 Subject: [PATCH 26/84] [#2440] Refactor Updater --- update.py | 199 +++++++++++++++++++++++++++--------------------------- 1 file changed, 98 insertions(+), 101 deletions(-) diff --git a/update.py b/update.py index f9574242..7ea619b8 100644 --- a/update.py +++ b/update.py @@ -12,9 +12,10 @@ import shutil import sys import threading import os +from dataclasses import dataclass from tkinter import messagebox from traceback import print_exc -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, cast, Any from xml.etree import ElementTree import requests import semantic_version @@ -25,58 +26,68 @@ from l10n import translations as tr if TYPE_CHECKING: import tkinter as tk - logger = get_main_logger() -def check_for_fdev_updates(silent: bool = False, local: bool = False) -> None: # noqa: CCR001 +def read_normalized_file(path: pathlib.Path) -> str: + """Read a UTF-8 (with BOM-safe) file and normalize line endings and whitespace.""" + try: + return path.read_bytes().decode('utf-8-sig').replace('\r\n', '\n').strip() + except FileNotFoundError: + return '' + + +def copy_bundle_file(filename: str, dest_dir: pathlib.Path) -> str: + """Attempt to copy a missing file from the bundled FDevIDs folder.""" + try: + shutil.copy(f"FDevIDs/{filename}", dest_dir) + return read_normalized_file(dest_dir / filename) + except (FileNotFoundError, shutil.SameFileError): + logger.info("Bundle copy failed or identical; continuing with empty content.") + return '' + + +def fetch_remote_file(url: str) -> str | None: + """Fetch a remote file and normalize its content.""" + try: + response = requests.get(url, timeout=20) + response.raise_for_status() + return response.text.replace('\r\n', '\n').strip() + except requests.RequestException: + return None + + +def check_for_fdev_updates(silent: bool = False, local: bool = False) -> None: """Check for and download FDEV ID file updates.""" - pathway = config.respath_path if local else config.app_dir_path + base_path = config.respath_path if local else config.app_dir_path + fdevid_dir = pathlib.Path(base_path, 'FDevIDs') + fdevid_dir.mkdir(parents=True, exist_ok=True) - files_urls = [ - ('commodity.csv', 'https://raw.githubusercontent.com/EDCD/FDevIDs/master/commodity.csv'), - ('rare_commodity.csv', 'https://raw.githubusercontent.com/EDCD/FDevIDs/master/rare_commodity.csv') - ] + files_urls = { + 'commodity.csv': 'https://raw.githubusercontent.com/EDCD/FDevIDs/master/commodity.csv', + 'rare_commodity.csv': 'https://raw.githubusercontent.com/EDCD/FDevIDs/master/rare_commodity.csv' + } - for file, url in files_urls: - fdevid_file = pathlib.Path(pathway / 'FDevIDs' / file) - fdevid_file.parent.mkdir(parents=True, exist_ok=True) - try: - with open(fdevid_file, newline='', encoding='utf-8') as f: - local_content = f.read() - except FileNotFoundError: - logger.info(f'File {file} not found. Writing from bundle...') - try: - for localfile in files_urls: - filepath = pathlib.Path(f"FDevIDs/{localfile[0]}") - try: - shutil.copy(filepath, pathway / 'FDevIDs') - except shutil.SameFileError: - logger.info("Not replacing same file...") - fdevid_file = pathlib.Path(pathway / 'FDevIDs' / file) - with open(fdevid_file, newline='', encoding='utf-8') as f: - local_content = f.read() - except FileNotFoundError: - local_content = None - - try: - response = requests.get(url, timeout=20) - response.raise_for_status() - except requests.RequestException: + for filename, url in files_urls.items(): + file_path = fdevid_dir / filename + local_content = read_normalized_file(file_path) or copy_bundle_file(filename, fdevid_dir) + remote_content = fetch_remote_file(url) + if not remote_content: if not silent: - logger.error(f'Failed to download {file}! Unable to continue.') + logger.error(f'Failed to download {filename}! Unable to continue.') continue - if local_content == response.text: + if local_content == remote_content: if not silent: - logger.info(f'FDEV ID file {file} already up to date.') - else: - if not silent: - logger.info(f'FDEV ID file {file} not up to date. Downloading...') - with open(fdevid_file, 'w', newline='', encoding='utf-8') as csvfile: - csvfile.write(response.text) + logger.info(f'FDEV ID file {filename} already up to date.') + continue + + if not silent: + logger.info(f'Updating FDEV ID file {filename}...') + file_path.write_text(remote_content, encoding='utf-8', newline='\n') +@dataclass(slots=True) class EDMCVersion: """ Hold all the information about an EDMC version. @@ -91,10 +102,9 @@ class EDMCVersion: semantic_version object for this version """ - def __init__(self, version: str, title: str, sv: semantic_version.base.Version): - self.version: str = version - self.title: str = title - self.sv: semantic_version.base.Version = sv + version: str + title: str + sv: semantic_version.Version class Updater: @@ -105,6 +115,21 @@ class Updater: WinSparkle on win32. """ + def __init__(self, tkroot: tk.Tk | None = None, provider: str = 'internal'): + """ + Initialise an Updater instance. + + :param tkroot: reference to the root window of the GUI + :param provider: 'internal' or other string if not + """ + self.root: tk.Tk | None = tkroot + self.provider: str = provider + self.thread: threading.Thread | None = None + self.updater: Any | None = None # ensure attribute exists + + if not self.use_internal() and sys.platform == 'win32': + self._init_winsparkle() + def shutdown_request(self) -> None: """Receive (Win)Sparkle shutdown request and send it to parent.""" if not config.shutting_down and self.root: @@ -116,61 +141,38 @@ class Updater: :return: bool """ - if self.provider == 'internal': - return True + return self.provider == 'internal' - return False + def _init_winsparkle(self) -> None: + """Initialize WinSparkle updater for Windows.""" + import ctypes + try: + self.updater = cast(ctypes.CDLL, ctypes.cdll.WinSparkle) + self.updater.win_sparkle_set_appcast_url(get_update_feed().encode()) # Set the appcast URL - def __init__(self, tkroot: tk.Tk | None = None, provider: str = 'internal'): - """ - Initialise an Updater instance. + # Set the appversion *without* build metadata, as WinSparkle + # doesn't do proper Semantic Version checks. + # NB: It 'accidentally' supports pre-release due to how it + # splits and compares strings: + # + self.updater.win_sparkle_set_app_build_version(str(appversion_nobuild())) - :param tkroot: reference to the root window of the GUI - :param provider: 'internal' or other string if not - """ - self.root: tk.Tk | None = tkroot - self.provider: str = provider - self.thread: threading.Thread | None = None + # set up shutdown callback + self.callback_t = ctypes.CFUNCTYPE(None) # keep reference + self.callback_fn = self.callback_t(self.shutdown_request) + self.updater.win_sparkle_set_shutdown_request_callback(self.callback_fn) - if self.use_internal(): - return + # Get WinSparkle running + self.updater.win_sparkle_init() - if sys.platform == 'win32': - import ctypes - - try: - self.updater: ctypes.CDLL | None = ctypes.cdll.WinSparkle - - # Set the appcast URL - self.updater.win_sparkle_set_appcast_url(get_update_feed().encode()) - - # Set the appversion *without* build metadata, as WinSparkle - # doesn't do proper Semantic Version checks. - # NB: It 'accidentally' supports pre-release due to how it - # splits and compares strings: - # - self.updater.win_sparkle_set_app_build_version(str(appversion_nobuild())) - - # set up shutdown callback - self.callback_t = ctypes.CFUNCTYPE(None) # keep reference - self.callback_fn = self.callback_t(self.shutdown_request) - self.updater.win_sparkle_set_shutdown_request_callback(self.callback_fn) - - # Get WinSparkle running - self.updater.win_sparkle_init() - - except Exception: - print_exc() - self.updater = None - if not os.getenv("EDMC_NO_UI"): - messagebox.showerror( - title=appname, - message="Updater Failed to Initialize. Please file a bug report!" - ) - else: - logger.error("Updater Failed to Initialize. Please file a bug report!") - - return + except Exception: + print_exc() + self.updater = None + msg = "Updater Failed to Initialize. Please file a bug report!" + if not os.getenv("EDMC_NO_UI"): + messagebox.showerror(title=appname, message=msg) + else: + logger.error(msg) def set_automatic_updates_check(self, onoroff: bool) -> None: """ @@ -187,10 +189,8 @@ class Updater: def check_for_updates(self) -> None: """Trigger the requisite method to check for an update.""" if self.use_internal(): - self.thread = threading.Thread(target=self.worker, name='update worker') - self.thread.daemon = True + self.thread = threading.Thread(target=self.worker, name='update worker', daemon=True) self.thread.start() - elif sys.platform == 'win32' and self.updater: self.updater.win_sparkle_check_update_with_ui() @@ -218,7 +218,6 @@ class Updater: except requests.RequestException as ex: logger.exception(f'Error retrieving update_feed file: {ex}') - return None try: @@ -226,7 +225,6 @@ class Updater: except SyntaxError as ex: logger.exception(f'Syntax error in update_feed file: {ex}') - return None # For *these* purposes all systems are the same as 'windows', as @@ -270,7 +268,6 @@ class Updater: # LANG: Update Available Text status['text'] = tr.tl("{NEWVER} is available").format(NEWVER=newversion.title) self.root.update_idletasks() - else: logger.info("No new version available at this time") From 30da989bc58c724c02f4b388016c46d888ace26d Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Tue, 11 Nov 2025 22:16:57 -0500 Subject: [PATCH 27/84] [Minor] Update LastError to a Dataclass --- plug.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/plug.py b/plug.py index eaf23d0d..1a8779f7 100644 --- a/plug.py +++ b/plug.py @@ -13,6 +13,7 @@ import logging import operator import os import sys +from dataclasses import dataclass, field import tkinter as tk from datetime import datetime, timedelta, timezone from pathlib import Path @@ -33,14 +34,12 @@ PLUGINS_broken = [] # For asynchronous error display +@dataclass class LastError: """Holds the last plugin error.""" - msg: str | None - root: tk.Tk - - def __init__(self) -> None: - self.msg = None + msg: str | None = None + root: tk.Tk | None = field(default=None, repr=False) # not initialized by default, hide in repr last_error = LastError() From b8fa0f841bb7ea459dcb598dc59ce8f310c00d25 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Tue, 11 Nov 2025 22:31:54 -0500 Subject: [PATCH 28/84] Revert Bad Label Style Change --- myNotebook.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/myNotebook.py b/myNotebook.py index b488916a..ac7978a7 100644 --- a/myNotebook.py +++ b/myNotebook.py @@ -51,13 +51,10 @@ class Label(ttk.Label): """Custom ttk.Label class to fix some display issues.""" def __init__(self, master: ttk.Frame | None = None, **kw): - style = ttk.Style() - if sys.platform == 'win32': - custom_style = 'nb.TLabel' # Create or update a style to emulate the tk.Label colors - style.configure(custom_style, foreground=PAGEFG, background=PAGEBG) - else: - custom_style = 'TLabel' # Use the platform default ttk style - kw.setdefault('style', custom_style) + kw['foreground'] = kw.pop('foreground', PAGEFG if sys.platform == 'win32' + else ttk.Style().lookup('TLabel', 'foreground')) + kw['background'] = kw.pop('background', PAGEBG if sys.platform == 'win32' + else ttk.Style().lookup('TLabel', 'background')) super().__init__(master, **kw) From 03cbe8553517ec80e5763097a16aac40a696effc Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Tue, 11 Nov 2025 23:17:02 -0500 Subject: [PATCH 29/84] [2116] A Few More Hand-Overs --- EDMarketConnector.py | 2 +- plugins/edsm.py | 10 +++++----- plugins/inara.py | 4 ++-- plugins/spansh_core.py | 5 +++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 0bdfb8c9..a59bbebc 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -2052,7 +2052,7 @@ def show_killswitch_poppup(root=None): idx += 1 idx += 1 - ok_button = tk.Button(frame, text="Ok", command=tl.destroy) + ok_button = ttk.Button(frame, text="Ok", command=tl.destroy) ok_button.grid(columnspan=2, sticky=tk.EW) diff --git a/plugins/edsm.py b/plugins/edsm.py index a2e5004f..e1e6b168 100644 --- a/plugins/edsm.py +++ b/plugins/edsm.py @@ -90,11 +90,11 @@ class This: self.newgame: bool = False # starting up - batch initial burst of events self.newgame_docked: bool = False # starting up while docked self.navbeaconscan: int = 0 # batch up burst of Scan events after NavBeaconScan - self.system_link: tk.Widget | None = None + self.system_link: ttk.Widget | None = None self.system_name: tk.Tk | None = None self.system_address: int | None = None # Frontier SystemAddress self.system_population: int | None = None - self.station_link: tk.Widget | None = None + self.station_link: ttk.Widget | None = None self.station_name: str | None = None self.station_marketid: int | None = None # Frontier MarketID self.on_foot = False @@ -109,7 +109,7 @@ class This: self.log: tk.IntVar | None = None self.log_button: ttk.Checkbutton | None = None - self.label: tk.Widget | None = None + self.label: ttk.Widget | None = None self.cmdr_label: nb.Label | None = None self.cmdr_text: nb.Label | None = None @@ -729,8 +729,8 @@ def send_to_edsm( # noqa: CCR001 # Respect rate limits if they exist if remaining == 0: # Calculate sleep time until the rate limit reset time - reset_time = datetime.utcfromtimestamp(reset) - current_time = datetime.utcnow() + reset_time = datetime.fromtimestamp(reset, tz=timezone.utc) + current_time = datetime.now(timezone.utc) sleep_time = (reset_time - current_time).total_seconds() diff --git a/plugins/inara.py b/plugins/inara.py index e398a3f3..d2fd1efc 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -113,11 +113,11 @@ class This: self.timer_run = True # Main window clicks - self.system_link: tk.Widget = None # type: ignore + self.system_link: ttk.Widget = None # type: ignore self.system_name: str | None = None # type: ignore self.system_address: str | None = None # type: ignore self.system_population: int | None = None - self.station_link: tk.Widget = None # type: ignore + self.station_link: ttk.Widget = None # type: ignore self.station_name = None self.station_marketid = None diff --git a/plugins/spansh_core.py b/plugins/spansh_core.py index 1b7536c5..5a3e541d 100644 --- a/plugins/spansh_core.py +++ b/plugins/spansh_core.py @@ -22,6 +22,7 @@ referenced in this file (or only in any other core plugin), and if so... from __future__ import annotations import tkinter as tk +from tkinter import ttk from typing import Any import requests from companion import CAPIData @@ -39,11 +40,11 @@ class This: def __init__(self): self.parent: tk.Tk self.shutting_down = False # Plugin is shutting down. - self.system_link: tk.Widget = None # type: ignore + self.system_link: ttk.Widget = None # type: ignore self.system_name: str | None = None self.system_address: str | None = None self.system_population: int | None = None - self.station_link: tk.Widget = None # type: ignore + self.station_link: ttk.Widget = None # type: ignore self.station_name = None self.station_marketid = None self.on_foot = False From c190ce92b3cd7976732bb3233743d41248ecea69 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Thu, 13 Nov 2025 21:11:36 -0500 Subject: [PATCH 30/84] [#2526] System Profiler Button Fix Moving this to Develop instead of Main Co-Authored-By: Philipp Trulson --- prefs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prefs.py b/prefs.py index e0660c9f..fc66eea9 100644 --- a/prefs.py +++ b/prefs.py @@ -61,7 +61,7 @@ def help_open_system_profiler(parent) -> None: profiler_path /= 'EDMCSystemProfiler.exe' subprocess.run(profiler_path, check=True) else: - subprocess.run(['python', "EDMCSystemProfiler.py"], shell=True, check=True) + subprocess.run(['python', "EDMCSystemProfiler.py"], shell=False, check=True) except Exception as err: parent.status["text"] = tr.tl("Error in System Profiler") # LANG: Catch & Record Profiler Errors logger.exception(err) From a6bafe58b7c3443ef6d26e1123cc3dfcf68e1f2b Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Thu, 13 Nov 2025 21:45:06 -0500 Subject: [PATCH 31/84] Remove Deprecated Functions --- EDMarketConnector.py | 7 ---- config/__init__.py | 71 +++---------------------------------- l10n.py | 34 ------------------ myNotebook.py | 17 --------- plugins/eddn.py | 28 --------------- tests/config/_old_config.py | 15 -------- tests/config/test_config.py | 3 +- 7 files changed, 5 insertions(+), 170 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index a59bbebc..ce49332f 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -765,13 +765,6 @@ class AppWindow: # Start a protocol handler to handle cAPI registration. Requires main loop to be running. self.w.after_idle(lambda: protocol.protocolhandler.start(self.w)) - # Migration from <= 3.30 - for username in config.get_list('fdev_usernames', default=[]): - config.delete_password(username) - config.delete('fdev_usernames', suppress=True) - config.delete('username', suppress=True) - config.delete('password', suppress=True) - config.delete('logdir', suppress=True) self.postprefs(False) # Companion login happens in callback from monitor self.toggle_suit_row(visible=False) if args.start_min: diff --git a/config/__init__.py b/config/__init__.py index 30f15998..e58df7b6 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -40,7 +40,6 @@ import pathlib import re import subprocess import sys -import warnings from abc import abstractmethod from typing import Any, Callable, Type, TypeVar import semantic_version @@ -52,7 +51,7 @@ appcmdname = 'EDMC' # # Major.Minor.Patch(-prerelease)(+buildmetadata) # NB: Do *not* import this, use the functions appversion() and appversion_nobuild() -_static_appversion = '5.13.2' +_static_appversion = '6.0.0-alpha0' _cached_version: semantic_version.Version | None = None copyright = '© 2015-2019 Jonathan Harris, 2020-2025 EDCD' @@ -68,11 +67,7 @@ capi_pretend_down: bool = False capi_debug_access_token: str | None = None # This must be done here in order to avoid an import cycle with EDMCLogging. # Other code should use EDMCLogging.get_main_logger -if os.getenv("EDMC_NO_UI"): - logger = logging.getLogger(appcmdname) - -else: - logger = logging.getLogger(appname) +logger = logging.getLogger(appcmdname) if os.getenv("EDMC_NO_UI") else logging.getLogger(appname) _T = TypeVar('_T') @@ -334,33 +329,6 @@ class AbstractConfig(abc.ABC): return None - @warnings.deprecated("get() is Deprecated. use the specific getter for your type. Will remove in 6.0") - def get( - self, key: str, - default: list | str | bool | int | None = None - ) -> list | str | bool | int | None: - """ - Return the data for the requested key, or a default. - - :param key: The key data is being requested for. - :param default: The default to return if the key does not exist, defaults to None. - :raises OSError: On Windows, if a Registry error occurs. - :return: The data or the default. - """ - if (a_list := self._suppress_call(self.get_list, ValueError, key, default=None)) is not None: - return a_list - - if (a_str := self._suppress_call(self.get_str, ValueError, key, default=None)) is not None: - return a_str - - if (a_bool := self._suppress_call(self.get_bool, ValueError, key, default=None)) is not None: - return a_bool - - if (an_int := self._suppress_call(self.get_int, ValueError, key, default=None)) is not None: - return an_int - - return default - @abstractmethod def get_list(self, key: str, *, default: list | None = None) -> list: """ @@ -396,16 +364,6 @@ class AbstractConfig(abc.ABC): """ raise NotImplementedError - @warnings.deprecated("Migrate to get_int. Will remove in 6.0 or later.") - def getint(self, key: str, *, default: int = 0) -> int: - """ - Getint is a Deprecated getter method. - - See get_int for its replacement. - :raises OSError: On Windows, if a Registry error occurs. - """ - return self.get_int(key, default=default) - @abstractmethod def get_int(self, key: str, *, default: int = 0) -> int: """ @@ -459,22 +417,6 @@ class AbstractConfig(abc.ABC): """Close this config and release any associated resources.""" raise NotImplementedError - @warnings.deprecated("Password system doesn't do anything. Will remove in 6.0 or later.") - def get_password(self, account: str) -> None: - """Legacy password retrieval.""" - pass - - @warnings.deprecated("Password system doesn't do anything. Will remove in 6.0 or later.") - def set_password(self, account: str, password: str) -> None: - """Legacy password setting.""" - pass - - @warnings.deprecated("Password system doesn't do anything. Will remove in 6.0 or later.") - def delete_password(self, account: str) -> None: - """Legacy password deletion.""" - pass -# End Dep Zone - def get_config(*args, **kwargs) -> AbstractConfig: """ @@ -496,6 +438,8 @@ def get_config(*args, **kwargs) -> AbstractConfig: config = get_config() +if sys.platform == "win32": + config.write_registry_to_toml(f"{config.app_dir_path}/config.toml") # type: ignore # Wiki: https://github.com/EDCD/EDMarketConnector/wiki/Participating-in-Open-Betas-of-EDMC @@ -504,10 +448,3 @@ def get_update_feed() -> str: if config.get_bool('beta_optin'): return 'https://raw.githubusercontent.com/EDCD/EDMarketConnector/releases/edmarketconnector-beta.xml' return 'https://raw.githubusercontent.com/EDCD/EDMarketConnector/releases/edmarketconnector.xml' - - -@warnings.deprecated("Migrate to get_update_feed(). Will remove in 6.0 or later.") -def __getattr__(name: str): - if name == 'update_feed': - return get_update_feed() - raise AttributeError(name=name) diff --git a/l10n.py b/l10n.py index 236d65f4..57c8651b 100755 --- a/l10n.py +++ b/l10n.py @@ -10,12 +10,10 @@ Localization with gettext is a pain on non-Unix systems. """ from __future__ import annotations -import builtins import locale import numbers import re import sys -import warnings from contextlib import suppress from os import listdir, sep from typing import Iterable, TextIO, cast @@ -77,8 +75,6 @@ class Translations: Use when translation is not desired or not available """ self.translations = {None: {}} - # 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 """ @@ -121,9 +117,6 @@ class Translations: except Exception: logger.exception(f'Exception occurred while parsing {lang}.strings in plugin {plugin}') - # 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: pathlib.Path | None = None) -> dict[str, str]: """Load all the translations from a translation file.""" if lang not in self.available() and lang != self.FALLBACK: # Because "en" doesn't appear in self.available() @@ -262,21 +255,6 @@ def _wszarray_to_list(array): class _Locale: """Locale holds a few utility methods to convert data to and from localized versions.""" - @warnings.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: N802 - warnings.warn('use _Locale.string_from_number instead.', DeprecationWarning, stacklevel=2) - return self.string_from_number(number, decimals) # type: ignore - - @warnings.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) - - @warnings.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() - def string_from_number(self, number: float | int, decimals: int = 5) -> str: """ Convert a number to a string. @@ -353,18 +331,6 @@ class _Locale: Locale = _Locale() translations = Translations() - -@warnings.deprecated("Migrate to `translations`. Will be removed in 6.0 or later.") -# Begin Deprecation Zone -class _Translations(Translations): - def __init__(self): - super().__init__() - - -# Yes, I know this is awful renaming garbage. But we need it for compat. -Translations: Translations = translations # type: ignore -# End Deprecation Zone - # generate template strings file - like xgettext # parsing is limited - only single ' or " delimited strings, and only one string per line if __name__ == "__main__": diff --git a/myNotebook.py b/myNotebook.py index ac7978a7..8541a5f9 100644 --- a/myNotebook.py +++ b/myNotebook.py @@ -11,7 +11,6 @@ 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 @@ -119,14 +118,6 @@ class EntryMenu(ttk.Entry): pass -class Entry(EntryMenu): - """Custom ttk.Entry class to fix some display issues.""" - - @warnings.deprecated("Migrate to EntryMenu. Will remove in 6.0 or later.") - def __init__(self, master: ttk.Frame | None = None, **kw): - EntryMenu.__init__(self, master, **kw) - - class Button(ttk.Button): """Custom ttk.Button class to fix some display issues.""" @@ -135,14 +126,6 @@ class Button(ttk.Button): super().__init__(master, style=style, **kw) # type: ignore -class ColoredButton(tk.Button): - """Custom tk.Button class to fix some display issues.""" - - @warnings.deprecated("Migrate to tk.Button. Will remove in 6.0 or later.") - def __init__(self, master: ttk.Frame | None = None, **kw): - tk.Button.__init__(self, master, **kw) - - class Checkbutton(ttk.Checkbutton): """Custom ttk.Checkbutton class to fix some display issues.""" diff --git a/plugins/eddn.py b/plugins/eddn.py index 2e37e1bf..6410d0b2 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -30,7 +30,6 @@ import re import sqlite3 import tkinter as tk from tkinter import ttk -import warnings from platform import system from textwrap import dedent from threading import Lock @@ -172,12 +171,6 @@ class EDDNSender: self.db_conn = self.sqlite_queue_v1() self.db = self.db_conn.cursor() - ####################################################################### - # Queue database migration - ####################################################################### - self.convert_legacy_file() - ####################################################################### - self.queue_processing = Lock() # Initiate retry/send-now timer logger.trace_if( @@ -223,27 +216,6 @@ class EDDNSender: return db_conn - @warnings.deprecated("Legacy files no longer used as of 5.6.0. Will remove in 6.0 or later.") - def convert_legacy_file(self): - """Convert a legacy file's contents into the sqlite3 db.""" - filename = config.app_dir_path / 'replay.jsonl' - if not filename.exists(): - return - logger.info("Converting legacy `replay.jsonl` to `eddn_queue-v1.db`") - try: - with filename.open('r', encoding='utf-8') as replay_file: - for line in replay_file: - cmdr, msg = json.loads(line) - self.add_message(cmdr, msg) - except Exception as e: - logger.exception("Failed to convert legacy file: %s", e) - return - logger.info("Conversion complete, removing `replay.jsonl`") - try: - filename.unlink() - except Exception as e: - logger.warning("Could not delete legacy file: %s", e) - def close(self) -> None: """Clean up any resources.""" logger.debug('Closing db cursor.') diff --git a/tests/config/_old_config.py b/tests/config/_old_config.py index 2b5244b6..dea1f2b3 100644 --- a/tests/config/_old_config.py +++ b/tests/config/_old_config.py @@ -3,7 +3,6 @@ from __future__ import annotations import numbers import sys -import warnings from configparser import NoOptionError from os import getenv, makedirs, mkdir from os.path import dirname, expanduser, isdir, join @@ -389,19 +388,5 @@ class OldConfig: def __init__(self): raise NotImplementedError('Implement me') - # Common - - def get_password(self, account: str) -> None: - """Legacy password retrieval.""" - warnings.warn("password subsystem is no longer supported", DeprecationWarning) - - def set_password(self, account: str, password: str) -> None: - """Legacy password setting.""" - warnings.warn("password subsystem is no longer supported", DeprecationWarning) - - def delete_password(self, account: str) -> None: - """Legacy password deletion.""" - warnings.warn("password subsystem is no longer supported", DeprecationWarning) - old_config = OldConfig() diff --git a/tests/config/test_config.py b/tests/config/test_config.py index 642da5c2..cf48acad 100644 --- a/tests/config/test_config.py +++ b/tests/config/test_config.py @@ -143,8 +143,7 @@ class TestNewConfig: config.set(name, '1337') config.save() self.__update_linuxconfig() - with pytest.deprecated_call(): - res = config.get(name) + res = config.get_str(name) assert res == '1337' config.delete(name) From bbb905a534fddca77cc0228b9ebe292768f77526 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Thu, 13 Nov 2025 21:46:21 -0500 Subject: [PATCH 32/84] Remove Prefs Dep Function --- prefs.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/prefs.py b/prefs.py index fc66eea9..5d604d39 100644 --- a/prefs.py +++ b/prefs.py @@ -9,7 +9,6 @@ from pathlib import Path import subprocess import sys import tkinter as tk -import warnings from os import system from tkinter import colorchooser as tkColorChooser # type: ignore # noqa: N812 from tkinter import ttk @@ -37,12 +36,6 @@ logger = get_main_logger() # May be imported by plugins -@warnings.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.""" - open_folder(Path(config.app_dir_path / 'logs')) - - def open_folder(file: Path) -> None: """Open the given file in the OS file explorer.""" if sys.platform.startswith('win'): From 5405664d52b9527aa5b4053857eba74e04a7786a Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Thu, 13 Nov 2025 22:26:00 -0500 Subject: [PATCH 33/84] [Minor] Don't Continually Enable EDAstro --- plugins/edastro_core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/edastro_core.py b/plugins/edastro_core.py index a6929217..6363b2d9 100644 --- a/plugins/edastro_core.py +++ b/plugins/edastro_core.py @@ -89,7 +89,7 @@ this = This() def set_config_first_run() -> None: """Enable EDAstro if the config key does not exist.""" - if not config.get_bool("edastro_send"): + if config.get_int("edastro_send", default=None) is None: logger.info("EDAstro First Run. Enabling") config.set("edastro_send", 1) From 71e803f8b5c0bb359cfa054cc63987c0b1dc2860 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Thu, 13 Nov 2025 22:31:02 -0500 Subject: [PATCH 34/84] [Minor] Don't Continually Enable EDAstro --- plugins/edastro_core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/edastro_core.py b/plugins/edastro_core.py index 6363b2d9..6e2be692 100644 --- a/plugins/edastro_core.py +++ b/plugins/edastro_core.py @@ -89,7 +89,7 @@ this = This() def set_config_first_run() -> None: """Enable EDAstro if the config key does not exist.""" - if config.get_int("edastro_send", default=None) is None: + if config.get_int("edastro_send") is None: logger.info("EDAstro First Run. Enabling") config.set("edastro_send", 1) From 2d3373843e2eb8cd857c5d22623d7366bb1f1281 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Thu, 13 Nov 2025 22:41:33 -0500 Subject: [PATCH 35/84] [517] Export Windows Config to TOML --- config/windows.py | 76 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 3 deletions(-) diff --git a/config/windows.py b/config/windows.py index f5676424..96d073c1 100644 --- a/config/windows.py +++ b/config/windows.py @@ -12,7 +12,10 @@ import pathlib import sys import uuid import winreg -from typing import Literal +import datetime +import tomli_w +import base64 +from typing import Literal, Any from config import AbstractConfig, applongname, appname, logger from win32comext.shell import shell @@ -33,7 +36,7 @@ class WinConfig(AbstractConfig): def __init__(self) -> None: super().__init__() - REGISTRY_SUBKEY = r'Software\Marginal\EDMarketConnector' # noqa: N806 + self.REGISTRY_SUBKEY = r'Software\Marginal\EDMarketConnector' create_key_defaults = functools.partial( winreg.CreateKeyEx, key=winreg.HKEY_CURRENT_USER, @@ -41,7 +44,7 @@ class WinConfig(AbstractConfig): ) try: - self.__reg_handle: winreg.HKEYType = create_key_defaults(sub_key=REGISTRY_SUBKEY) + self.__reg_handle: winreg.HKEYType = create_key_defaults(sub_key=self.REGISTRY_SUBKEY) except OSError: logger.exception('Could not create required registry keys') @@ -76,6 +79,73 @@ class WinConfig(AbstractConfig): docs = known_folder_path(shell.FOLDERID_Documents) self.set("outdir", docs if docs is not None else self.home) + def _convert_reg_value_for_toml(self, data, data_type): + """Convert Windows registry values into TOML-native types for 6.0's global config.""" + # Plain string + if data_type == winreg.REG_SZ: + return str(data) + + # Expandable string: keep as string + if data_type == winreg.REG_EXPAND_SZ: + try: + expanded = winreg.ExpandEnvironmentStrings(data) + except Exception: + expanded = data + return str(expanded) + + # DWORD or QWORD: store as integer + if data_type in (winreg.REG_DWORD, winreg.REG_QWORD): + return int(data) + + # Multi-string: store as list + if data_type == winreg.REG_MULTI_SZ: + return list(data) + + # Binary: store as base64 string + if data_type == winreg.REG_BINARY: + return base64.b64encode(data).decode("ascii") + + # Else, force to string + return str(data) + + def write_registry_to_toml(self, toml_path: str) -> None: + """ + Export all registry values under self.REGISTRY_SUBKEY into a global TOML config. + + Values are normalized into TOML-native types (str, int, list, base64). + Booleans are left as ints (0/1) and should be interpreted adaptively by get_bool. + """ + key = self.__reg_handle + + try: + _, num_values, _ = winreg.QueryInfoKey(key) + + # Write config, including writing where and when we got this from. + config_data: dict[str, Any] = { + "generated": datetime.datetime.now(datetime.timezone.utc).isoformat(), + "source": "windows_registry", + "subkey": self.REGISTRY_SUBKEY, + "settings": {} + } + + settings = config_data["settings"] + + for i in range(num_values): + name, data, data_type = winreg.EnumValue(key, i) + settings[name] = self._convert_reg_value_for_toml(data, data_type) + + # Write TOML to file + path_obj = pathlib.Path(toml_path) + path_obj.parent.mkdir(parents=True, exist_ok=True) + with path_obj.open("wb") as f: + tomli_w.dump(config_data, f) + + logger.info(f"Registry exported to TOML: {toml_path}") + + except OSError: + logger.exception(f"Could not export registry key {self.REGISTRY_SUBKEY}") + raise + def __get_regentry(self, key: str) -> None | list | str | int: """Access the Registry for the raw entry.""" try: From 567d42e4b35a9eddefc747c20f1feaf6faa30bb7 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Sun, 16 Nov 2025 19:08:19 -0500 Subject: [PATCH 36/84] [517] Hand Over Config to New Format --- EDMCLogging.py | 4 +- EDMCSystemProfiler.py | 4 +- config/__init__.py | 358 ++++++++++++++++++++++++++---------------- config/linux.py | 291 ++++++++-------------------------- config/windows.py | 298 ++++++++--------------------------- requirements.txt | 1 + 6 files changed, 358 insertions(+), 598 deletions(-) diff --git a/EDMCLogging.py b/EDMCLogging.py index 59c8e312..201648a2 100644 --- a/EDMCLogging.py +++ b/EDMCLogging.py @@ -51,7 +51,7 @@ from threading import get_native_id as thread_native_id from time import gmtime from traceback import print_exc from typing import TYPE_CHECKING, cast -from config import appcmdname, appname, config, trace_on +from config import appcmdname, appname, config, trace_on, config_logger # TODO: Tests: # @@ -535,4 +535,6 @@ if not loglevel: base_logger_name = appcmdname if os.getenv('EDMC_NO_UI') else appname edmclogger = Logger(base_logger_name, loglevel=loglevel) +for h in config_logger.handlers[:]: + config_logger.removeHandler(h) logger: 'LoggerMixin' = edmclogger.get_logger() diff --git a/EDMCSystemProfiler.py b/EDMCSystemProfiler.py index a5d97ce4..123ca5fc 100644 --- a/EDMCSystemProfiler.py +++ b/EDMCSystemProfiler.py @@ -38,7 +38,7 @@ from monitor import monitor from EDMCLogging import get_main_logger -def get_sys_report(active_config: config.AbstractConfig) -> str: +def get_sys_report(active_config: config.Config) -> str: """Gather system information about Elite, the Host Computer, and EDMC.""" # Calculate Requested Information plt = platform.uname() @@ -108,7 +108,7 @@ def copy_sys_report(root: tk.Tk, report: str) -> None: messagebox.showinfo("System Profiler", "System Report copied to Clipboard", parent=root) -def main(active_config: config.AbstractConfig) -> None: +def main(active_config: config.Config) -> None: """Entry Point for the System Profiler.""" # Now Let's Begin root: tk.Tk = tk.Tk() diff --git a/config/__init__.py b/config/__init__.py index e58df7b6..e7505f1e 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -12,27 +12,27 @@ from __future__ import annotations __all__ = [ # defined in the order they appear in the file - 'GITVERSION_FILE', - 'appname', - 'applongname', - 'appcmdname', - 'copyright', - 'update_interval', - 'debug_senders', - 'trace_on', - 'capi_pretend_down', - 'capi_debug_access_token', - 'logger', - 'git_shorthash_from_head', - 'appversion', - 'user_agent', - 'appversion_nobuild', - 'AbstractConfig', - 'config', - 'get_update_feed', + "GITVERSION_FILE", + "appname", + "applongname", + "appcmdname", + "copyright", + "update_interval", + "debug_senders", + "trace_on", + "capi_pretend_down", + "capi_debug_access_token", + "logger", + "git_shorthash_from_head", + "appversion", + "user_agent", + "appversion_nobuild", + "Config", + "config", + "get_update_feed", + "config_logger", ] -import abc import contextlib import logging import os @@ -40,23 +40,25 @@ import pathlib import re import subprocess import sys -from abc import abstractmethod +import tomllib +import tomli_w +from time import gmtime from typing import Any, Callable, Type, TypeVar import semantic_version from constants import GITVERSION_FILE, applongname, appname # Any of these may be imported by plugins -appcmdname = 'EDMC' +appcmdname = "EDMC" # appversion **MUST** follow Semantic Versioning rules: # # Major.Minor.Patch(-prerelease)(+buildmetadata) # NB: Do *not* import this, use the functions appversion() and appversion_nobuild() -_static_appversion = '6.0.0-alpha0' +_static_appversion = "6.0.0-alpha0" _cached_version: semantic_version.Version | None = None -copyright = '© 2015-2019 Jonathan Harris, 2020-2025 EDCD' +copyright = "© 2015-2019 Jonathan Harris, 2020-2025 EDCD" -update_interval = 8*60*60 # 8 Hours +update_interval = 8 * 60 * 60 # 8 Hours # Providers marked to be in debug mode. Generally this is expected to switch to sending data to a log file debug_senders: list[str] = [] # TRACE logging code that should actually be used. Means not spamming it @@ -67,10 +69,14 @@ capi_pretend_down: bool = False capi_debug_access_token: str | None = None # This must be done here in order to avoid an import cycle with EDMCLogging. # Other code should use EDMCLogging.get_main_logger -logger = logging.getLogger(appcmdname) if os.getenv("EDMC_NO_UI") else logging.getLogger(appname) +logger = ( + logging.getLogger(appcmdname) + if os.getenv("EDMC_NO_UI") + else logging.getLogger(appname) +) -_T = TypeVar('_T') +_T = TypeVar("_T") def git_shorthash_from_head() -> str | None: @@ -94,14 +100,14 @@ def git_shorthash_from_head() -> str | None: return None if not re.fullmatch(r"[0-9a-f]{7,}", shorthash): - logger.error(f"'{shorthash}' doesn't look like a valid git short hash, forcing to None") + logger.error( + f"'{shorthash}' doesn't look like a valid git short hash, forcing to None" + ) return None with contextlib.suppress(Exception): diff_result = subprocess.run( - ["git", "diff", "--stat", "HEAD"], - capture_output=True, - check=True + ["git", "diff", "--stat", "HEAD"], capture_output=True, check=True ) if diff_result.stdout: shorthash += ".DIRTY" @@ -121,10 +127,12 @@ def appversion() -> semantic_version.Version: if _cached_version is not None: return _cached_version - if getattr(sys, 'frozen', False): + if getattr(sys, "frozen", False): # Running frozen, so we should have a .gitversion file # Yes, .parent because if frozen we're inside library.zip - with open(pathlib.Path(sys.path[0]).parent / GITVERSION_FILE, encoding='utf-8') as gitv: + with open( + pathlib.Path(sys.path[0]).parent / GITVERSION_FILE, encoding="utf-8" + ) as gitv: shorthash: str | None = gitv.read() else: @@ -134,16 +142,18 @@ def appversion() -> semantic_version.Version: shorthash = git_shorthash_from_head() if shorthash is None: if pathlib.Path(sys.path[0] + "/" + GITVERSION_FILE).exists(): - with open(pathlib.Path(sys.path[0] + "/" + GITVERSION_FILE), encoding='utf-8') as gitv: + with open( + pathlib.Path(sys.path[0] + "/" + GITVERSION_FILE), encoding="utf-8" + ) as gitv: shorthash = gitv.read() else: - shorthash = 'UNKNOWN' + shorthash = "UNKNOWN" - _cached_version = semantic_version.Version(f'{_static_appversion}+{shorthash}') + _cached_version = semantic_version.Version(f"{_static_appversion}+{shorthash}") return _cached_version -user_agent = f'EDCD-{appname}-{appversion()}' +user_agent = f"EDCD-{appname}-{appversion()}" def appversion_nobuild() -> semantic_version.Version: @@ -155,12 +165,12 @@ def appversion_nobuild() -> semantic_version.Version: :return: App version without any build meta data. """ - return appversion().truncate('prerelease') + return appversion().truncate("prerelease") -class AbstractConfig(abc.ABC): +class Config: """ - Abstract root class of all platform specific Config implementations. + Platform-unified Config class for 6.0+. Commented lines are no longer supported or replaced. """ @@ -197,13 +207,113 @@ class AbstractConfig(abc.ABC): __eddn_tracking_ui = False # Show EDDN tracking UI ? __skip_timecheck = False # Skip checking event timestamps? - def __init__(self) -> None: + def __init__(self, app_path) -> None: self.home_path = pathlib.Path.home() + # Set Needed Platform Var for app_dir_path + self.app_dir_path = app_path + + self.toml_path: pathlib.Path = self.app_dir_path / "config.toml" + self.generated: str | None = None + self.source: str | None = None + self.settings: dict[str, Any] = {} + self._load() + self.default_plugin_dir_path = self.app_dir_path / "plugins" + if (plugdir_str := self.get_str("plugin_dir")) is None or not pathlib.Path( + plugdir_str + ).is_dir(): + self.set("plugin_dir", str(self.default_plugin_dir_path)) + plugdir_str = self.default_plugin_dir + self.plugin_dir_path = pathlib.Path(plugdir_str) + self.plugin_dir_path.mkdir(exist_ok=True) + + # Call the rest of the platform var helpers + self._init_platform() + + def _init_platform(self): + if sys.platform == "win32": + from .windows import win_helper + + win_helper(self) + elif sys.platform == "linux": + from .linux import linux_helper + + linux_helper(self) + else: + raise RuntimeError(f"Unsupported platform: {sys.platform}") def set_shutdown(self): """Set flag denoting we're in the shutdown sequence.""" self.__in_shutdown = True + def _load(self): + """Load TOML from disk and store fields.""" + if not self.toml_path.exists(): + raise FileNotFoundError(f"Config file not found: {self.toml_path}") + + with self.toml_path.open("rb") as f: + data = tomllib.load(f) + + # Capture metadata + self.generated = data.get("generated") + self.source = data.get("source") + + # Settings dict created by write_registry_to_toml() + raw_settings = data.get("settings", {}) + self.settings = {} + + self.settings = dict(raw_settings) + + def get(self, key: str, default=None): + """Return raw stored value.""" + return self.settings.get(key, default) + + def get_str(self, key: str, default="") -> str: + """Return string value.""" + val = self.get(key, default) + return str(val) if val is not None else default + + def get_int(self, key: str, default=0) -> int: + """Adaptive int (handles booleans stored as ints).""" + val = self.get(key) + if isinstance(val, int): + return val + try: + return int(val) + except (ValueError, TypeError): + return default + + def get_bool(self, key: str, default=False) -> bool: + """ + Adaptive boolean reader. + + - Accepts ints 0/1 + - Accepts strings "true"/"false"/"1"/"0" + - Accepts real booleans + """ + val = self.get(key) + + if isinstance(val, bool): + return val + + if isinstance(val, int): + return val != 0 + + if isinstance(val, str): + v = val.strip().lower() + if v in ("1", "true", "yes", "on"): + return True + if v in ("0", "false", "no", "off"): + return False + + return default + + def get_list(self, key: str, default=None): + """Return the list referred to by the given key if it exists, or the default.""" + val = self.get(key) + return ( + val if isinstance(val, list) else (default if default is not None else []) + ) + @property def shutting_down(self) -> bool: """ @@ -315,8 +425,10 @@ class AbstractConfig(abc.ABC): @staticmethod def _suppress_call( - func: Callable[..., _T], exceptions: Type[BaseException] | list[Type[BaseException]] = Exception, - *args: Any, **kwargs: Any + func: Callable[..., _T], + exceptions: Type[BaseException] | list[Type[BaseException]] = Exception, + *args: Any, + **kwargs: Any, ) -> _T | None: if exceptions is None: exceptions = [Exception] @@ -329,96 +441,54 @@ class AbstractConfig(abc.ABC): return None - @abstractmethod - def get_list(self, key: str, *, default: list | None = None) -> list: - """ - Return the list referred to by the given key if it exists, or the default. - - Implements :meth:`AbstractConfig.get_list`. - """ - raise NotImplementedError - - @abstractmethod - def get_str(self, key: str, *, default: str | None = None) -> str: - """ - Return the string referred to by the given key if it exists, or the default. - - :param key: The key data is being requested for. - :param default: Default to return if the key does not exist, defaults to None. - :raises ValueError: If an internal error occurs getting or converting a value. - :raises OSError: On Windows, if a Registry error occurs. - :return: The requested data or the default. - """ - raise NotImplementedError - - @abstractmethod - def get_bool(self, key: str, *, default: bool | None = None) -> bool: - """ - Return the bool referred to by the given key if it exists, or the default. - - :param key: The key data is being requested for. - :param default: Default to return if the key does not exist, defaults to None - :raises ValueError: If an internal error occurs getting or converting a value - :raises OSError: On Windows, if a Registry error occurs. - :return: The requested data or the default - """ - raise NotImplementedError - - @abstractmethod - def get_int(self, key: str, *, default: int = 0) -> int: - """ - Return the int referred to by key if it exists in the config. - - For legacy reasons, the default is 0 and not None. - - :param key: The key data is being requested for. - :param default: Default to return if the key does not exist, defaults to 0. - :raises ValueError: If the internal representation of this key cannot be converted to an int. - :raises OSError: On Windows, if a Registry error occurs. - :return: The requested data or the default. - """ - raise NotImplementedError - - @abstractmethod - def set(self, key: str, val: int | str | list[str] | bool) -> None: - """ - Set the given key's data to the given value. - - :param key: The key to set the value on. - :param val: The value to set the key's data to. - :raises ValueError: On an invalid type. - :raises OSError: On Windows, if a Registry error occurs. - """ - raise NotImplementedError - - @abstractmethod def delete(self, key: str, *, suppress=False) -> None: - """ - Delete the given key from the config. + """Delete the given key from the config.""" + try: + self.settings.pop(key, None) + except (KeyError, IndexError): + if suppress: + return + raise + self.save() - :param key: The key to delete. - :param suppress: bool - Whether to suppress any errors. Useful in case - code to migrate settings is blindly removing an old key. - :raises OSError: On Windows, if a registry error occurs. - """ - raise NotImplementedError + def set(self, key: str, value: Any): + """Modify a setting and save to disk.""" + self.settings[key] = value + self.save() - @abstractmethod - def save(self) -> None: - """ - Save the current configuration. + def save(self): + """Write updated config back to TOML.""" + data = { + "generated": self.generated, + "source": self.source, + "settings": self.settings, + } - :raises OSError: On Windows, if a Registry error occurs. - """ - raise NotImplementedError + with self.toml_path.open("wb") as f: + tomli_w.dump(data, f) - @abstractmethod def close(self) -> None: - """Close this config and release any associated resources.""" - raise NotImplementedError + """Save config changes before closing.""" + self.save() -def get_config(*args, **kwargs) -> AbstractConfig: +def get_appdirpath(): + """Grab the Application Directory early.""" + app_dir_path = None + if sys.platform == "win32": + base = pathlib.Path(os.getenv("LOCALAPPDATA")) # type: ignore + app_dir_path = base / appname + if sys.platform == "linux": + xdg_data_home = pathlib.Path( + os.getenv("XDG_DATA_HOME", default="~/.local/share") + ).expanduser() + app_dir_path = xdg_data_home / appname + if app_dir_path is None: + raise ValueError + return app_dir_path + + +def get_config(*args, **kwargs) -> Config: """ Get the appropriate config class for the current platform. @@ -426,25 +496,45 @@ def get_config(*args, **kwargs) -> AbstractConfig: :param kwargs: Args to be passed through to implementation. :return: Instance of the implementation. """ + app_dir_path = get_appdirpath() + config = None + if pathlib.Path.exists(app_dir_path / "config.toml"): + return Config(app_path=app_dir_path) + if sys.platform == "win32": # pragma: sys-platform-win32 - from .windows import WinConfig - return WinConfig(*args, **kwargs) + from .windows import WinConfigMinimal + + config = WinConfigMinimal() if sys.platform == "linux": # pragma: sys-platform-linux - from .linux import LinuxConfig - return LinuxConfig(*args, **kwargs) + from .linux import LinuxConfigMinimal + config = LinuxConfigMinimal() - raise ValueError(f'Unknown platform: {sys.platform=}') + if config: + config.write_to_toml(f"{app_dir_path}/config.toml") # type: ignore + return Config(app_path=app_dir_path) + + raise ValueError(f"Unknown platform: {sys.platform=}") + + +# Set internal Config logger, because config is set up before main logger. +config_logger = logging.getLogger("pre_config") +config_logger.setLevel(logging.DEBUG) # Or INFO + +ch = logging.StreamHandler() +ch.setLevel(logging.DEBUG) +formatter = logging.Formatter("%(asctime)s [%(levelname)s] %(message)s") +formatter.converter = gmtime # Optional: match your main logger's UTC timestamps +ch.setFormatter(formatter) +config_logger.addHandler(ch) config = get_config() -if sys.platform == "win32": - config.write_registry_to_toml(f"{config.app_dir_path}/config.toml") # type: ignore # Wiki: https://github.com/EDCD/EDMarketConnector/wiki/Participating-in-Open-Betas-of-EDMC def get_update_feed() -> str: """Select the proper update feed for the current update track.""" - if config.get_bool('beta_optin'): - return 'https://raw.githubusercontent.com/EDCD/EDMarketConnector/releases/edmarketconnector-beta.xml' - return 'https://raw.githubusercontent.com/EDCD/EDMarketConnector/releases/edmarketconnector.xml' + if config.get_bool("beta_optin"): + return "https://raw.githubusercontent.com/EDCD/EDMarketConnector/releases/edmarketconnector-beta.xml" + return "https://raw.githubusercontent.com/EDCD/EDMarketConnector/releases/edmarketconnector.xml" diff --git a/config/linux.py b/config/linux.py index 651fea09..9260cd74 100644 --- a/config/linux.py +++ b/config/linux.py @@ -5,252 +5,87 @@ Copyright (c) EDCD, All Rights Reserved Licensed under the GNU General Public License. See LICENSE file. """ + from __future__ import annotations import os -import pathlib import sys -from configparser import ConfigParser -from config import AbstractConfig, appname, logger +from config import config_logger -if sys.platform != 'linux': +if sys.platform != "linux": raise EnvironmentError("This file is for Linux only.") -class LinuxConfig(AbstractConfig): - """Linux implementation of AbstractConfig.""" +import pathlib +from configparser import ConfigParser +import datetime +import tomli_w +from typing import Any, TYPE_CHECKING - SECTION = 'config' - # TODO: I dislike this, would rather use a sane config file format. But here we are. - __unescape_lut = {'\\': '\\', 'n': '\n', ';': ';', 'r': '\r', '#': '#'} - __escape_lut = {'\\': '\\', '\n': 'n', ';': ';', '\r': 'r'} +if TYPE_CHECKING: + from . import Config + + +class LinuxConfigMinimal: + """Minimal Linux config loader that dumps existing config to TOML.""" + + SECTION = "config" def __init__(self, filename: str | None = None) -> None: - super().__init__() - # http://standards.freedesktop.org/basedir-spec/latest/ar01s03.html - xdg_data_home = pathlib.Path(os.getenv('XDG_DATA_HOME', default='~/.local/share')).expanduser() - self.app_dir_path = xdg_data_home / appname - self.app_dir_path.mkdir(exist_ok=True, parents=True) - - self.default_plugin_dir_path = self.app_dir_path / 'plugins' - self.respath_path = pathlib.Path(__file__).parent.parent - - self.internal_plugin_dir_path = self.respath_path / 'plugins' - self.default_journal_dir_path = None # type: ignore - self.identifier = f'uk.org.marginal.{appname.lower()}' # TODO: Unused? - - config_home = pathlib.Path(os.getenv('XDG_CONFIG_HOME', default='~/.config')).expanduser() - - self.filename = config_home / appname / f'{appname}.ini' - if filename is not None: - self.filename = pathlib.Path(filename) - + # Determine config path + xdg_config_home = pathlib.Path( + os.getenv("XDG_CONFIG_HOME", "~/.config") + ).expanduser() + self.filename = ( + pathlib.Path(filename) + if filename + else xdg_config_home / "EDMarketConnector" / "EDMarketConnector.ini" + ) self.filename.parent.mkdir(exist_ok=True, parents=True) - self.config: ConfigParser | None = ConfigParser(comment_prefixes=('#',), interpolation=None) - self.config.read(self.filename) # read() ignores files that dont exist - - # Ensure that our section exists. This is here because configparser will happily create files for us, but it - # does not magically create sections - try: - self.config[self.SECTION].get("this_does_not_exist", fallback=None) - except KeyError: - logger.info("Config section not found. Backing up existing file (if any) and readding a section header") - if self.filename.exists(): - (self.filename.parent / f'{appname}.ini.backup').write_bytes(self.filename.read_bytes()) + # Load INI + self.config = ConfigParser(interpolation=None) + self.config.read(self.filename) + # Ensure section exists + if self.SECTION not in self.config: self.config.add_section(self.SECTION) - if (plugdir_str := self.get_str('plugin_dir')) is None or not pathlib.Path(plugdir_str).is_dir(): - self.set("plugin_dir", str(self.default_plugin_dir_path)) - plugdir_str = self.default_plugin_dir - self.plugin_dir_path = pathlib.Path(plugdir_str) - self.plugin_dir_path.mkdir(exist_ok=True) + def _get_settings_dict(self) -> dict[str, Any]: + """Return all keys/values from SECTION as a dict of strings.""" + return { + key: self.config[self.SECTION][key] for key in self.config[self.SECTION] + } - if (outdir := self.get_str('outdir')) is None or not pathlib.Path(outdir).is_dir(): - self.set('outdir', self.home) + def write_to_toml(self, toml_path: str) -> None: + """Dump existing config to TOML file.""" + config_logger.debug("Generating New Config File") + config_data: dict[str, Any] = { + "generated": datetime.datetime.now(datetime.timezone.utc).isoformat(), + "source": "linux_ini", + "section": self.SECTION, + "settings": self._get_settings_dict(), + } - def __escape(self, s: str) -> str: - """ - Escape a string using self.__escape_lut. - - This does NOT support multi-character escapes. - - :param s: str - String to be escaped. - :return: str - The escaped string. - """ - out = "" - for c in s: - if c not in self.__escape_lut: - out += c - continue - - out += '\\' + self.__escape_lut[c] - - return out - - def __unescape(self, s: str) -> str: - """ - Unescape a string. - - :param s: str - The string to unescape. - :return: str - The unescaped string. - """ - out: list[str] = [] - i = 0 - while i < len(s): - c = s[i] - if c != '\\': - out.append(c) - i += 1 - continue - - # We have a backslash, check what its escaping - if i == len(s)-1: - raise ValueError('Escaped string has unescaped trailer') - - unescaped = self.__unescape_lut.get(s[i+1]) - if unescaped is None: - raise ValueError(f'Unknown escape: \\ {s[i+1]}') - - out.append(unescaped) - i += 2 - - return "".join(out) - - def __raw_get(self, key: str) -> str | None: - """ - Get a raw data value from the config file. - - :param key: str - The key data is being requested for. - :return: str - The raw data, if found. - """ - if self.config is None: - raise ValueError('Attempt to use a closed config') - - return self.config[self.SECTION].get(key) - - def get_str(self, key: str, *, default: str | None = None) -> str: - """ - Return the string referred to by the given key if it exists, or the default. - - Implements :meth:`AbstractConfig.get_str`. - """ - data = self.__raw_get(key) - if data is None: - return default # type: ignore # Yes it could be None, but we're _assuming_ that people gave us a default - - if '\n' in data: - raise ValueError('asked for string, got list') - - return self.__unescape(data) - - def get_list(self, key: str, *, default: list | None = None) -> list: - """ - Return the list referred to by the given key if it exists, or the default. - - Implements :meth:`AbstractConfig.get_list`. - """ - data = self.__raw_get(key) - - if data is None: - return default # type: ignore # Yes it could be None, but we're _assuming_ that people gave us a default - - split = data.split('\n') - if split[-1] != ';': - raise ValueError('Encoded list does not have trailer sentinel') - - return list(map(self.__unescape, split[:-1])) - - def get_int(self, key: str, *, default: int = 0) -> int: - """ - Return the int referred to by key if it exists in the config. - - Implements :meth:`AbstractConfig.get_int`. - """ - data = self.__raw_get(key) - - if data is None: - return default - - try: - return int(data) - - except ValueError as e: - raise ValueError(f'requested {key=} as int cannot be converted to int') from e - - def get_bool(self, key: str, *, default: bool | None = None) -> bool: - """ - Return the bool referred to by the given key if it exists, or the default. - - Implements :meth:`AbstractConfig.get_bool`. - """ - if self.config is None: - raise ValueError('attempt to use a closed config') - - data = self.__raw_get(key) - if data is None: - return default # type: ignore # Yes it could be None, but we're _assuming_ that people gave us a default - - return bool(int(data)) - - def set(self, key: str, val: int | str | list[str]) -> None: - """ - Set the given key's data to the given value. - - Implements :meth:`AbstractConfig.set`. - """ - if self.config is None: - raise ValueError('attempt to use a closed config') - - to_set: str | None = None - if isinstance(val, bool): - to_set = str(int(val)) - - elif isinstance(val, str): - to_set = self.__escape(val) - - elif isinstance(val, int): - to_set = str(val) - - elif isinstance(val, list): - to_set = '\n'.join([self.__escape(s) for s in val] + [';']) - - else: - raise ValueError(f'Unexpected type for value {type(val)=}') - - self.config.set(self.SECTION, key, to_set) - self.save() - - def delete(self, key: str, *, suppress=False) -> None: - """ - Delete the given key from the config. - - Implements :meth:`AbstractConfig.delete`. - """ - if self.config is None: - raise ValueError('attempt to use a closed config') - - self.config.remove_option(self.SECTION, key) - self.save() - - def save(self) -> None: - """ - Save the current configuration. - - Implements :meth:`AbstractConfig.save`. - """ - if self.config is None: - raise ValueError('attempt to use a closed config') - - with open(self.filename, 'w', encoding='utf-8') as f: - self.config.write(f) + path_obj = pathlib.Path(toml_path) + path_obj.parent.mkdir(parents=True, exist_ok=True) + config_logger.debug("Writing Config File") + with path_obj.open("wb") as f: + tomli_w.dump(config_data, f) def close(self) -> None: - """ - Close this config and release any associated resources. - - Implements :meth:`AbstractConfig.close`. - """ - self.save() + """Release resources (stub).""" self.config = None + + +def linux_helper(config: Config) -> Config: + """Set Environment Specific Variables for Linux Config.""" + config_logger.debug("Linux environment detected. Setting platform-specific variables.") + config.respath_path = pathlib.Path(__file__).parent.parent + config.internal_plugin_dir_path = config.respath_path / "plugins" + config.default_journal_dir_path = None # type: ignore + if (outdir := config.get_str("outdir")) is None or not pathlib.Path( + outdir + ).is_dir(): + config.set("outdir", config.home) + return config diff --git a/config/windows.py b/config/windows.py index 96d073c1..11875b66 100644 --- a/config/windows.py +++ b/config/windows.py @@ -5,21 +5,23 @@ Copyright (c) EDCD, All Rights Reserved Licensed under the GNU General Public License. See LICENSE file. """ + from __future__ import annotations -import functools import pathlib import sys import uuid import winreg import datetime import tomli_w -import base64 -from typing import Literal, Any -from config import AbstractConfig, applongname, appname, logger +from config import config_logger from win32comext.shell import shell +from typing import Any, TYPE_CHECKING -if sys.platform != 'win32': +if TYPE_CHECKING: + from . import Config + +if sys.platform != "win32": raise EnvironmentError("This file is for Windows only.") REG_RESERVED_ALWAYS_ZERO = 0 @@ -30,254 +32,84 @@ def known_folder_path(guid: uuid.UUID) -> str | None: return shell.SHGetKnownFolderPath(guid, 0, 0) -class WinConfig(AbstractConfig): - """Implementation of AbstractConfig for Windows.""" +class WinConfigMinimal: + """Minimal Windows config for exporting registry values to TOML.""" + + REGISTRY_SUBKEY = r"Software\Marginal\EDMarketConnector" def __init__(self) -> None: - super().__init__() - - self.REGISTRY_SUBKEY = r'Software\Marginal\EDMarketConnector' - create_key_defaults = functools.partial( - winreg.CreateKeyEx, - key=winreg.HKEY_CURRENT_USER, + # Open or create the registry key + self.__reg_handle = winreg.CreateKeyEx( + winreg.HKEY_CURRENT_USER, + self.REGISTRY_SUBKEY, access=winreg.KEY_ALL_ACCESS | winreg.KEY_WOW64_64KEY, ) - try: - self.__reg_handle: winreg.HKEYType = create_key_defaults(sub_key=self.REGISTRY_SUBKEY) - - except OSError: - logger.exception('Could not create required registry keys') - raise - - if local_appdata := known_folder_path(shell.FOLDERID_LocalAppData): - self.app_dir_path = pathlib.Path(local_appdata) / appname - self.app_dir_path.mkdir(exist_ok=True) - - self.default_plugin_dir_path = self.app_dir_path / 'plugins' - if (plugdir_str := self.get_str('plugin_dir')) is None or not pathlib.Path(plugdir_str).is_dir(): - self.set("plugin_dir", str(self.default_plugin_dir_path)) - plugdir_str = self.default_plugin_dir - self.plugin_dir_path = pathlib.Path(plugdir_str) - self.plugin_dir_path.mkdir(exist_ok=True) - - if getattr(sys, 'frozen', False): - self.respath_path = pathlib.Path(sys.executable).parent - self.internal_plugin_dir_path = self.respath_path / 'plugins' - else: - self.respath_path = pathlib.Path(__file__).parent.parent - self.internal_plugin_dir_path = self.respath_path / 'plugins' - - self.home_path = pathlib.Path.home() - - journal_dir_path = pathlib.Path( - known_folder_path(shell.FOLDERID_SavedGames)) / 'Frontier Developments' / 'Elite Dangerous' # type: ignore - self.default_journal_dir_path = journal_dir_path if journal_dir_path.is_dir() else None # type: ignore - - self.identifier = applongname - if (outdir_str := self.get_str('outdir')) is None or not pathlib.Path(outdir_str).is_dir(): - docs = known_folder_path(shell.FOLDERID_Documents) - self.set("outdir", docs if docs is not None else self.home) - - def _convert_reg_value_for_toml(self, data, data_type): - """Convert Windows registry values into TOML-native types for 6.0's global config.""" - # Plain string + def _convert_reg_value_for_toml(self, data, data_type) -> Any: + """Convert Windows registry values into TOML-native types.""" if data_type == winreg.REG_SZ: return str(data) - - # Expandable string: keep as string if data_type == winreg.REG_EXPAND_SZ: try: - expanded = winreg.ExpandEnvironmentStrings(data) + return str(winreg.ExpandEnvironmentStrings(data)) except Exception: - expanded = data - return str(expanded) - - # DWORD or QWORD: store as integer + return str(data) if data_type in (winreg.REG_DWORD, winreg.REG_QWORD): return int(data) - - # Multi-string: store as list if data_type == winreg.REG_MULTI_SZ: return list(data) - - # Binary: store as base64 string - if data_type == winreg.REG_BINARY: - return base64.b64encode(data).decode("ascii") - - # Else, force to string + # Fallback: force to string return str(data) - def write_registry_to_toml(self, toml_path: str) -> None: - """ - Export all registry values under self.REGISTRY_SUBKEY into a global TOML config. - - Values are normalized into TOML-native types (str, int, list, base64). - Booleans are left as ints (0/1) and should be interpreted adaptively by get_bool. - """ + def write_to_toml(self, toml_path: str) -> None: + """Export all registry values under REGISTRY_SUBKEY to TOML.""" + config_logger.debug("Generating New Config File") key = self.__reg_handle + _, num_values, _ = winreg.QueryInfoKey(key) - try: - _, num_values, _ = winreg.QueryInfoKey(key) + config_data: dict[str, Any] = { + "generated": datetime.datetime.now(datetime.timezone.utc).isoformat(), + "source": "windows_registry", + "settings": {}, + } - # Write config, including writing where and when we got this from. - config_data: dict[str, Any] = { - "generated": datetime.datetime.now(datetime.timezone.utc).isoformat(), - "source": "windows_registry", - "subkey": self.REGISTRY_SUBKEY, - "settings": {} - } + for i in range(num_values): + name, data, data_type = winreg.EnumValue(key, i) + config_data["settings"][name] = self._convert_reg_value_for_toml( + data, data_type + ) - settings = config_data["settings"] - - for i in range(num_values): - name, data, data_type = winreg.EnumValue(key, i) - settings[name] = self._convert_reg_value_for_toml(data, data_type) - - # Write TOML to file - path_obj = pathlib.Path(toml_path) - path_obj.parent.mkdir(parents=True, exist_ok=True) - with path_obj.open("wb") as f: - tomli_w.dump(config_data, f) - - logger.info(f"Registry exported to TOML: {toml_path}") - - except OSError: - logger.exception(f"Could not export registry key {self.REGISTRY_SUBKEY}") - raise - - def __get_regentry(self, key: str) -> None | list | str | int: - """Access the Registry for the raw entry.""" - try: - value, _type = winreg.QueryValueEx(self.__reg_handle, key) - except FileNotFoundError: - # Key doesn't exist - return None - - # For programmers who want to actually know what is going on - if _type == winreg.REG_SZ: - return str(value) - - if _type == winreg.REG_DWORD: - return int(value) - - if _type == winreg.REG_MULTI_SZ: - return list(value) - - logger.warning(f'Registry key {key=} returned unknown type {_type=} {value=}') - return None - - def get_str(self, key: str, *, default: str | None = None) -> str: - """ - Return the string referred to by the given key if it exists, or the default. - - Implements :meth:`AbstractConfig.get_str`. - """ - res = self.__get_regentry(key) - if res is None: - return default # type: ignore # Yes it could be None, but we're _assuming_ that people gave us a default - - if not isinstance(res, str): - raise ValueError(f'Data from registry is not a string: {type(res)=} {res=}') - - return res - - def get_list(self, key: str, *, default: list | None = None) -> list: - """ - Return the list referred to by the given key if it exists, or the default. - - Implements :meth:`AbstractConfig.get_list`. - """ - res = self.__get_regentry(key) - if res is None: - return default # type: ignore # Yes it could be None, but we're _assuming_ that people gave us a default - - if not isinstance(res, list): - raise ValueError(f'Data from registry is not a list: {type(res)=} {res}') - - return res - - def get_int(self, key: str, *, default: int = 0) -> int: - """ - Return the int referred to by key if it exists in the config. - - Implements :meth:`AbstractConfig.get_int`. - """ - res = self.__get_regentry(key) - if res is None: - return default - - if not isinstance(res, int): - raise ValueError(f'Data from registry is not an int: {type(res)=} {res}') - - return res - - def get_bool(self, key: str, *, default: bool | None = None) -> bool: - """ - Return the bool referred to by the given key if it exists, or the default. - - Implements :meth:`AbstractConfig.get_bool`. - """ - res = self.get_int(key, default=default) # type: ignore - if res is None: - return default # Yes it could be None, but we're _assuming_ that people gave us a default - - return bool(res) - - def set(self, key: str, val: int | str | list[str] | bool) -> None: - """ - Set the given key's data to the given value. - - Implements :meth:`AbstractConfig.set`. - """ - # These are the types that winreg.REG_* below resolve to. - reg_type: Literal[1] | Literal[4] | Literal[7] - if isinstance(val, str): - reg_type = winreg.REG_SZ - - elif isinstance(val, int): - reg_type = winreg.REG_DWORD - - elif isinstance(val, list): - reg_type = winreg.REG_MULTI_SZ - - elif isinstance(val, bool): - reg_type = winreg.REG_DWORD - val = int(val) - - else: - raise ValueError(f'Unexpected type for value {type(val)=}') - - winreg.SetValueEx(self.__reg_handle, key, REG_RESERVED_ALWAYS_ZERO, reg_type, val) # type: ignore - - def delete(self, key: str, *, suppress=False) -> None: - """ - Delete the given key from the config. - - 'key' is relative to the base Registry path we use. - - Implements :meth:`AbstractConfig.delete`. - """ - try: - winreg.DeleteValue(self.__reg_handle, key) - except OSError: - if suppress: - return - - raise - - def save(self) -> None: - """ - Save the configuration. - - Not required for WinConfig as Registry keys are flushed on write. - """ - pass + path_obj = pathlib.Path(toml_path) + path_obj.parent.mkdir(parents=True, exist_ok=True) + config_logger.debug("Writing Config File") + with path_obj.open("wb") as f: + tomli_w.dump(config_data, f) def close(self): - """ - Close this config and release any associated resources. - - Implements :meth:`AbstractConfig.close`. - """ + """Close registry handle.""" self.__reg_handle.Close() + + +def win_helper(config: Config) -> Config: + """Set Environment Specific Variables for Windows Config.""" + config_logger.debug("Windows environment detected. Setting platform-specific variables.") + if getattr(sys, "frozen", False): + config.respath_path = pathlib.Path(sys.executable).parent + config.internal_plugin_dir_path = config.respath_path / "plugins" + else: + config.respath_path = pathlib.Path(__file__).parent.parent + config.internal_plugin_dir_path = config.respath_path / "plugins" + + journal_dir_path = ( + pathlib.Path(known_folder_path(shell.FOLDERID_SavedGames)) # type: ignore + / "Frontier Developments" + / "Elite Dangerous" + ) + config.default_journal_dir_path = journal_dir_path if journal_dir_path.is_dir() else None # type: ignore + + if (outdir_str := config.get_str("outdir")) is None or not pathlib.Path( + outdir_str + ).is_dir(): + docs = known_folder_path(shell.FOLDERID_Documents) + config.set("outdir", docs if docs is not None else config.home) + return config diff --git a/requirements.txt b/requirements.txt index 10b4ac67..32001a17 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,3 +6,4 @@ semantic-version==2.10.0 # For manipulating folder permissions and the like. pywin32==311; sys_platform == 'win32' psutil==7.1.3 +tomli-w==1.2.0 From 52b5c194807ee2b3c404b34e3d0a1d4a4e33aa51 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Sun, 16 Nov 2025 19:09:42 -0500 Subject: [PATCH 37/84] [Minor] Whitespace Stuff --- config/linux.py | 1 - config/windows.py | 1 - 2 files changed, 2 deletions(-) diff --git a/config/linux.py b/config/linux.py index 9260cd74..6ac36bc6 100644 --- a/config/linux.py +++ b/config/linux.py @@ -5,7 +5,6 @@ Copyright (c) EDCD, All Rights Reserved Licensed under the GNU General Public License. See LICENSE file. """ - from __future__ import annotations import os diff --git a/config/windows.py b/config/windows.py index 11875b66..691b4f7a 100644 --- a/config/windows.py +++ b/config/windows.py @@ -5,7 +5,6 @@ Copyright (c) EDCD, All Rights Reserved Licensed under the GNU General Public License. See LICENSE file. """ - from __future__ import annotations import pathlib From fa0ec91b8f00d2915859eb1d13ce56d06111a01d Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Sun, 16 Nov 2025 20:54:54 -0500 Subject: [PATCH 38/84] [517] Don't Die If Nothing to Convert --- config/__init__.py | 46 +++++++++++++++++++++++++++++++--------------- config/linux.py | 10 +++------- config/windows.py | 10 +++++++++- 3 files changed, 43 insertions(+), 23 deletions(-) diff --git a/config/__init__.py b/config/__init__.py index e7505f1e..cf01e91c 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -218,9 +218,12 @@ class Config: self.settings: dict[str, Any] = {} self._load() self.default_plugin_dir_path = self.app_dir_path / "plugins" - if (plugdir_str := self.get_str("plugin_dir")) is None or not pathlib.Path( - plugdir_str - ).is_dir(): + plugdir_str = self.get_str("plugin_dir") + if not self.get_str("plugin_dir"): + plugdir_str = str(self.default_plugin_dir) + self.plugin_dir_path = self.default_plugin_dir_path + self.set("plugin_dir", plugdir_str) + if plugdir_str is None or not pathlib.Path(plugdir_str).is_dir(): self.set("plugin_dir", str(self.default_plugin_dir_path)) plugdir_str = self.default_plugin_dir self.plugin_dir_path = pathlib.Path(plugdir_str) @@ -246,22 +249,30 @@ class Config: self.__in_shutdown = True def _load(self): - """Load TOML from disk and store fields.""" + """Load TOML from disk and store fields. Create file if missing.""" if not self.toml_path.exists(): - raise FileNotFoundError(f"Config file not found: {self.toml_path}") + # Ensure parent directories exist + self.toml_path.parent.mkdir(parents=True, exist_ok=True) + # Replace None with TOML-serializable defaults + default_data = { + "generated": "", # empty string instead of None + "source": "", # empty string instead of None + "settings": {} # empty table + } + with self.toml_path.open("wb") as f: + tomli_w.dump(default_data, f) + + # Load the TOML file with self.toml_path.open("rb") as f: data = tomllib.load(f) - # Capture metadata - self.generated = data.get("generated") - self.source = data.get("source") + # Capture metadata, fallback to empty string if missing + self.generated = data.get("generated", "") + self.source = data.get("source", "") # Settings dict created by write_registry_to_toml() - raw_settings = data.get("settings", {}) - self.settings = {} - - self.settings = dict(raw_settings) + self.settings = dict(data.get("settings", {})) def get(self, key: str, default=None): """Return raw stored value.""" @@ -503,12 +514,17 @@ def get_config(*args, **kwargs) -> Config: if sys.platform == "win32": # pragma: sys-platform-win32 from .windows import WinConfigMinimal - - config = WinConfigMinimal() + try: + config = WinConfigMinimal() + except FileNotFoundError: + return Config(app_path=app_dir_path) # Nothing to Convert if sys.platform == "linux": # pragma: sys-platform-linux from .linux import LinuxConfigMinimal - config = LinuxConfigMinimal() + try: + config = LinuxConfigMinimal() + except FileNotFoundError: + return Config(app_path=app_dir_path) # Nothing to Convert if config: config.write_to_toml(f"{app_dir_path}/config.toml") # type: ignore diff --git a/config/linux.py b/config/linux.py index 6ac36bc6..394b3e4e 100644 --- a/config/linux.py +++ b/config/linux.py @@ -26,7 +26,7 @@ if TYPE_CHECKING: class LinuxConfigMinimal: - """Minimal Linux config loader that dumps existing config to TOML.""" + """Minimal Linux config for exporting pre-6.0 config values to TOML.""" SECTION = "config" @@ -40,16 +40,12 @@ class LinuxConfigMinimal: if filename else xdg_config_home / "EDMarketConnector" / "EDMarketConnector.ini" ) - self.filename.parent.mkdir(exist_ok=True, parents=True) - + if not pathlib.Path(filename).exists(): + raise FileNotFoundError # Load INI self.config = ConfigParser(interpolation=None) self.config.read(self.filename) - # Ensure section exists - if self.SECTION not in self.config: - self.config.add_section(self.SECTION) - def _get_settings_dict(self) -> dict[str, Any]: """Return all keys/values from SECTION as a dict of strings.""" return { diff --git a/config/windows.py b/config/windows.py index 691b4f7a..6789bc4e 100644 --- a/config/windows.py +++ b/config/windows.py @@ -32,11 +32,19 @@ def known_folder_path(guid: uuid.UUID) -> str | None: class WinConfigMinimal: - """Minimal Windows config for exporting registry values to TOML.""" + """Minimal Windows config for exporting pre-6.0 config values to TOML.""" REGISTRY_SUBKEY = r"Software\Marginal\EDMarketConnector" def __init__(self) -> None: + # Try to open the key with read access + with winreg.OpenKey( + winreg.HKEY_CURRENT_USER, + self.REGISTRY_SUBKEY, + 0, + winreg.KEY_READ | winreg.KEY_WOW64_64KEY + ): + pass # If this fails, key doesn't exist, nothing to convert # Open or create the registry key self.__reg_handle = winreg.CreateKeyEx( winreg.HKEY_CURRENT_USER, From 16212e154b5fdead833334c471a735cefb4b78be Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Sun, 16 Nov 2025 21:46:36 -0500 Subject: [PATCH 39/84] [517] Set Logging Handler and Remove Old Tests --- config/__init__.py | 2 +- tests/config/test_config.py | 98 ------------------------------------- 2 files changed, 1 insertion(+), 99 deletions(-) diff --git a/config/__init__.py b/config/__init__.py index cf01e91c..c1a45a5b 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -537,7 +537,7 @@ def get_config(*args, **kwargs) -> Config: config_logger = logging.getLogger("pre_config") config_logger.setLevel(logging.DEBUG) # Or INFO -ch = logging.StreamHandler() +ch = logging.StreamHandler(sys.stdout) ch.setLevel(logging.DEBUG) formatter = logging.Formatter("%(asctime)s [%(levelname)s] %(message)s") formatter.converter = gmtime # Optional: match your main logger's UTC timestamps diff --git a/tests/config/test_config.py b/tests/config/test_config.py index cf48acad..32c05ca4 100644 --- a/tests/config/test_config.py +++ b/tests/config/test_config.py @@ -7,7 +7,6 @@ key deletions. Said modifications are to keys that are generated internally. Most of these tests are parity tests with the "old" config, and likely one day can be entirely removed. """ -import contextlib import itertools import pathlib import random @@ -23,8 +22,6 @@ from pytest import mark sys.path += [str(pathlib.Path(__file__).parent.parent.resolve()), "."] print(sys.path) -from _old_config import old_config # noqa: E402 - from config import config # noqa: E402 @@ -148,98 +145,3 @@ class TestNewConfig: assert res == '1337' config.delete(name) config.save() - - -class TestOldNewConfig: - """Tests going through the old config and out the new config.""" - - KEY_PREFIX = 'oldnew_' - - def teardown_method(self) -> None: - """ - Teardown for all config tests to save out configs. - - It is expected that tests have cleaned up whatever keys they have aded. - This is here to ensure that a save out happens for configs that need it. - """ - old_config.save() - config.save() - - def cleanup_entry(self, entry: str) -> None: - """Remove the given key, on both sides if on linux.""" - config.delete(entry) - if sys.platform == 'linux': - old_config.delete(entry) - - def __update_linuxconfig(self) -> None: - """On linux config uses ConfigParser, which doesn't update from disk changes. Force the update here.""" - if sys.platform != 'linux': - return - - from config.linux import LinuxConfig # type: ignore - if isinstance(config, LinuxConfig) and config.config is not None: - config.config.read(config.filename) - - @mark.parametrize("i", _build_test_list(int_tests, _get_fuzz(int, 50, (-big_int, big_int)))) - def test_int(self, i: int) -> None: - """Save an int though the old config, recall it using the new config.""" - if sys.platform == 'win32': - i = abs(i) - - name = self.KEY_PREFIX + f'int_{i}' - old_config.set(name, i) - old_config.save() - - self.__update_linuxconfig() - - res = config.get_int(name) - with contextlib.ExitStack() as stack: - stack.callback(self.cleanup_entry, name) - assert res == i - - @mark.parametrize("string", _build_test_list(string_tests, _get_fuzz(str, value_length=(0, 512)))) - def test_string(self, string: str) -> None: - """Save a string though the old config, recall it using the new config.""" - string = string.replace("\r", "") # The old config does _not_ support \r in its entries. We do. - name = self.KEY_PREFIX + f'string_{hash(string)}' - old_config.set(name, string) - old_config.save() - - self.__update_linuxconfig() - - res = config.get_str(name) - with contextlib.ExitStack() as stack: - stack.callback(self.cleanup_entry, name) - assert res == string - - @mark.parametrize("lst", _build_test_list(list_tests, _get_fuzz(list))) - def test_list(self, lst: list[str]) -> None: - """Save a list though the old config, recall it using the new config.""" - lst = [x.replace("\r", "") for x in lst] # OldConfig on linux fails to store these correctly - if sys.platform == 'win32': - # old conf on windows replaces empty entries with spaces as a workaround for a bug. New conf does not - # So insert those spaces here, to ensure that it works otherwise. - lst = [e if len(e) > 0 else ' ' for e in lst] - - name = self.KEY_PREFIX + f'list_test_{hash("".join(lst))}' - old_config.set(name, lst) - old_config.save() - - self.__update_linuxconfig() - - res = config.get_list(name) - with contextlib.ExitStack() as stack: - stack.callback(self.cleanup_entry, name) - assert res == lst - - @mark.skipif(sys.platform == 'win32', reason="Old Windows config does not support bool types") - @mark.parametrize("b", bool_tests) - def test_bool(self, b: bool) -> None: - """Save a bool though the old config, recall it using the new config.""" - name = str(b) - old_config.set(name, b) - old_config.save() - self.__update_linuxconfig() - with contextlib.ExitStack() as stack: - stack.callback(self.cleanup_entry, name) - assert config.get_bool(name) == b From 13eb8b375ca42bdaded9344ce8479bf918799a00 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Sun, 16 Nov 2025 21:55:02 -0500 Subject: [PATCH 40/84] [512] Remove Old Tests These don't apply... because the config they were written for no longer exists. --- tests/config/_old_config.py | 392 ------------------------------------ tests/config/test_config.py | 147 -------------- 2 files changed, 539 deletions(-) delete mode 100644 tests/config/_old_config.py delete mode 100644 tests/config/test_config.py diff --git a/tests/config/_old_config.py b/tests/config/_old_config.py deleted file mode 100644 index dea1f2b3..00000000 --- a/tests/config/_old_config.py +++ /dev/null @@ -1,392 +0,0 @@ -"""Old Configuration Test File.""" -from __future__ import annotations - -import numbers -import sys -from configparser import NoOptionError -from os import getenv, makedirs, mkdir -from os.path import dirname, expanduser, isdir, join -from typing import TYPE_CHECKING -from config import applongname, appname, update_interval -from EDMCLogging import get_main_logger - -logger = get_main_logger() - -if sys.platform == 'win32': - import ctypes - import uuid - from ctypes.wintypes import DWORD, HANDLE, HKEY, LONG, LPCVOID, LPCWSTR - if TYPE_CHECKING: - import ctypes.windll # type: ignore - - FOLDERID_Documents = uuid.UUID('{FDD39AD0-238F-46AF-ADB4-6C85480369C7}') - FOLDERID_LocalAppData = uuid.UUID('{F1B32785-6FBA-4FCF-9D55-7B8E7F157091}') - FOLDERID_Profile = uuid.UUID('{5E6C858F-0E22-4760-9AFE-EA3317B67173}') - FOLDERID_SavedGames = uuid.UUID('{4C5C32FF-BB9D-43b0-B5B4-2D72E54EAAA4}') - - SHGetKnownFolderPath = ctypes.windll.shell32.SHGetKnownFolderPath - SHGetKnownFolderPath.argtypes = [ctypes.c_char_p, DWORD, HANDLE, ctypes.POINTER(ctypes.c_wchar_p)] - - CoTaskMemFree = ctypes.windll.ole32.CoTaskMemFree - CoTaskMemFree.argtypes = [ctypes.c_void_p] - - # winreg in Python <= 3.7.4 handles REG_MULTI_SZ incorrectly, so do this instead. https://bugs.python.org/issue32587 - HKEY_CURRENT_USER = 0x80000001 - KEY_ALL_ACCESS = 0x000F003F - REG_CREATED_NEW_KEY = 0x00000001 - REG_OPENED_EXISTING_KEY = 0x00000002 - REG_SZ = 1 - REG_DWORD = 4 - REG_MULTI_SZ = 7 - - REG_RESERVED_ALWAYS_ZERO = 0 - - RegCreateKeyEx = ctypes.windll.advapi32.RegCreateKeyExW - RegCreateKeyEx.restype = LONG - RegCreateKeyEx.argtypes = [ - HKEY, LPCWSTR, DWORD, LPCVOID, DWORD, DWORD, LPCVOID, ctypes.POINTER(HKEY), ctypes.POINTER(DWORD) - ] - - RegOpenKeyEx = ctypes.windll.advapi32.RegOpenKeyExW - RegOpenKeyEx.restype = LONG - RegOpenKeyEx.argtypes = [HKEY, LPCWSTR, DWORD, DWORD, ctypes.POINTER(HKEY)] - - RegCloseKey = ctypes.windll.advapi32.RegCloseKey - RegCloseKey.restype = LONG - RegCloseKey.argtypes = [HKEY] - - RegQueryValueEx = ctypes.windll.advapi32.RegQueryValueExW - RegQueryValueEx.restype = LONG - RegQueryValueEx.argtypes = [HKEY, LPCWSTR, LPCVOID, ctypes.POINTER(DWORD), LPCVOID, ctypes.POINTER(DWORD)] - - RegSetValueEx = ctypes.windll.advapi32.RegSetValueExW - RegSetValueEx.restype = LONG - RegSetValueEx.argtypes = [HKEY, LPCWSTR, LPCVOID, DWORD, LPCVOID, DWORD] - - RegCopyTree = ctypes.windll.advapi32.RegCopyTreeW - RegCopyTree.restype = LONG - RegCopyTree.argtypes = [HKEY, LPCWSTR, HKEY] - - RegDeleteKey = ctypes.windll.advapi32.RegDeleteTreeW - RegDeleteKey.restype = LONG - RegDeleteKey.argtypes = [HKEY, LPCWSTR] - - RegDeleteValue = ctypes.windll.advapi32.RegDeleteValueW - RegDeleteValue.restype = LONG - RegDeleteValue.argtypes = [HKEY, LPCWSTR] - - def known_folder_path(guid: uuid.UUID) -> str | None: - """Look up a Windows GUID to actual folder path name.""" - buf = ctypes.c_wchar_p() - if SHGetKnownFolderPath(ctypes.create_string_buffer(guid.bytes_le), 0, 0, ctypes.byref(buf)): - return None - retval = buf.value # copy data - CoTaskMemFree(buf) # and free original - return retval - -elif sys.platform == 'linux': - import codecs - from configparser import RawConfigParser - - -class OldConfig: - """Object that holds all configuration data.""" - - OUT_EDDN_SEND_STATION_DATA = 1 - # OUT_MKT_BPC = 2 # No longer supported - OUT_MKT_TD = 4 - OUT_MKT_CSV = 8 - OUT_SHIP = 16 - # OUT_SHIP_EDS = 16 # Replaced by OUT_SHIP - # OUT_SYS_FILE = 32 # No longer supported - # OUT_STAT = 64 # No longer available - # OUT_SHIP_CORIOLIS = 128 # Replaced by OUT_SHIP - # OUT_SYS_EDSM = 256 # Now a plugin - # OUT_SYS_AUTO = 512 # Now always automatic - OUT_MKT_MANUAL = 1024 - OUT_EDDN_SEND_NON_STATION = 2048 - OUT_EDDN_DELAY = 4096 - OUT_STATION_ANY = OUT_EDDN_SEND_STATION_DATA | OUT_MKT_TD | OUT_MKT_CSV - - if sys.platform == 'win32': # noqa: C901 - - def __init__(self): - self.app_dir = join(known_folder_path(FOLDERID_LocalAppData), appname) # type: ignore - if not isdir(self.app_dir): - mkdir(self.app_dir) - - self.plugin_dir = join(self.app_dir, 'plugins') - if not isdir(self.plugin_dir): - mkdir(self.plugin_dir) - - if getattr(sys, 'frozen', False): - self.internal_plugin_dir = join(dirname(sys.executable), 'plugins') - self.respath = dirname(sys.executable) - - else: - self.internal_plugin_dir = join(dirname(__file__), 'plugins') - self.respath = dirname(__file__) - - # expanduser in Python 2 on Windows doesn't handle non-ASCII - http://bugs.python.org/issue13207 - self.home = known_folder_path(FOLDERID_Profile) or r'\\' - - journaldir = known_folder_path(FOLDERID_SavedGames) - if journaldir: - self.default_journal_dir: str | None = join(journaldir, 'Frontier Developments', 'Elite Dangerous') - - else: - self.default_journal_dir = None - - self.identifier = applongname - self.hkey: ctypes.c_void_p | None = HKEY() - disposition = DWORD() - if RegCreateKeyEx( - HKEY_CURRENT_USER, - r'Software\Marginal\EDMarketConnector', - 0, - None, - 0, - KEY_ALL_ACCESS, - None, - ctypes.byref(self.hkey), - ctypes.byref(disposition) - ): - raise Exception() - - # set WinSparkle defaults - https://github.com/vslavik/winsparkle/wiki/Registry-Settings - edcdhkey = HKEY() - if RegCreateKeyEx( - HKEY_CURRENT_USER, - r'Software\EDCD\EDMarketConnector', - 0, - None, - 0, - KEY_ALL_ACCESS, - None, - ctypes.byref(edcdhkey), - ctypes.byref(disposition) - ): - raise Exception() - - sparklekey = HKEY() - if not RegCreateKeyEx( - edcdhkey, - 'WinSparkle', - 0, - None, - 0, - KEY_ALL_ACCESS, - None, - ctypes.byref(sparklekey), - ctypes.byref(disposition) - ): - if disposition.value == REG_CREATED_NEW_KEY: - buf = ctypes.create_unicode_buffer('1') - RegSetValueEx(sparklekey, 'CheckForUpdates', 0, 1, buf, len(buf) * 2) - - buf = ctypes.create_unicode_buffer(str(update_interval)) - RegSetValueEx(sparklekey, 'UpdateInterval', 0, 1, buf, len(buf) * 2) - RegCloseKey(sparklekey) - - if not self.get('outdir') or not isdir(self.get('outdir')): # type: ignore - self.set('outdir', known_folder_path(FOLDERID_Documents) or self.home) - - def get(self, key: str, default: None | list | str = None) -> None | list | str: - """Look up a string configuration value.""" - key_type = DWORD() - key_size = DWORD() - # Only strings are handled here. - if ( - RegQueryValueEx( - self.hkey, - key, - 0, - ctypes.byref(key_type), - None, - ctypes.byref(key_size) - ) - or key_type.value not in (REG_SZ, REG_MULTI_SZ) - ): - return default - - buf = ctypes.create_unicode_buffer(int(key_size.value / 2)) - if RegQueryValueEx(self.hkey, key, 0, ctypes.byref(key_type), buf, ctypes.byref(key_size)): - return default - - if key_type.value == REG_MULTI_SZ: - return list(ctypes.wstring_at(buf, len(buf)-2).split('\x00')) - - return str(buf.value) - - def getint(self, key: str, default: int = 0) -> int: - """Look up an integer configuration value.""" - key_type = DWORD() - key_size = DWORD(4) - key_val = DWORD() - if ( - RegQueryValueEx( - self.hkey, - key, - 0, - ctypes.byref(key_type), - ctypes.byref(key_val), - ctypes.byref(key_size) - ) - or key_type.value != REG_DWORD - ): - return default - - return key_val.value - - def set(self, key: str, val: int | str | list) -> None: - """Set value on the specified configuration key.""" - if isinstance(val, str): - buf = ctypes.create_unicode_buffer(val) - RegSetValueEx(self.hkey, key, 0, REG_SZ, buf, len(buf)*2) - - elif isinstance(val, numbers.Integral): - RegSetValueEx(self.hkey, key, 0, REG_DWORD, ctypes.byref(DWORD(val)), 4) - - elif isinstance(val, list): - # null terminated non-empty strings - string_val = '\x00'.join([str(x) or ' ' for x in val] + ['']) - buf = ctypes.create_unicode_buffer(string_val) - RegSetValueEx(self.hkey, key, 0, REG_MULTI_SZ, buf, len(buf)*2) - - else: - raise NotImplementedError() - - def delete(self, key: str) -> None: - """Delete the specified configuration key.""" - RegDeleteValue(self.hkey, key) - - def save(self) -> None: - """Save current configuration to disk.""" - pass # Redundant since registry keys are written immediately - - def close(self) -> None: - """Close the configuration.""" - RegCloseKey(self.hkey) - self.hkey = None - - elif sys.platform == 'linux': - SECTION = 'config' - - def __init__(self): - - # http://standards.freedesktop.org/basedir-spec/latest/ar01s03.html - self.app_dir = join(getenv('XDG_DATA_HOME', expanduser('~/.local/share')), appname) - if not isdir(self.app_dir): - makedirs(self.app_dir) - - self.plugin_dir = join(self.app_dir, 'plugins') - if not isdir(self.plugin_dir): - mkdir(self.plugin_dir) - - self.internal_plugin_dir = join(dirname(__file__), 'plugins') - self.default_journal_dir: str | None = None - self.home = expanduser('~') - self.respath = dirname(__file__) - self.identifier = f'uk.org.marginal.{appname.lower()}' - - self.filename = join(getenv('XDG_CONFIG_HOME', expanduser('~/.config')), appname, f'{appname}.ini') - if not isdir(dirname(self.filename)): - makedirs(dirname(self.filename)) - - self.config = RawConfigParser(comment_prefixes=('#',)) - try: - with codecs.open(self.filename) as h: - self.config.read_file(h) - - except Exception as e: - logger.debug('Reading config failed, assuming we\'re making a new one...', exc_info=e) - self.config.add_section(self.SECTION) - - if not self.get('outdir') or not isdir(self.get('outdir')): # type: ignore # Not going to change - self.set('outdir', expanduser('~')) - - def get(self, key: str, default: None | list | str = None) -> None | list | str: - """Look up a string configuration value.""" - try: - val = self.config.get(self.SECTION, key) - if '\n' in val: # list - # ConfigParser drops the last entry if blank, - # so we add a spurious ';' entry in set() and remove it here - assert val.split('\n')[-1] == ';', val.split('\n') - return [self._unescape(x) for x in val.split('\n')[:-1]] - return self._unescape(val) - - except NoOptionError: - logger.debug(f'attempted to get key {key} that does not exist') - return default - - except Exception as e: - logger.debug('And the exception type is...', exc_info=e) - return default - - def getint(self, key: str, default: int = 0) -> int: - """Look up an integer configuration value.""" - try: - return self.config.getint(self.SECTION, key) - - except ValueError as e: - logger.error(f"Failed to int({key=})", exc_info=e) - - except NoOptionError: - logger.debug(f'attempted to get key {key} that does not exist') - - except Exception: - logger.exception(f'unexpected exception while attempting to access {key}') - - return default - - def set(self, key: str, val: int | str | list) -> None: - """Set value on the specified configuration key.""" - if isinstance(val, bool): - self.config.set(self.SECTION, key, val and '1' or '0') - - elif isinstance(val, (numbers.Integral, str)): - self.config.set(self.SECTION, key, self._escape(val)) - - elif isinstance(val, list): - self.config.set(self.SECTION, key, '\n'.join([self._escape(x) for x in val] + [';'])) - - else: - raise NotImplementedError() - - def delete(self, key: str) -> None: - """Delete the specified configuration key.""" - self.config.remove_option(self.SECTION, key) - - def save(self) -> None: - """Save current configuration to disk.""" - with codecs.open(self.filename, 'w', 'utf-8') as h: - self.config.write(h) - - def close(self) -> None: - """Close the configuration.""" - self.save() - self.config = None # type: ignore - - def _escape(self, val: str) -> str: - """Escape a string for storage.""" - return str(val).replace('\\', '\\\\').replace('\n', '\\n').replace(';', '\\;') - - def _unescape(self, val: str) -> str: - """Un-escape a string from storage.""" - chars = list(val) - i = 0 - while i < len(chars): - if chars[i] == '\\': - chars.pop(i) - if chars[i] == 'n': - chars[i] = '\n' - i += 1 - return ''.join(chars) - - else: - def __init__(self): - raise NotImplementedError('Implement me') - - -old_config = OldConfig() diff --git a/tests/config/test_config.py b/tests/config/test_config.py deleted file mode 100644 index 32c05ca4..00000000 --- a/tests/config/test_config.py +++ /dev/null @@ -1,147 +0,0 @@ -""" -Test the config system. - -Note: These tests to arbitrary reads and writes to an existing config, including -key deletions. Said modifications are to keys that are generated internally. - -Most of these tests are parity tests with the "old" config, and likely one day can be -entirely removed. -""" -import itertools -import pathlib -import random -import string -import sys -from typing import Any, Iterable, cast - -import pytest -from pytest import mark - -# isort: split - -sys.path += [str(pathlib.Path(__file__).parent.parent.resolve()), "."] -print(sys.path) - -from config import config # noqa: E402 - - -def _fuzz_list(length: int) -> list[str]: - out = [] - for _ in range(length): - out.append(_fuzz_generators[str](random.randint(0, 1337))) - - return cast(list[str], out) - - -_fuzz_generators = { # Type annotating this would be a nightmare. - int: lambda i: random.randint(min(0, i), max(0, i)), - # This doesn't cover unicode, or random bytes. Use them at your own peril - str: lambda s: "".join(random.choice(string.ascii_letters + string.digits + '\r\n') for _ in range(s)), - bool: lambda _: bool(random.choice((True, False))), - list: _fuzz_list, -} - - -def _get_fuzz(_type: Any, num_values=50, value_length=(0, 10)) -> list: - return [_fuzz_generators[_type](random.randint(*value_length)) for _ in range(num_values)] - - -int_tests = [0, 1, 2, 3, (1 << 32)-1, -1337] - -string_tests = [ - "test", "", "this\nis\na\ntest", "orange sidewinder", "needs \\ more backslashes\\", "\\; \\n", r"\\\\ \\\\; \\\\n", - r"entry with escapes \\ \\; \\n" -] - -list_tests = [ - ["test"], - ["multiple", "entries"], - ["multiple", "entries", "with", "", "blanks"], - ["entry", "that ends", "in a", ""], - ["entry with \n", "newlines\nin", "weird\nplaces"], - [r"entry with escapes \\ \\; \\n"], - [r"\\\\ \\\\; \\\\n"] -] -bool_tests = [True, False] - -big_int = int(0xFFFFFFFF) # 32 bit int - - -def _make_params(args: list[Any], id_name: str = 'random_test_{i}') -> list: - return [pytest.param(x, id=id_name.format(i=i)) for i, x in enumerate(args)] - - -def _build_test_list(static_data, random_data, random_id_name='random_test_{i}') -> Iterable: - return itertools.chain(static_data, _make_params(random_data, id_name=random_id_name)) - - -class TestNewConfig: - """Test the new config with an array of hand-picked and random data.""" - - def __update_linuxconfig(self) -> None: - """On linux config uses ConfigParser, which doesn't update from disk changes. Force the update here.""" - if sys.platform != 'linux': - return - - from config.linux import LinuxConfig # type: ignore - - if isinstance(config, LinuxConfig) and config.config is not None: - config.config.read(config.filename) - - @mark.parametrize("i", _build_test_list(int_tests, _get_fuzz(int, value_length=(-big_int, big_int)))) - def test_ints(self, i: int) -> None: - """Save int and then unpack it again.""" - if sys.platform == 'win32': - i = abs(i) - - name = f"int_test_{i}" - config.set(name, i) - config.save() - self.__update_linuxconfig() - assert i == config.get_int(name) - config.delete(name) - - @mark.parametrize("string", _build_test_list(string_tests, _get_fuzz(str, value_length=(0, 512)))) - def test_string(self, string: str) -> None: - """Save a string and then ask for it back.""" - name = f'str_test_{hash(string)}' - config.set(name, string) - config.save() - self.__update_linuxconfig() - assert string == config.get_str(name) - config.delete(name) - - @mark.parametrize("lst", _build_test_list(list_tests, _get_fuzz(list))) - def test_list(self, lst: list[str]) -> None: - """Save a list and then ask for it back.""" - name = f'list_test_{hash("".join(lst))}' - config.set(name, lst) - - config.save() - self.__update_linuxconfig() - - assert lst == config.get_list(name) - - config.delete(name) - - @mark.parametrize('b', bool_tests) - def test_bool(self, b: bool) -> None: - """Save a bool and ask for it back.""" - name = str(b) - config.set(name, b) - config.save() - self.__update_linuxconfig() - assert b == config.get_bool(name) - config.delete(name) - - def test_get_no_error(self) -> None: - """Regression test to ensure that get() doesn't throw a TypeError.""" - name = 'test-get' - config.set(name, '1337') - config.save() - self.__update_linuxconfig() - res = config.get_str(name) - - assert res == '1337' - config.delete(name) - config.save() From ab0b09420d6363174c42cdd32667d7090f160122 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Sun, 16 Nov 2025 22:20:39 -0500 Subject: [PATCH 41/84] [517] Handle Other Exceptions --- config/__init__.py | 2 +- config/linux.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/__init__.py b/config/__init__.py index c1a45a5b..b3f7ac69 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -523,7 +523,7 @@ def get_config(*args, **kwargs) -> Config: from .linux import LinuxConfigMinimal try: config = LinuxConfigMinimal() - except FileNotFoundError: + except (FileNotFoundError, TypeError): return Config(app_path=app_dir_path) # Nothing to Convert if config: diff --git a/config/linux.py b/config/linux.py index 394b3e4e..b7aa354a 100644 --- a/config/linux.py +++ b/config/linux.py @@ -40,7 +40,7 @@ class LinuxConfigMinimal: if filename else xdg_config_home / "EDMarketConnector" / "EDMarketConnector.ini" ) - if not pathlib.Path(filename).exists(): + if not pathlib.Path(filename).is_file(): raise FileNotFoundError # Load INI self.config = ConfigParser(interpolation=None) From 6e982e8a546c652f976c0914faa64705c776ab30 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Sun, 16 Nov 2025 22:37:25 -0500 Subject: [PATCH 42/84] [#1790] Build 64 and 32 Bit Installers --- .github/workflows/windows-build.yml | 82 +++++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 3 deletions(-) diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml index 3bffb6bd..41b7be88 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -68,7 +68,7 @@ jobs: path: | EDMarketConnector-release-*.tar.gz - windows_build: + windows_build_32: needs: [variables] name: Build EDMC runs-on: windows-latest @@ -128,7 +128,83 @@ jobs: - name: Rename Installer run: | - Get-ChildItem -Path . -Filter "EDMarketConnector_Installer_*.exe" | Rename-Item -NewName {"EDMarketConnector_Installer_Unsigned_$($_.Name -replace '^EDMarketConnector_Installer_', '')"} + Get-ChildItem -Path . -Filter "EDMarketConnector_Installer_*.exe" | + Rename-Item -NewName { + $rest = $_.Name -replace '^EDMarketConnector_Installer_', '' + "EDMarketConnector_Installer_Unsigned_${rest}_x86.exe" + } + - name: Upload build files + uses: actions/upload-artifact@v5 + with: + name: built-files-windows + path: | + EDMarketConnector_Installer_*.exe + EDMarketConnector-release-*.zip + windows_build_64: + needs: [variables] + name: Build EDMC + runs-on: windows-latest + + defaults: + run: + shell: powershell + + steps: + - uses: actions/checkout@v5 + with: + submodules: true + + - name: Make zip archive + uses: thedoctor0/zip-release@main + with: + type: 'zip' + # We want an in-zip prefix of `EDMarketConnector/` for all files, so + # we specify that: + # 1. We work from the parent directory + directory: '..' + # 2. The path we're using is the 'root' directory + path: 'EDMarketConnector' + # 3. The .zip file has to be in the 'root' so that upload-artifact + # will process it. Can't use relative paths. + filename: 'EDMarketConnector/EDMarketConnector-release-${{ needs.variables.outputs.sem_ver }}.zip' + # 4. And all the exclusions need to be prefixed with the 'root' + # directory. + # NB: If this gets too long it can cause zip 'Command Line Error', + # presumably due to a Windows CL length limit. + exclusions: 'EDMarketConnector/EDMarketConnector-release-*.* EDMarketConnector/.editorconfig EDMarketConnector/.flake8 EDMarketConnector/.git* EDMarketConnector/.mypy.ini EDMarketConnector/.pre-commit-config.yaml EDMarketConnector/build.py EDMarketConnector/*.manifest EDMarketConnector/coriolis-data/ EDMarketConnector/img/ EDMarketConnector/pyproject.toml EDMarketConnector/scripts/ EDMarketConnector/tests/' + + - uses: actions/setup-python@v6 + with: + python-version-file: '.python-version' + architecture: "x64" + cache: 'pip' # caching pip dependencies + + - name: Install python tools + run: | + pip install -r requirements-dev.txt + + - name: Download winsparkle + run: | + Invoke-Webrequest -UseBasicParsing https://github.com/vslavik/winsparkle/releases/download/v0.9.2/WinSparkle-0.9.2.zip -OutFile out.zip + Expand-Archive out.zip + Move-Item 'out\WinSparkle-0.9.2\x64\Release\*' '.\' + + - name: Build EDMC + run: | + python build.py + + - name: InnoSetup + uses: nadeemjazmawe/inno-setup-action-cli@v6.0.5 + with: + filepath: './EDMC_Installer_Config.iss' + + - name: Rename Installer + run: | + Get-ChildItem -Path . -Filter "EDMarketConnector_Installer_*.exe" | + Rename-Item -NewName { + $rest = $_.Name -replace '^EDMarketConnector_Installer_', '' + "EDMarketConnector_Installer_Unsigned_${rest}_x64.exe" + } - name: Upload build files uses: actions/upload-artifact@v5 @@ -139,7 +215,7 @@ jobs: EDMarketConnector-release-*.zip Merge: runs-on: ubuntu-latest - needs: [ windows_build, linux_build ] + needs: [ windows_build_64, windows_build_32, linux_build ] steps: - name: Merge Artifacts uses: actions/upload-artifact/merge@v5 From 0f30b5f650f0b44274139ec99e8da1cc23fd896c Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Sun, 16 Nov 2025 22:51:55 -0500 Subject: [PATCH 43/84] [1790] Update Build Script --- .github/workflows/windows-build.yml | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml index 41b7be88..1b3e7773 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -34,12 +34,15 @@ jobs: run: | echo "${{ needs.variables.outputs.short_sha }}" > .gitversion + - name: Sanitize version for filenames + run: echo "SAFE_SEMVER=${{ needs.variables.outputs.sem_ver }}" | tr '/ ' '_' >> $GITHUB_ENV + - name: Make tar archive run: | # For 'tar' we can only specify filename/glob exclusions, not any # directory location tar -c -v -z \ - -f "../EDMarketConnector-release-${{ needs.variables.outputs.sem_ver }}.tar.gz" \ + -f "../EDMarketConnector-release-${SAFE_SEMVER}.tar.gz" \ -C .. \ --exclude=EDMarketConnector-release-*.* \ --exclude=.editorconfig \ @@ -59,7 +62,7 @@ jobs: --exclude=scripts \ --exclude=tests \ EDMarketConnector - mv "../EDMarketConnector-release-${{ needs.variables.outputs.sem_ver }}.tar.gz" . + mv "../EDMarketConnector-release-${SAFE_SEMVER}.tar.gz" . - name: Upload build files uses: actions/upload-artifact@v5 @@ -68,9 +71,9 @@ jobs: path: | EDMarketConnector-release-*.tar.gz - windows_build_32: + windows_build_86: needs: [variables] - name: Build EDMC + name: Build EDMC (x86) runs-on: windows-latest defaults: @@ -82,6 +85,9 @@ jobs: with: submodules: true + - name: Sanitize version for filenames + run: echo "SAFE_SEMVER=${{ needs.variables.outputs.sem_ver }}" | tr '/ ' '_' >> $GITHUB_ENV + - name: Make zip archive uses: thedoctor0/zip-release@main with: @@ -94,7 +100,7 @@ jobs: path: 'EDMarketConnector' # 3. The .zip file has to be in the 'root' so that upload-artifact # will process it. Can't use relative paths. - filename: 'EDMarketConnector/EDMarketConnector-release-${{ needs.variables.outputs.sem_ver }}.zip' + filename: 'EDMarketConnector/EDMarketConnector-release-${SAFE_SEMVER}.zip' # 4. And all the exclusions need to be prefixed with the 'root' # directory. # NB: If this gets too long it can cause zip 'Command Line Error', @@ -136,13 +142,13 @@ jobs: - name: Upload build files uses: actions/upload-artifact@v5 with: - name: built-files-windows + name: built-files-windows-x86 path: | EDMarketConnector_Installer_*.exe EDMarketConnector-release-*.zip windows_build_64: needs: [variables] - name: Build EDMC + name: Build EDMC (x64) runs-on: windows-latest defaults: @@ -166,7 +172,7 @@ jobs: path: 'EDMarketConnector' # 3. The .zip file has to be in the 'root' so that upload-artifact # will process it. Can't use relative paths. - filename: 'EDMarketConnector/EDMarketConnector-release-${{ needs.variables.outputs.sem_ver }}.zip' + filename: 'EDMarketConnector/EDMarketConnector-release-${SAFE_SEMVER}.zip' # 4. And all the exclusions need to be prefixed with the 'root' # directory. # NB: If this gets too long it can cause zip 'Command Line Error', @@ -209,7 +215,7 @@ jobs: - name: Upload build files uses: actions/upload-artifact@v5 with: - name: built-files-windows + name: built-files-windows-64 path: | EDMarketConnector_Installer_*.exe EDMarketConnector-release-*.zip From 1cf8e3f4ddba533a76070a7002dc7070af2639f7 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Sun, 16 Nov 2025 22:54:56 -0500 Subject: [PATCH 44/84] [Minor] :( --- .github/workflows/windows-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml index 1b3e7773..846d8619 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -221,7 +221,7 @@ jobs: EDMarketConnector-release-*.zip Merge: runs-on: ubuntu-latest - needs: [ windows_build_64, windows_build_32, linux_build ] + needs: [ windows_build_64, windows_build_86, linux_build ] steps: - name: Merge Artifacts uses: actions/upload-artifact/merge@v5 From ae10433f4929686408a68954f7676ce5ec478382 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Sun, 16 Nov 2025 23:19:52 -0500 Subject: [PATCH 45/84] [1790] Improve Speed of Builds --- .github/workflows/windows-build.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml index 846d8619..fae5fc31 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -41,8 +41,7 @@ jobs: run: | # For 'tar' we can only specify filename/glob exclusions, not any # directory location - tar -c -v -z \ - -f "../EDMarketConnector-release-${SAFE_SEMVER}.tar.gz" \ + tar -czf "EDMarketConnector-release-${SAFE_SEMVER}.tar.gz" \ -C .. \ --exclude=EDMarketConnector-release-*.* \ --exclude=.editorconfig \ @@ -62,7 +61,6 @@ jobs: --exclude=scripts \ --exclude=tests \ EDMarketConnector - mv "../EDMarketConnector-release-${SAFE_SEMVER}.tar.gz" . - name: Upload build files uses: actions/upload-artifact@v5 @@ -160,6 +158,9 @@ jobs: with: submodules: true + - name: Sanitize version for filenames + run: echo "SAFE_SEMVER=${{ needs.variables.outputs.sem_ver }}" | tr '/ ' '_' >> $GITHUB_ENV + - name: Make zip archive uses: thedoctor0/zip-release@main with: @@ -243,7 +244,7 @@ jobs: path: ./ - name: Hash files - run: sha256sum EDMarketConnector_Installer_*.exe EDMarketConnector-release-*.{zip,tar.gz} > ./hashes.sum + run: find . -maxdepth 1 -type f \( -name "*.exe" -o -name "*.zip" -o -name "*.tar.gz" \) -print0 \ | xargs -0 -P 4 sha256sum > hashes.sum - name: Create Draft Release uses: "softprops/action-gh-release@v2" From c1229b60a22aad4579f16d1a9829ab13c6faa3dd Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Sun, 16 Nov 2025 23:19:52 -0500 Subject: [PATCH 46/84] [1790] Improve Speed of Builds --- .github/workflows/windows-build.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml index 846d8619..910837ed 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -62,7 +62,7 @@ jobs: --exclude=scripts \ --exclude=tests \ EDMarketConnector - mv "../EDMarketConnector-release-${SAFE_SEMVER}.tar.gz" . + mv "../EDMarketConnector-release-${SAFE_SEMVER}.tar.gz" . - name: Upload build files uses: actions/upload-artifact@v5 @@ -160,6 +160,9 @@ jobs: with: submodules: true + - name: Sanitize version for filenames + run: echo "SAFE_SEMVER=${{ needs.variables.outputs.sem_ver }}" | tr '/ ' '_' >> $GITHUB_ENV + - name: Make zip archive uses: thedoctor0/zip-release@main with: @@ -243,7 +246,7 @@ jobs: path: ./ - name: Hash files - run: sha256sum EDMarketConnector_Installer_*.exe EDMarketConnector-release-*.{zip,tar.gz} > ./hashes.sum + run: find . -maxdepth 1 -type f \( -name "*.exe" -o -name "*.zip" -o -name "*.tar.gz" \) -print0 \ | xargs -0 -P 4 sha256sum > hashes.sum - name: Create Draft Release uses: "softprops/action-gh-release@v2" From ef355f57458e071424a9dcaf55390c512a170c8a Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Sun, 16 Nov 2025 23:33:36 -0500 Subject: [PATCH 47/84] Revert Bad Change --- .github/workflows/windows-build.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml index 8ed10810..6b2f6362 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -41,7 +41,8 @@ jobs: run: | # For 'tar' we can only specify filename/glob exclusions, not any # directory location - tar -czf "EDMarketConnector-release-${SAFE_SEMVER}.tar.gz" \ + tar -c -v -z \ + -f "../EDMarketConnector-release-${SAFE_SEMVER}.tar.gz" \ -C .. \ --exclude=EDMarketConnector-release-*.* \ --exclude=.editorconfig \ @@ -61,7 +62,7 @@ jobs: --exclude=scripts \ --exclude=tests \ EDMarketConnector - mv "../EDMarketConnector-release-${SAFE_SEMVER}.tar.gz" . + mv "../EDMarketConnector-release-${SAFE_SEMVER}.tar.gz" . - name: Upload build files uses: actions/upload-artifact@v5 From 9d2d02ae4707da25d633dac5d00b2156f1082a09 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Sun, 16 Nov 2025 23:47:33 -0500 Subject: [PATCH 48/84] [1790] Rename Output Zip --- .github/workflows/windows-build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml index 6b2f6362..6ca33f7f 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -100,7 +100,7 @@ jobs: path: 'EDMarketConnector' # 3. The .zip file has to be in the 'root' so that upload-artifact # will process it. Can't use relative paths. - filename: 'EDMarketConnector/EDMarketConnector-release-${SAFE_SEMVER}.zip' + filename: ${{ format('EDMarketConnector/EDMarketConnector-release-{0}.zip', env.SAFE_SEMVER) }} # 4. And all the exclusions need to be prefixed with the 'root' # directory. # NB: If this gets too long it can cause zip 'Command Line Error', @@ -175,7 +175,7 @@ jobs: path: 'EDMarketConnector' # 3. The .zip file has to be in the 'root' so that upload-artifact # will process it. Can't use relative paths. - filename: 'EDMarketConnector/EDMarketConnector-release-${SAFE_SEMVER}.zip' + filename: ${{ format('EDMarketConnector/EDMarketConnector-release-{0}.zip', env.SAFE_SEMVER) }} # 4. And all the exclusions need to be prefixed with the 'root' # directory. # NB: If this gets too long it can cause zip 'Command Line Error', From 7b97f29867e31cf90084973fee30f65419017cac Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Sun, 16 Nov 2025 23:54:41 -0500 Subject: [PATCH 49/84] [Minor] I shouldn't code late at night --- .github/workflows/windows-build.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml index 6ca33f7f..747d497d 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -86,7 +86,9 @@ jobs: submodules: true - name: Sanitize version for filenames - run: echo "SAFE_SEMVER=${{ needs.variables.outputs.sem_ver }}" | tr '/ ' '_' >> $GITHUB_ENV + run: | + $safe = "${{ needs.variables.outputs.sem_ver }}" -replace '[\/ ]', '_' + echo "SAFE_SEMVER=$safe" >> $env:GITHUB_ENV - name: Make zip archive uses: thedoctor0/zip-release@main From 0f5ab3e7068f89265885ce2af605ee0360f13bc4 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Mon, 17 Nov 2025 00:00:38 -0500 Subject: [PATCH 50/84] Update windows-build.yml --- .github/workflows/windows-build.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml index 747d497d..0c5dd523 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -163,7 +163,9 @@ jobs: submodules: true - name: Sanitize version for filenames - run: echo "SAFE_SEMVER=${{ needs.variables.outputs.sem_ver }}" | tr '/ ' '_' >> $GITHUB_ENV + run: | + $safe = "${{ needs.variables.outputs.sem_ver }}" -replace '[\/ ]', '_' + echo "SAFE_SEMVER=$safe" >> $env:GITHUB_ENV - name: Make zip archive uses: thedoctor0/zip-release@main From 84dc66c8ac79a3dbcf5389a023b72dead3eb7c68 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Mon, 17 Nov 2025 19:05:24 -0500 Subject: [PATCH 51/84] [#1293] Create Scrollable Notebook --- myNotebook.py | 180 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 180 insertions(+) diff --git a/myNotebook.py b/myNotebook.py index 8541a5f9..46f79622 100644 --- a/myNotebook.py +++ b/myNotebook.py @@ -157,3 +157,183 @@ class OptionMenu(ttk.OptionMenu): # Workaround for https://bugs.python.org/issue25684 for i in range(0, self['menu'].index('end') + 1): self['menu'].entryconfig(i, variable=variable) + + +class ScrollableNotebook(Notebook): + """ + ScrollableNotebook – A tab bar that scrolls horizontally when there are too many tabs. + + Based off ttkScrollableNotebook by @muhammeteminturgut. + https://github.com/muhammeteminturgut/ttkScrollableNotebook + """ + + def __init__( + self, + master: ttk.Frame | None = None, + tabmenu: bool = False, + *args, + **kwargs + ) -> None: + super().__init__(master, **kwargs) + + # Sliding state + self.xLocation: int = 0 + self.timer: str | None = None + self.menuSpace: int = 50 if tabmenu else 30 + self.contentsManaged: list[tk.Widget] = [] + + # Notebook that holds the actual content widgets + self.notebookContent: ttk.Notebook = ttk.Notebook(self, **kwargs) + self.notebookContent.pack(fill="both", expand=True) + self.notebookContent.bind("", self._reset_slide) + + # Notebook that displays scrollable tabs + self.notebookTab: ttk.Notebook = ttk.Notebook(self, **kwargs) + self.notebookTab.place(x=0, y=0) + self.notebookTab.bind("<>", self._tab_changer) + + # Sliding frame and controls + slide_frame: ttk.Frame = ttk.Frame(self) + slide_frame.place(relx=1.0, x=0, y=1, anchor=tk.NE) + + if tabmenu: + menu_btn = ttk.Label(slide_frame, text="\u2630") + menu_btn.bind("", self._bottom_menu) + menu_btn.pack(side=tk.RIGHT) + + left_arrow = ttk.Label(slide_frame, text=" \u276e") + left_arrow.bind("", self._left_slide_start) + left_arrow.bind("", self._slide_stop) + left_arrow.pack(side=tk.LEFT) + right_arrow = ttk.Label(slide_frame, text=" \u276f") + right_arrow.bind("", self._right_slide_start) + right_arrow.bind("", self._slide_stop) + right_arrow.pack(side=tk.RIGHT) + + # Outer Notebook geometry + self.grid(padx=10, pady=10, sticky=tk.NSEW) + + def _bottom_menu(self, event: tk.Event) -> None: + menu = tk.Menu(self, tearoff=0) + for tab in self.notebookTab.tabs(): + label = self.notebookTab.tab(tab, option="text") + menu.add_command(label=label, command=lambda t=tab: self.select(t)) # type: ignore + try: + menu.tk_popup(event.x_root, event.y_root) + finally: + menu.grab_release() + + def _tab_changer(self, event: tk.Event) -> None: + try: + idx = self.notebookTab.index("current") + self.notebookContent.select(idx) + except Exception: + pass + + def _right_slide_start(self, event: tk.Event | None = None) -> None: + if self._right_slide(event): + self.timer = self.after(100, self._right_slide_start) + + def _right_slide(self, event: tk.Event | None) -> bool: + tabs_w = self.notebookTab.winfo_width() + content_w = self.notebookContent.winfo_width() + + if tabs_w > content_w - self.menuSpace: + remaining = content_w - (tabs_w + self.notebookTab.winfo_x()) + if remaining <= self.menuSpace + 5: + self.xLocation -= 20 + self.notebookTab.place(x=self.xLocation, y=0) + return True + return False + + def _left_slide_start(self, event: tk.Event | None = None) -> None: + if self._left_slide(event): + self.timer = self.after(100, self._left_slide_start) + + def _left_slide(self, event: tk.Event | None) -> bool: + if self.notebookTab.winfo_x() != 0: + self.xLocation += 20 + self.notebookTab.place(x=self.xLocation, y=0) + return True + return False + + def _slide_stop(self, event: tk.Event) -> None: + if self.timer is not None: + self.after_cancel(self.timer) + self.timer = None + + def _reset_slide(self, event: tk.Event | None = None) -> None: + self.notebookTab.place(x=0, y=0) + self.xLocation = 0 + + def add(self, child: tk.Widget, **kwargs) -> None: + """Add content + visual tab.""" + has_tabs = len(self.notebookTab.tabs()) > 0 + + # Content tab properties + content_kwargs = kwargs.copy() + content_kwargs["text"] = "" # content tabs never show text + + if has_tabs: + content_kwargs["state"] = "hidden" + else: + content_kwargs.pop("state", None) + + # Add content widget + self.notebookContent.add(child, **content_kwargs) + + # Add visible tab + self.notebookTab.add(ttk.Frame(self.notebookTab), **kwargs) + self.contentsManaged.append(child) + + def __content_tab_id(self, tab_id: str) -> str: + idx = self.notebookTab.tabs().index(tab_id) + return self.notebookContent.tabs()[idx] + + def forget(self, tab_id: str) -> None: # type: ignore + """Remove a tab from both the visible tab strip and the hidden content notebook.""" + idx = self.notebookTab.index(tab_id) + content_tab = self.__content_tab_id(tab_id) + + self.notebookContent.forget(content_tab) + self.notebookTab.forget(tab_id) + self.contentsManaged[idx].destroy() + self.contentsManaged.pop(idx) + + def hide(self, tab_id: str) -> None: + """Hide a tab without destroying it.""" + self.notebookContent.hide(self.__content_tab_id(tab_id)) + self.notebookTab.hide(tab_id) + + def identify(self, x: int, y: int) -> str | None: # type: ignore + """Identify the visible tab at a given x/y coord.""" + return self.notebookTab.identify(x, y) + + def index(self, tab_id: str) -> int: + """Return the index of a visible tab.""" + return self.notebookTab.index(tab_id) + + def insert(self, pos: int, child: tk.Widget, **kwargs) -> None: + """Insert a new tab at a specified position.""" + self.notebookContent.insert(pos, child, **kwargs) + self.notebookTab.insert(pos, ttk.Frame(self.notebookTab), **kwargs) + + def select(self, tab_id: str) -> None: # type: ignore + """Select a tab.""" + self.notebookTab.select(tab_id) + + def tab(self, tab_id: str, option: str | None = None, **kwargs): + """Get/Set Options for tabs.""" + c_kwargs = kwargs.copy() + c_kwargs["text"] = "" # content tabs never show text + self.notebookContent.tab(self.__content_tab_id(tab_id), **c_kwargs) + return self.notebookTab.tab(tab_id, option=option, **kwargs) + + def tabs(self) -> tuple[str, ...]: + """Tuple of all tabs.""" + return self.notebookTab.tabs() + + def enable_traversal(self) -> None: + """Enable keyboard shortcuts for tabs.""" + self.notebookContent.enable_traversal() + self.notebookTab.enable_traversal() From ca243b775f7399a83141862378d50ea0e4458d1f Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Mon, 17 Nov 2025 19:12:12 -0500 Subject: [PATCH 52/84] [#261] Enable Plugin Enable/Disable System This does rely on plugins respecting a stop call. --- L10n/en.template | 9 ++++++ prefs.py | 79 ++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 79 insertions(+), 9 deletions(-) diff --git a/L10n/en.template b/L10n/en.template index 98ae2ba9..faac3259 100644 --- a/L10n/en.template +++ b/L10n/en.template @@ -498,6 +498,15 @@ /* prefs.py: Catch & Record Profiler Errors; */ "Error in System Profiler" = "Error in System Profiler"; +/* prefs.py: Disabling a Plugin. */ +"Disabling plugin {PLUGIN}. This will cause a restart. Click OK to continue..." = "Disabling plugin {PLUGIN}. This will cause a restart. Click OK to continue..."; + +/* prefs.py: Enable a Disabled Plugin */ +"Enable" = "Enable"; + +/* prefs.py: Disable an Enabled Plugin */ +"Disable" = "Disable"; + /* stats.py: Cmdr stats; In files: stats.py:58; */ "Balance" = "Balance"; diff --git a/prefs.py b/prefs.py index 5d604d39..71e03087 100644 --- a/prefs.py +++ b/prefs.py @@ -4,6 +4,7 @@ from __future__ import annotations import contextlib import logging +import time from os.path import join, normpath from pathlib import Path import subprocess @@ -275,7 +276,7 @@ class PreferencesDialog(tk.Toplevel): frame.rowconfigure(0, weight=1) frame.rowconfigure(1, weight=0) - notebook: nb.Notebook = nb.Notebook(frame) + notebook: nb.ScrollableNotebook = nb.ScrollableNotebook(frame, tabmenu=True) notebook.bind('<>', self.tabchanged) # Recompute on tab change self.PADX = 10 @@ -324,12 +325,6 @@ class PreferencesDialog(tk.Toplevel): # Set Log Directory self.logfile_loc = Path(config.app_dir_path / 'logs') - # Set minimum size to prevent content cut-off - self.update_idletasks() # Update "requested size" from geometry manager - min_width = self.winfo_reqwidth() - min_height = self.winfo_reqheight() - self.wm_minsize(min_width, min_height) - def __setup_output_tab(self, root_notebook: ttk.Notebook) -> None: output_frame = nb.Frame(root_notebook) output_frame.columnconfigure(0, weight=1) @@ -980,11 +975,19 @@ class PreferencesDialog(tk.Toplevel): ).grid(padx=self.PADX, pady=self.PADY, sticky=tk.W, row=row.get()) for plugin in enabled_plugins: + curr_row = row.get() label = nb.Label(plugins_frame, text=plugin.name if plugin.name == plugin.folder else f'{plugin.folder} ({plugin.name})') - label.grid(columnspan=2, padx=self.LISTX, pady=self.PADY, sticky=tk.W, row=row.get()) + label.grid(column=0, columnspan=2, padx=self.LISTX, pady=self.PADY, sticky=tk.W, row=curr_row) + + btn = ttk.Button( + plugins_frame, + text=tr.tl("Disable"), # LANG: Disable an Enabled Plugin + command=lambda plugin=plugin: self.disable_plugin(plugin) # type: ignore + ) + btn.grid(column=3, padx=self.LISTX, pady=self.PADY, sticky=tk.W, row=curr_row) ############################################################ # Show which plugins don't have Python 3.x support @@ -1026,9 +1029,18 @@ class PreferencesDialog(tk.Toplevel): ).grid(padx=self.PADX, pady=self.PADY, sticky=tk.W, row=row.get()) for plugin in disabled_plugins: + curr_row = row.get() nb.Label(plugins_frame, text=plugin.name).grid( - columnspan=2, padx=self.LISTX, pady=self.PADY, sticky=tk.W, row=row.get() + column=0, columnspan=2, padx=self.LISTX, pady=self.PADY, sticky=tk.W, row=curr_row ) + + btn = ttk.Button( + plugins_frame, + text=tr.tl("Enable"), # LANG: Enable a Disabled Plugin + command=lambda plugin=plugin: self.enable_plugin(plugin) # type: ignore + ) + btn.grid(column=3, padx=self.LISTX, pady=self.PADY, sticky=tk.W, row=curr_row) + ############################################################ # Show plugins that failed to load ############################################################ @@ -1050,6 +1062,55 @@ class PreferencesDialog(tk.Toplevel): # LANG: Label on Settings > Plugins tab notebook.add(plugins_frame, text=tr.tl('Plugins')) # Tab heading in settings + def disable_plugin(self, plugin): + """Disable an existing plugin and restart.""" + logger.debug(f"Calling plugin_stop() for {plugin.name}") + if plugin._get_func('plugin_stop'): # Try to stop cleanly. We're going regardless... + plugin.module.plugin_stop() + # LANG: Text of Notification Popup for EDMC Restart + restart_msg = tr.tl( # LANG: Disabling a Plugin + r"Disabling plugin {PLUGIN}. This will cause a restart. Click OK to continue..." + ).format(PLUGIN=plugin.name) + restart_box = tk.messagebox.Message( + title=tr.tl('Restart Required'), # LANG: Title of Notification Popup for EDMC Restart + message=restart_msg, + type=tk.messagebox.OK + ) + restart_box.show() + time.sleep(2) # Give plugin stop time to work. + plug.PLUGINS.remove(plugin) # Remove PLugin from active list + try: + folder = Path(config.plugin_dir_path / plugin.folder) + new_name = f"{folder}.disabled" + folder.rename(new_name) + logger.info(f"Disabled {plugin.name}.") + except FileExistsError: + logger.warning("Unable to disable the plugin!") + return + self.req_restart = True + self.apply() + + def enable_plugin(self, plugin): + """Enable an existing plugin and restart.""" + logger.debug(f"Attempting to enable {plugin.name}") + localfolder = plugin.folder + ".disabled" + folder = Path(config.plugin_dir_path) / localfolder + if not folder.exists(): + logger.warning(f"Folder does not exist: {folder}") + return + new_folder = folder.with_name(plugin.folder.replace(".disabled", "")) + if new_folder.exists(): + logger.warning(f"Target folder already exists: {new_folder}") + return + try: + folder.rename(new_folder) + logger.info(f"Enabled {plugin.name}.") + except Exception as e: + logger.error(f"Failed to enable plugin {plugin.name}: {e}") + return + self.req_restart = True + self.apply() + def cmdrchanged(self, event=None): """ Notify plugins of cmdr change. From 61e8ff0c7a436afaa4a51966775b1f29c0120ef6 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Tue, 18 Nov 2025 18:56:37 -0500 Subject: [PATCH 53/84] [Minor] Fix "Reset Provider" popup on first run --- EDMarketConnector.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index a665b641..aceba378 100644 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -2054,20 +2054,23 @@ def validate_providers(): station_provider: str = config.get_str("station_provider") if station_provider not in plug.provides('station_url'): logger.error("Station Provider Not Valid. Setting to Default.") + if config.get_str('station_provider'): # Only generate a pop-up if an invalid entry exists, not no value. + reset_providers["Station"] = (station_provider, "EDSM") config.set('station_provider', 'EDSM') - reset_providers["Station"] = (station_provider, "EDSM") shipyard_provider: str = config.get_str("shipyard_provider") if shipyard_provider not in plug.provides('shipyard_url'): logger.error("Shipyard Provider Not Valid. Setting to Default.") + if config.get_str('shipyard_provider'): # Only generate a pop-up if an invalid entry exists, not no value. + reset_providers["Shipyard"] = (shipyard_provider, "EDSY") config.set('shipyard_provider', 'EDSY') - reset_providers["Shipyard"] = (shipyard_provider, "EDSY") system_provider: str = config.get_str("system_provider") if system_provider not in plug.provides('system_url'): logger.error("System Provider Not Valid. Setting to Default.") + if config.get_str('system_provider'): # Only generate a pop-up if an invalid entry exists, not no value. + reset_providers["System"] = (system_provider, "EDSM") config.set('system_provider', 'EDSM') - reset_providers["System"] = (system_provider, "EDSM") if not reset_providers: return From bc09786b283bf28efa32f0a77ca06e51d2b74204 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Tue, 18 Nov 2025 21:50:56 -0500 Subject: [PATCH 54/84] [RELEASE] 6.0.0-beta1 --- ChangeLog.md | 69 ++++++++++++++++++++++++++++++++++++---------- config/__init__.py | 2 +- 2 files changed, 55 insertions(+), 16 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index c4d24e42..39c08e64 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,26 +1,65 @@ This is the master changelog for Elite Dangerous Market Connector. Entries are in reverse chronological order (latest first). --- -* We currently test against, and package with, Python 3.13, 32-bit. - * As a result, we do not support Windows 7, 8, or 8.1. - * Developers can check the contents of the `.python-version` file - in the source (not distributed with the Windows installer) for the - currently used version. +* We currently test against, and package with, Python 3.13, 64-bit. --- -Release 6.0.0 +Pre-Release 6.0.0-Beta1 === +This is a PUBLIC BETA for EDMC 6.0.0, now available on the Beta update track! -This is the WORK IN PROGRESS changelog for upcoming release 5.14. All features are subject to change. +This build represents one of the most significant internal updates to EDMC in recent memory. +It includes a complete overhaul of the configuration system, full x64-bit build support, major plugin-system +enhancements (including enable/disable support), new core plugins, and additional updates across the codebase. + +Because of the scale of these changes, existing workflows, plugins, and user configurations may behave differently. +Plugin developers must review the removal list and update their plugins promptly, as several +deprecated APIs and legacy behaviors have been removed. + +This is a BETA release – BUGS ARE EXPECTED. Please report any issues on GitHub so we can stabilize the final 6.0.0 release. **Changes and Enhancements** -* Updated Python minimum version to 3.13. -* Updated a number of under-the-hood dependencies -* Updated WinSparkle updater +* Enables building of x64-bit builds. +* Added a new unified config system and migrates both Linux and Windows configuration files to a new config.toml format at the program root directory. +* Added a new EDAstro core plugin to send specific events to EDAstro. +* Added a new plugin Enable/Disable system in Preferences -> Plugins. +* Added a new logger into the Config module prior to the default logger. +* Added a new --skip-journallock argument to allow EDMC to start even if the journal lock was not acquired. +* Added a new ScrollableNotebook class to enable horizontal scrolling of tabs in a Notebook. +* Updated the Plugins settings window to use the new ScrollableNotebook class. +* Updated a number of GitHub workflow dependencies. +* Updated the default Python version to 3.13. * Updated EDMC:// protocol handler to use process handles with least-privilege access for improved security and reliability. -* Updated prototyping for proper 32/64-bit font loading -* Updated WndProc callbacks for proper 32/64-bit handling -* Changed some functions to use non-deprecated alternatives -* Set new deprecation warnings using Python 3.13's new Deprecation decorator. -* Fixed a bug where "en" would not be included as a valid language and raise a KeyError +* Updated a number of Tkinter TK elements to use the updated TTK equivelents. +* Updated some internal function calls to use non-deprecated alternatives. +* Updated the LastError class to a Python Dataclass. +* Updated a number of dependencies. +* Updated a number of Win32 calls with proper prototyping for x64-bit builds. +* Updated the WIndows WinSparkle updater to be more maintainable. +* Updated the Windows DDE Request handler for the EDMC Protocol, specifically callbacks and internal stability. +* Simplified some internal logic calls. +* Simplified the git shorthash function call. + +**Bug Fixes** +* Fixes a bug where protocol handler reset popups would be generated on first runs of EDMC. +* Fixed a bug where "en" was not present in available languages. +* Fixed a bug where the EDMC System Profiler could not be run on Linux systems. +* Fixed a bug where the plugin prefs window was not resizable. +* Fixed a bug where EDDN's queue would not actually start processing on app launch. + +**Key Removals** +* Removed the long-deprecated config 1.0 conversion calls. +* Removed the "_" builtin translation in favor of tr.tl. +* Removed the stringFromNumber, numberFromString, and preferredLanguages functions. +* Removed the _Translations singleton in favor of the more modern classes. +* Removed the nb.Entry, nb.ColoredButton classes. +* Removed legacy queue migration functionality from EDDN. +* Removed the help_open_log_folder function in favor of open_log_folder. +* Removed the legacy config AbstractClass and most Windows/Linux specific config functions in favor of new defaults. + +**Plugin Developers** +* Several deprecated functions have been removed. Please ensure your plugins are updated! +* The new Plugin Disable option relies on plugins respecting plugin_stop(). Ensure that your plugins respect this call! +* EDMC is now installed by default with x64-bit builds. +* EDMC will expect a minimum version of Python 3.13. While we do not currently use code incompatible with some earlier versions, we reserve the right to do so. Release 5.13.3 === diff --git a/config/__init__.py b/config/__init__.py index b3f7ac69..77609a76 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -53,7 +53,7 @@ appcmdname = "EDMC" # # Major.Minor.Patch(-prerelease)(+buildmetadata) # NB: Do *not* import this, use the functions appversion() and appversion_nobuild() -_static_appversion = "6.0.0-alpha0" +_static_appversion = "6.0.0-beta1" _cached_version: semantic_version.Version | None = None copyright = "© 2015-2019 Jonathan Harris, 2020-2025 EDCD" From 3fee941bbb55879dfebe56061cc5ff7606917dcc Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Tue, 18 Nov 2025 22:17:26 -0500 Subject: [PATCH 55/84] [Minor] Fix Some Output Tooling --- .github/workflows/windows-build.yml | 2 +- ChangeLog.md | 12 ++++++------ scripts/build_changelog.py | 6 ++++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml index 0c5dd523..8418c2dd 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -250,7 +250,7 @@ jobs: path: ./ - name: Hash files - run: find . -maxdepth 1 -type f \( -name "*.exe" -o -name "*.zip" -o -name "*.tar.gz" \) -print0 \ | xargs -0 -P 4 sha256sum > hashes.sum + run: sha256sum EDMarketConnector_Installer_*.exe EDMarketConnector-release-*.{zip,tar.gz} > ./hashes.sum - name: Create Draft Release uses: "softprops/action-gh-release@v2" diff --git a/ChangeLog.md b/ChangeLog.md index 39c08e64..f1f688ae 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -7,7 +7,7 @@ Pre-Release 6.0.0-Beta1 This is a PUBLIC BETA for EDMC 6.0.0, now available on the Beta update track! This build represents one of the most significant internal updates to EDMC in recent memory. -It includes a complete overhaul of the configuration system, full x64-bit build support, major plugin-system +It includes a complete overhaul of the configuration system, full x64-bit build support, major plugin system enhancements (including enable/disable support), new core plugins, and additional updates across the codebase. Because of the scale of these changes, existing workflows, plugins, and user configurations may behave differently. @@ -18,22 +18,22 @@ This is a BETA release – BUGS ARE EXPECTED. Please report any issues on GitHub **Changes and Enhancements** * Enables building of x64-bit builds. -* Added a new unified config system and migrates both Linux and Windows configuration files to a new config.toml format at the program root directory. +* Added a new unified config system and migrated both Linux and Windows configuration files to a new config.toml format at the program root directory. * Added a new EDAstro core plugin to send specific events to EDAstro. -* Added a new plugin Enable/Disable system in Preferences -> Plugins. -* Added a new logger into the Config module prior to the default logger. +* Added a new plugin Enable/Disable system, in Preferences -> Plugins. +* Added a new logger to the Config module prior to the default logger. * Added a new --skip-journallock argument to allow EDMC to start even if the journal lock was not acquired. * Added a new ScrollableNotebook class to enable horizontal scrolling of tabs in a Notebook. * Updated the Plugins settings window to use the new ScrollableNotebook class. * Updated a number of GitHub workflow dependencies. * Updated the default Python version to 3.13. * Updated EDMC:// protocol handler to use process handles with least-privilege access for improved security and reliability. -* Updated a number of Tkinter TK elements to use the updated TTK equivelents. +* Updated a number of Tkinter TK elements to use the updated TTK equivalents. * Updated some internal function calls to use non-deprecated alternatives. * Updated the LastError class to a Python Dataclass. * Updated a number of dependencies. * Updated a number of Win32 calls with proper prototyping for x64-bit builds. -* Updated the WIndows WinSparkle updater to be more maintainable. +* Updated the Windows WinSparkle updater to be more maintainable. * Updated the Windows DDE Request handler for the EDMC Protocol, specifically callbacks and internal stability. * Simplified some internal logic calls. * Simplified the git shorthash function call. diff --git a/scripts/build_changelog.py b/scripts/build_changelog.py index 42157947..3406ed50 100644 --- a/scripts/build_changelog.py +++ b/scripts/build_changelog.py @@ -43,7 +43,7 @@ def build_html(md_changelog: str, version: str) -> str: """Convert markdown changelog to HTML.""" html_out = f"

Release {version}

\n" html_out += mistune.html(md_changelog) # type: ignore - html_out = re.sub(r"h1", "h2", html_out) + "\n
" + html_out = re.sub(r"h1", "h2", html_out) + "
" with open("script_output/html_changelog.txt", "w", encoding="utf-8") as html_file: html_file.write(html_out) @@ -75,6 +75,8 @@ def build_fdev( f"[HEADING=2][URL='{gh_link}'][SIZE=7]Release {version}[/SIZE][/URL][/HEADING]\n" f"[URL='{vt_signed}']Pre-emptive upload to VirusTotal[/URL]. " f"([URL='{vt_unsigned}']Unsigned Installer[/URL])\n\n" + f"Please note: EDMC now distributes 64-bit builds by default. 32-bit (x86) builds " + f"are still available for download on GitHub.\n\n" ) if version.startswith(("Pre-Release", "Beta")): @@ -118,7 +120,7 @@ You can also view the Elite: Dangerous Forum thread [HERE](https://forums.fronti [Unsigned Installer](""" - reddit_mid_2 = """) if you don't want to use the code-signed option. + reddit_mid_2 = """) if you don't want to use the code-signed option. Please note: EDMC now distributes 64-bit builds by default. 32-bit (x86) builds are still available for download on GitHub. ~~----------------------------------------------------~~ """ From 8dbd5cae69675d4a09c877dd42842ebd181ddb1a Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Wed, 19 Nov 2025 20:57:41 -0500 Subject: [PATCH 56/84] [Minor] Add Custom Config Path, Add Additional Logging --- EDMC.py | 5 +++++ EDMarketConnector.py | 5 +++++ config/__init__.py | 44 ++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/EDMC.py b/EDMC.py index b8e95a55..58264fb0 100755 --- a/EDMC.py +++ b/EDMC.py @@ -132,6 +132,8 @@ def main() -> None: # noqa: C901, CCR001 action='store_true', ) + parser.add_argument('--config', help="Define a custom config to load EDMC from") + parser.add_argument('-a', metavar='FILE', help='write ship loadout to FILE in Companion API json format') parser.add_argument('-e', metavar='FILE', help='write ship loadout to FILE in E:D Shipyard plain text format') parser.add_argument('-l', metavar='FILE', help='write ship locations to FILE in CSV format') @@ -175,6 +177,9 @@ def main() -> None: # noqa: C901, CCR001 sys.exit(EXIT_ARGS) edmclogger.set_channels_loglevel(args.loglevel) + if args.config: + config.reload_from_path(args.config) + logger.debug(f'Startup v{appversion()} : Running on Python v{sys.version}') logger.debug(f'''Platform: {sys.platform} argv[0]: {sys.argv[0]} diff --git a/EDMarketConnector.py b/EDMarketConnector.py index aceba378..e7bdf490 100644 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -102,6 +102,8 @@ if __name__ == '__main__': # noqa: C901 help="Start the application minimized", action="store_true" ) + + parser.add_argument('--config', help="Define a custom config to load EDMC from") ########################################################################### ########################################################################### @@ -204,6 +206,9 @@ if __name__ == '__main__': # noqa: C901 args: argparse.Namespace = parser.parse_args() + if args.config: + config.reload_from_path(args.config) + if args.capi_pretend_down: import config as conf_module logger.info('Pretending CAPI is down') diff --git a/config/__init__.py b/config/__init__.py index 77609a76..6fb3e03f 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -211,7 +211,6 @@ class Config: self.home_path = pathlib.Path.home() # Set Needed Platform Var for app_dir_path self.app_dir_path = app_path - self.toml_path: pathlib.Path = self.app_dir_path / "config.toml" self.generated: str | None = None self.source: str | None = None @@ -226,7 +225,7 @@ class Config: if plugdir_str is None or not pathlib.Path(plugdir_str).is_dir(): self.set("plugin_dir", str(self.default_plugin_dir_path)) plugdir_str = self.default_plugin_dir - self.plugin_dir_path = pathlib.Path(plugdir_str) + self.plugin_dir_path = pathlib.Path(self.get('plugin_dir')) self.plugin_dir_path.mkdir(exist_ok=True) # Call the rest of the platform var helpers @@ -434,6 +433,44 @@ class Config: """Return a string version of default_journal_dir.""" return str(self.default_journal_dir_path) + def reload_from_path(self, new_config_path: str | pathlib.Path) -> None: + """ + Replace the active config TOML file path and reload all settings. + + This allows the main application (after argparse) to override the + config file used without needing to recreate the Config instance. + """ + new_path = pathlib.Path(new_config_path) + + if not new_path.is_file(): + logger.error(f"Config file not found: {new_config_path}") + return # Use the default config. + + logger.info(f"Reloading config from alternate path: {new_path}") + + # Update path and reload + self.toml_path = new_path + self.generated = None + self.source = None + self.settings = {} + + # Load TOML content from the new file and setup system. + self._load() + self._init_platform() + + # Re-run plugin_dir logic + plugdir_str = self.get_str("plugin_dir") + if not plugdir_str: + plugdir_str = str(self.default_plugin_dir) + self.plugin_dir_path = self.default_plugin_dir_path + self.set("plugin_dir", plugdir_str) + elif not pathlib.Path(plugdir_str).is_dir(): + self.set("plugin_dir", str(self.default_plugin_dir_path)) + plugdir_str = self.default_plugin_dir + + self.plugin_dir_path = pathlib.Path(plugdir_str) + self.plugin_dir_path.mkdir(exist_ok=True) + @staticmethod def _suppress_call( func: Callable[..., _T], @@ -517,6 +554,7 @@ def get_config(*args, **kwargs) -> Config: try: config = WinConfigMinimal() except FileNotFoundError: + logger.error("No Config TOML found, no Windows Registry entry found.") return Config(app_path=app_dir_path) # Nothing to Convert if sys.platform == "linux": # pragma: sys-platform-linux @@ -524,9 +562,11 @@ def get_config(*args, **kwargs) -> Config: try: config = LinuxConfigMinimal() except (FileNotFoundError, TypeError): + logger.error("No Config TOML found, no Linux ini file found.") return Config(app_path=app_dir_path) # Nothing to Convert if config: + logger.info("Oldstyle config found. Converting...") config.write_to_toml(f"{app_dir_path}/config.toml") # type: ignore return Config(app_path=app_dir_path) From f2d2354fb5d5f1276af4a7bc40d06fa9e110498c Mon Sep 17 00:00:00 2001 From: David Muckle Date: Wed, 19 Nov 2025 21:50:34 -0500 Subject: [PATCH 57/84] Improve linux config import and logging --- config/linux.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/config/linux.py b/config/linux.py index b7aa354a..27e4d6bf 100644 --- a/config/linux.py +++ b/config/linux.py @@ -40,11 +40,16 @@ class LinuxConfigMinimal: if filename else xdg_config_home / "EDMarketConnector" / "EDMarketConnector.ini" ) - if not pathlib.Path(filename).is_file(): + if not pathlib.Path(self.filename).is_file(): raise FileNotFoundError # Load INI self.config = ConfigParser(interpolation=None) - self.config.read(self.filename) + try: + read_files = self.config.read(self.filename) + config_logger.debug("ConfigParser.read returned: %s", read_files) + except Exception as e: + config_logger.exception("Failed to read INI file %s: %s", self.filename, e) + raise def _get_settings_dict(self) -> dict[str, Any]: """Return all keys/values from SECTION as a dict of strings.""" @@ -64,7 +69,7 @@ class LinuxConfigMinimal: path_obj = pathlib.Path(toml_path) path_obj.parent.mkdir(parents=True, exist_ok=True) - config_logger.debug("Writing Config File") + config_logger.debug("Writing Config File to %s", path_obj) with path_obj.open("wb") as f: tomli_w.dump(config_data, f) From b85705c13ab1f2e02ae612894fdd743b06fe269b Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Thu, 20 Nov 2025 17:53:57 -0500 Subject: [PATCH 58/84] [#2532] Ignore Loadout If Embarked --- plugins/inara.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plugins/inara.py b/plugins/inara.py index d2fd1efc..3b292f4c 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -105,6 +105,7 @@ class This: self.materials: list[dict[str, Any]] | None = None self.last_credits: int = 0 # Send credit update soon after Startup / new game self.storedmodules: list[dict[str, Any]] | None = None + self.embarked: bool = False # Boarded Someone Else's Ship? Should always start as False. self.loadout: dict[str, Any] | None = None self.fleet: list[dict[str, Any]] | None = None self.shipswap: bool = False # just swapped ship @@ -532,6 +533,13 @@ def journal_entry( # noqa: C901, CCR001 power_data = {'powerName': entry["Power"], 'rankValue': entry["Rank"]} new_add_event('setCommanderRankPower', entry['timestamp'], power_data) + # Handle Embark/Disembark Events + if event_name == 'Embark': + this.embarked = True + + if event_name == 'Disembark': + this.embarked = False + # Ship change if event_name == 'Loadout' and this.shipswap: this.loadout = make_loadout(state) @@ -821,7 +829,7 @@ def journal_entry( # noqa: C901, CCR001 for ship in this.fleet: new_add_event('setCommanderShip', entry['timestamp'], ship) # Loadout - if event_name == 'Loadout': + if event_name == 'Loadout' and not this.embarked: # Ignore Loadout Events if Embarked loadout = make_loadout(state) if this.loadout != loadout: this.loadout = loadout From a8e34f2a3b1348e967dd6a0e7526d1b3b392f82f Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Thu, 20 Nov 2025 18:00:06 -0500 Subject: [PATCH 59/84] Add Multicrew Check Too --- plugins/inara.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/inara.py b/plugins/inara.py index 3b292f4c..56df1e0e 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -536,9 +536,11 @@ def journal_entry( # noqa: C901, CCR001 # Handle Embark/Disembark Events if event_name == 'Embark': this.embarked = True + this.multicrew = True if event_name == 'Disembark': this.embarked = False + this.multicrew = False # Ship change if event_name == 'Loadout' and this.shipswap: From 459a79446054ef6e6f0443df7768f121014e9b94 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Thu, 20 Nov 2025 18:03:58 -0500 Subject: [PATCH 60/84] [PRE-RELEASE] 6.0.0-beta2 --- ChangeLog.md | 19 ++++++++++++++++++- config/__init__.py | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index f1f688ae..539d8996 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -2,6 +2,23 @@ This is the master changelog for Elite Dangerous Market Connector. Entries are --- * We currently test against, and package with, Python 3.13, 64-bit. --- +Pre-Release 6.0.0-Beta2 +=== +This is a PUBLIC BETA for EDMC 6.0.0, now available on the Beta update track! + +This build contains everything in Beta1, with a few fixes identified in testing and a new --config option. + +This is a BETA release – BUGS ARE EXPECTED. Please report any issues on GitHub so we can stabilize the final 6.0.0 release. + +**Changes and Enhancements** +* Added a new --config option to EDMC to allow users to specify a different config file. +* Added additional notes about 64-bit builds to the changelog generator. + +**Bug Fixes** +* Fixed a bug where the release hashes.sum would not have content populate. +* Fixed a bug where .ini config files would not be read during file conversion on Linux static builds like Flatpak. +* Fixed a bug where Embarked crew would send erronious events to Inara. + Pre-Release 6.0.0-Beta1 === This is a PUBLIC BETA for EDMC 6.0.0, now available on the Beta update track! @@ -18,7 +35,7 @@ This is a BETA release – BUGS ARE EXPECTED. Please report any issues on GitHub **Changes and Enhancements** * Enables building of x64-bit builds. -* Added a new unified config system and migrated both Linux and Windows configuration files to a new config.toml format at the program root directory. +* Added a new unified config system and migrated both Linux and Windows configuration files to a new config.toml format. This config file is placed by default in EDMC's LocalAppData folder on Windows or the XDG_DATA_HOME/EDMarketConnector path on Linux. * Added a new EDAstro core plugin to send specific events to EDAstro. * Added a new plugin Enable/Disable system, in Preferences -> Plugins. * Added a new logger to the Config module prior to the default logger. diff --git a/config/__init__.py b/config/__init__.py index 6fb3e03f..3fe9a255 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -53,7 +53,7 @@ appcmdname = "EDMC" # # Major.Minor.Patch(-prerelease)(+buildmetadata) # NB: Do *not* import this, use the functions appversion() and appversion_nobuild() -_static_appversion = "6.0.0-beta1" +_static_appversion = "6.0.0-beta2" _cached_version: semantic_version.Version | None = None copyright = "© 2015-2019 Jonathan Harris, 2020-2025 EDCD" From 48dafaf31fb5ada830ac76e99bd236e6315d0592 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Thu, 20 Nov 2025 18:19:04 -0500 Subject: [PATCH 61/84] Update ChangeLog.md --- ChangeLog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index 539d8996..0cd46d97 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -17,7 +17,7 @@ This is a BETA release – BUGS ARE EXPECTED. Please report any issues on GitHub **Bug Fixes** * Fixed a bug where the release hashes.sum would not have content populate. * Fixed a bug where .ini config files would not be read during file conversion on Linux static builds like Flatpak. -* Fixed a bug where Embarked crew would send erronious events to Inara. +* Fixed a bug where Embarked crew would send erroneous events to Inara. Pre-Release 6.0.0-Beta1 === From d5afc4517b7af2108669b2604ed1b231a33161f8 Mon Sep 17 00:00:00 2001 From: David Muckle Date: Fri, 21 Nov 2025 21:02:16 -0500 Subject: [PATCH 62/84] Correctly decode lists in Linux .ini file, treat all config keys as lowercase. --- config/__init__.py | 14 ++++----- config/linux.py | 74 ++++++++++++++++++++++++++++++++++++++++++---- config/windows.py | 2 +- 3 files changed, 76 insertions(+), 14 deletions(-) diff --git a/config/__init__.py b/config/__init__.py index 3fe9a255..1d6a1ebd 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -275,16 +275,16 @@ class Config: def get(self, key: str, default=None): """Return raw stored value.""" - return self.settings.get(key, default) + return self.settings.get(key.lower(), default) def get_str(self, key: str, default="") -> str: """Return string value.""" - val = self.get(key, default) + val = self.get(key.lower(), default) return str(val) if val is not None else default def get_int(self, key: str, default=0) -> int: """Adaptive int (handles booleans stored as ints).""" - val = self.get(key) + val = self.get(key.lower()) if isinstance(val, int): return val try: @@ -300,7 +300,7 @@ class Config: - Accepts strings "true"/"false"/"1"/"0" - Accepts real booleans """ - val = self.get(key) + val = self.get(key.lower()) if isinstance(val, bool): return val @@ -319,7 +319,7 @@ class Config: def get_list(self, key: str, default=None): """Return the list referred to by the given key if it exists, or the default.""" - val = self.get(key) + val = self.get(key.lower()) return ( val if isinstance(val, list) else (default if default is not None else []) ) @@ -492,7 +492,7 @@ class Config: def delete(self, key: str, *, suppress=False) -> None: """Delete the given key from the config.""" try: - self.settings.pop(key, None) + self.settings.pop(key.lower(), None) except (KeyError, IndexError): if suppress: return @@ -501,7 +501,7 @@ class Config: def set(self, key: str, value: Any): """Modify a setting and save to disk.""" - self.settings[key] = value + self.settings[key.lower()] = value self.save() def save(self): diff --git a/config/linux.py b/config/linux.py index 27e4d6bf..000946be 100644 --- a/config/linux.py +++ b/config/linux.py @@ -42,8 +42,7 @@ class LinuxConfigMinimal: ) if not pathlib.Path(self.filename).is_file(): raise FileNotFoundError - # Load INI - self.config = ConfigParser(interpolation=None) + self.config = ConfigParser(comment_prefixes=('#',), interpolation=None) try: read_files = self.config.read(self.filename) config_logger.debug("ConfigParser.read returned: %s", read_files) @@ -51,11 +50,74 @@ class LinuxConfigMinimal: config_logger.exception("Failed to read INI file %s: %s", self.filename, e) raise + __unescape_lut = {'\\': '\\', 'n': '\n', ';': ';', 'r': '\r', '#': '#'} + + def __unescape(self, s: str) -> str: + """ + Unescape a string. + + :param s: str - The string to unescape. + :return: str - The unescaped string. + """ + out: list[str] = [] + i = 0 + while i < len(s): + c = s[i] + if c != '\\': + out.append(c) + i += 1 + continue + + # We have a backslash, check what it's escaping + if i == len(s) - 1: + raise ValueError('Escaped string has unescaped trailer') + + unescaped = self.__unescape_lut.get(s[i + 1]) + if unescaped is None: + raise ValueError(f'Unknown escape: \\{s[i+1]}') + + out.append(unescaped) + i += 2 + + return "".join(out) + def _get_settings_dict(self) -> dict[str, Any]: - """Return all keys/values from SECTION as a dict of strings.""" - return { - key: self.config[self.SECTION][key] for key in self.config[self.SECTION] - } + """ + Return all keys/values from SECTION as a dict of strings or lists. + + This decodes the historical encoding where lists are encoded as + newline-separated values separated by ';' + """ + result: dict[str, Any] = {} + for key in self.config[self.SECTION]: + raw = self.config[self.SECTION][key] + + if raw is None: + continue + + # If the value contains newline(s), check for trailing ';' sentinel + if "\n" in raw: + parts = raw.split("\n") + if parts and parts[-1].strip() == ";": + items = [self.__unescape(p.strip()) for p in parts[:-1]] + result[key] = items + config_logger.debug("Decoded list for key '%s' with %d items", key, len(items)) + continue + else: + # Not a valid encoded list; fall back to unescaped string + try: + result[key] = self.__unescape(raw) + except Exception: + result[key] = raw + continue + + # Single value: unescape and return + try: + result[key] = self.__unescape(raw) + except Exception: + result[key] = raw + + return result def write_to_toml(self, toml_path: str) -> None: """Dump existing config to TOML file.""" diff --git a/config/windows.py b/config/windows.py index 6789bc4e..ee654c4b 100644 --- a/config/windows.py +++ b/config/windows.py @@ -82,7 +82,7 @@ class WinConfigMinimal: for i in range(num_values): name, data, data_type = winreg.EnumValue(key, i) - config_data["settings"][name] = self._convert_reg_value_for_toml( + config_data["settings"][str(name).lower()] = self._convert_reg_value_for_toml( data, data_type ) From b9f3cf3d6ad9ae229fe10141d1422f50b2fe5f58 Mon Sep 17 00:00:00 2001 From: Inutt <1228850-inutt@users.noreply.gitlab.com> Date: Mon, 24 Nov 2025 17:59:47 +0000 Subject: [PATCH 63/84] Fix relative imports in plugins Allow plugins to use relative imports to avoid conflicts between modules with the same name from another plugin. Fixes #2345 diff --git a/plug.py b/plug.py index 1a8779f7..8890c80f 100644 --- a/plug.py +++ b/plug.py @@ -48,13 +48,20 @@ last_error = LastError() class Plugin: """An EDMC plugin.""" - def __init__(self, name: str, loadfile: Path | None, plugin_logger: logging.Logger | None): # noqa: CCR001 + def __init__( + self, + name: str, + loadfile: Path | None, + plugin_logger: logging.Logger | None, + internal: bool = False + ): # noqa: CCR001 """ Load a single plugin. :param name: Base name of the file being loaded from. :param loadfile: Full path/filename of the plugin. :param plugin_logger: The logging instance for this plugin to use. + :param internal: True to use internal plugin loader logic. Defaults to False. :raises Exception: Typically, ImportError or OSError """ self.name: str = name # Display name. @@ -65,14 +72,19 @@ class Plugin: if loadfile: logger.info(f'loading plugin "{name.replace(".", "_")}" from "{loadfile}"') try: - filename = 'plugin_' - filename += name.encode(encoding='ascii', errors='replace').decode('utf-8').replace('.', '_') - spec = importlib.util.spec_from_file_location(filename, loadfile) - # Replaces older load_module() code. Includes a safety check that the module name is set. - if spec is not None and spec.loader is not None: - module = importlib.util.module_from_spec(spec) - sys.modules[module.__name__] = module - spec.loader.exec_module(module) + if internal: + filename = 'plugin_' + filename += name.encode(encoding='ascii', errors='replace').decode('utf-8').replace('.', '_') + spec = importlib.util.spec_from_file_location(filename, loadfile) + # Replaces older load_module() code. Includes a safety check that the module name is set. + if spec is not None and spec.loader is not None: + module = importlib.util.module_from_spec(spec) + sys.modules[module.__name__] = module + spec.loader.exec_module(module) + else: + module = importlib.import_module('.load', name) + + if module: if getattr(module, 'plugin_start3', None): newname = module.plugin_start3(Path(loadfile).resolve().parent) self.name = str(newname) if newname else self.name @@ -170,7 +182,7 @@ def _load_internal_plugins(): try: plugin_name = name[:-3] plugin_path = config.internal_plugin_dir_path / name - plugin = Plugin(plugin_name, plugin_path, logger) + plugin = Plugin(plugin_name, plugin_path, logger, internal=True) plugin.folder = None internal.append(plugin) except Exception: diff --git a/plug.py b/plug.py index 1a8779f7..8890c80f 100644 --- a/plug.py +++ b/plug.py @@ -48,13 +48,20 @@ last_error = LastError() class Plugin: """An EDMC plugin.""" - def __init__(self, name: str, loadfile: Path | None, plugin_logger: logging.Logger | None): # noqa: CCR001 + def __init__( + self, + name: str, + loadfile: Path | None, + plugin_logger: logging.Logger | None, + internal: bool = False + ): # noqa: CCR001 """ Load a single plugin. :param name: Base name of the file being loaded from. :param loadfile: Full path/filename of the plugin. :param plugin_logger: The logging instance for this plugin to use. + :param internal: True to use internal plugin loader logic. Defaults to False. :raises Exception: Typically, ImportError or OSError """ self.name: str = name # Display name. @@ -65,14 +72,19 @@ class Plugin: if loadfile: logger.info(f'loading plugin "{name.replace(".", "_")}" from "{loadfile}"') try: - filename = 'plugin_' - filename += name.encode(encoding='ascii', errors='replace').decode('utf-8').replace('.', '_') - spec = importlib.util.spec_from_file_location(filename, loadfile) - # Replaces older load_module() code. Includes a safety check that the module name is set. - if spec is not None and spec.loader is not None: - module = importlib.util.module_from_spec(spec) - sys.modules[module.__name__] = module - spec.loader.exec_module(module) + if internal: + filename = 'plugin_' + filename += name.encode(encoding='ascii', errors='replace').decode('utf-8').replace('.', '_') + spec = importlib.util.spec_from_file_location(filename, loadfile) + # Replaces older load_module() code. Includes a safety check that the module name is set. + if spec is not None and spec.loader is not None: + module = importlib.util.module_from_spec(spec) + sys.modules[module.__name__] = module + spec.loader.exec_module(module) + else: + module = importlib.import_module('.load', name) + + if module: if getattr(module, 'plugin_start3', None): newname = module.plugin_start3(Path(loadfile).resolve().parent) self.name = str(newname) if newname else self.name @@ -170,7 +182,7 @@ def _load_internal_plugins(): try: plugin_name = name[:-3] plugin_path = config.internal_plugin_dir_path / name - plugin = Plugin(plugin_name, plugin_path, logger) + plugin = Plugin(plugin_name, plugin_path, logger, internal=True) plugin.folder = None internal.append(plugin) except Exception: --- plug.py | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/plug.py b/plug.py index 1a8779f7..8890c80f 100644 --- a/plug.py +++ b/plug.py @@ -48,13 +48,20 @@ last_error = LastError() class Plugin: """An EDMC plugin.""" - def __init__(self, name: str, loadfile: Path | None, plugin_logger: logging.Logger | None): # noqa: CCR001 + def __init__( + self, + name: str, + loadfile: Path | None, + plugin_logger: logging.Logger | None, + internal: bool = False + ): # noqa: CCR001 """ Load a single plugin. :param name: Base name of the file being loaded from. :param loadfile: Full path/filename of the plugin. :param plugin_logger: The logging instance for this plugin to use. + :param internal: True to use internal plugin loader logic. Defaults to False. :raises Exception: Typically, ImportError or OSError """ self.name: str = name # Display name. @@ -65,14 +72,19 @@ class Plugin: if loadfile: logger.info(f'loading plugin "{name.replace(".", "_")}" from "{loadfile}"') try: - filename = 'plugin_' - filename += name.encode(encoding='ascii', errors='replace').decode('utf-8').replace('.', '_') - spec = importlib.util.spec_from_file_location(filename, loadfile) - # Replaces older load_module() code. Includes a safety check that the module name is set. - if spec is not None and spec.loader is not None: - module = importlib.util.module_from_spec(spec) - sys.modules[module.__name__] = module - spec.loader.exec_module(module) + if internal: + filename = 'plugin_' + filename += name.encode(encoding='ascii', errors='replace').decode('utf-8').replace('.', '_') + spec = importlib.util.spec_from_file_location(filename, loadfile) + # Replaces older load_module() code. Includes a safety check that the module name is set. + if spec is not None and spec.loader is not None: + module = importlib.util.module_from_spec(spec) + sys.modules[module.__name__] = module + spec.loader.exec_module(module) + else: + module = importlib.import_module('.load', name) + + if module: if getattr(module, 'plugin_start3', None): newname = module.plugin_start3(Path(loadfile).resolve().parent) self.name = str(newname) if newname else self.name @@ -170,7 +182,7 @@ def _load_internal_plugins(): try: plugin_name = name[:-3] plugin_path = config.internal_plugin_dir_path / name - plugin = Plugin(plugin_name, plugin_path, logger) + plugin = Plugin(plugin_name, plugin_path, logger, internal=True) plugin.folder = None internal.append(plugin) except Exception: From f4e70dbe5b199b892d3c0d629c19a9493db3144d Mon Sep 17 00:00:00 2001 From: Inutt <1228850-inutt@users.noreply.gitlab.com> Date: Mon, 24 Nov 2025 20:14:51 +0000 Subject: [PATCH 64/84] Add documentation for relative plugin imports diff --git a/PLUGINS.md b/PLUGINS.md index 6fd20ef9..71aaec7a 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -163,6 +163,19 @@ circular imports. For an example of how this is done, look at the code in `plugins/common_coreutils.py` and the usage of these functions in other core plugins. +Plugins may import additional code modules from `load.py` in the usual way. Note +that using an import statement like `import my_module` or `from my_module import +foo` will only import one module with that name **across all plugins**. This can +be used to create a shared library used by several plugins if used carefully, +but may create a conflict if another plugin also has a module of the same name +containing different code. For example if two plugins both contain a +`widgets.py` file and both do `import widgets`, only one of the two modules will +actually be imported. + +To avoid this issue, use a relative import statement such as `import .widgets` +or `from .widgets import foo` to ensure that the module is loaded from the +current plugin, even if the name conflicts with another plugin's code. + --- ## Logging --- PLUGINS.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/PLUGINS.md b/PLUGINS.md index 6fd20ef9..71aaec7a 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -163,6 +163,19 @@ circular imports. For an example of how this is done, look at the code in `plugins/common_coreutils.py` and the usage of these functions in other core plugins. +Plugins may import additional code modules from `load.py` in the usual way. Note +that using an import statement like `import my_module` or `from my_module import +foo` will only import one module with that name **across all plugins**. This can +be used to create a shared library used by several plugins if used carefully, +but may create a conflict if another plugin also has a module of the same name +containing different code. For example if two plugins both contain a +`widgets.py` file and both do `import widgets`, only one of the two modules will +actually be imported. + +To avoid this issue, use a relative import statement such as `import .widgets` +or `from .widgets import foo` to ensure that the module is loaded from the +current plugin, even if the name conflicts with another plugin's code. + --- ## Logging From d4ac2fe8b15e49ff819afb3104c7ea1c1d305641 Mon Sep 17 00:00:00 2001 From: David Muckle Date: Tue, 25 Nov 2025 18:42:15 -0500 Subject: [PATCH 65/84] Cast sets to strings, tweak get_str behavior per PR feedback --- config/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/__init__.py b/config/__init__.py index 1d6a1ebd..d45a59fe 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -279,7 +279,7 @@ class Config: def get_str(self, key: str, default="") -> str: """Return string value.""" - val = self.get(key.lower(), default) + val = self.get(key.lower(), None) return str(val) if val is not None else default def get_int(self, key: str, default=0) -> int: @@ -501,7 +501,7 @@ class Config: def set(self, key: str, value: Any): """Modify a setting and save to disk.""" - self.settings[key.lower()] = value + self.settings[key.lower()] = str(value) self.save() def save(self): From a667882189b241234de27f0f5b68c4beac564e4e Mon Sep 17 00:00:00 2001 From: David Muckle Date: Tue, 25 Nov 2025 19:19:32 -0500 Subject: [PATCH 66/84] Add special case in setting for lists to avoid storing as strings The `get_list` does a type check if the value returned is a list, and returns default otherwise. Since we were storing everything as a string, if something set a list after the initial migration to toml, that key would then always be returned as the default value --- config/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/config/__init__.py b/config/__init__.py index d45a59fe..83d73d71 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -501,7 +501,10 @@ class Config: def set(self, key: str, value: Any): """Modify a setting and save to disk.""" - self.settings[key.lower()] = str(value) + if isinstance(value, list): + self.settings[key.lower()] = value + else: + self.settings[key.lower()] = str(value) self.save() def save(self): From bf5824223d94f6d3546b62827eb4df08714f7c41 Mon Sep 17 00:00:00 2001 From: Inutt <1228850-inutt@users.noreply.gitlab.com> Date: Tue, 25 Nov 2025 04:44:11 +0000 Subject: [PATCH 67/84] Fix mypy linting issues Mostly related to adjusting `if sys.platform == 'win32'` logic so things that are only defined on win32 platforms don't cause issues on other platforms. --- common_utils.py | 27 +++++++++++++-------------- config/linux.py | 2 +- myNotebook.py | 16 ++++++++++++---- prefs.py | 5 +++++ util_ships.py | 3 ++- 5 files changed, 33 insertions(+), 20 deletions(-) diff --git a/common_utils.py b/common_utils.py index a6f78356..ce3c7986 100644 --- a/common_utils.py +++ b/common_utils.py @@ -29,23 +29,22 @@ def ensure_on_screen(self, parent: tk.Tk): :param self: The calling class instance of tk.TopLevel :param parent: The parent window """ - if sys.platform != 'win32': - return - try: - # Get monitor info for the monitor containing the parent window - monitor = win32api.MonitorFromWindow(parent.winfo_id(), win32con.MONITOR_DEFAULTTONEAREST) - monitor_info = win32api.GetMonitorInfo(monitor) - work_area = monitor_info['Work'] # Gets the working area (excludes taskbar) + if sys.platform == 'win32': + try: + # Get monitor info for the monitor containing the parent window + monitor = win32api.MonitorFromWindow(parent.winfo_id(), win32con.MONITOR_DEFAULTTONEAREST) + monitor_info = win32api.GetMonitorInfo(monitor) + work_area = monitor_info['Work'] # Gets the working area (excludes taskbar) - # Calculate optimal position - x = max(work_area[0], min(parent.winfo_rootx(), work_area[2] - self.winfo_width())) - y = max(work_area[1], min(parent.winfo_rooty(), work_area[3] - self.winfo_height())) + # Calculate optimal position + x = max(work_area[0], min(parent.winfo_rootx(), work_area[2] - self.winfo_width())) + y = max(work_area[1], min(parent.winfo_rooty(), work_area[3] - self.winfo_height())) - # Update window position - self.geometry(f"+{x}+{y}") + # Update window position + self.geometry(f"+{x}+{y}") - except Exception as e: - logger.debug(f"Failed to ensure window is on screen: {e}") + except Exception as e: + logger.debug(f"Failed to ensure window is on screen: {e}") def log_locale(prefix: str) -> None: diff --git a/config/linux.py b/config/linux.py index 27e4d6bf..1b5ac924 100644 --- a/config/linux.py +++ b/config/linux.py @@ -75,7 +75,7 @@ class LinuxConfigMinimal: def close(self) -> None: """Release resources (stub).""" - self.config = None + del self.config def linux_helper(config: Config) -> Config: diff --git a/myNotebook.py b/myNotebook.py index 46f79622..e4fe6f89 100644 --- a/myNotebook.py +++ b/myNotebook.py @@ -50,10 +50,18 @@ class Label(ttk.Label): """Custom ttk.Label class to fix some display issues.""" def __init__(self, master: ttk.Frame | None = None, **kw): - kw['foreground'] = kw.pop('foreground', PAGEFG if sys.platform == 'win32' - else ttk.Style().lookup('TLabel', 'foreground')) - kw['background'] = kw.pop('background', PAGEBG if sys.platform == 'win32' - else ttk.Style().lookup('TLabel', 'background')) + if sys.platform == 'win32': + fg_color = PAGEFG + else: + fg_color = ttk.Style().lookup('TLabel', 'foreground') + + if sys.platform == 'win32': + bg_color = PAGEBG + else: + bg_color = ttk.Style().lookup('TLabel', 'background') + + kw['foreground'] = kw.pop('foreground', fg_color) + kw['background'] = kw.pop('background', bg_color) super().__init__(master, **kw) diff --git a/prefs.py b/prefs.py index 71e03087..ef5bd2df 100644 --- a/prefs.py +++ b/prefs.py @@ -310,6 +310,11 @@ class PreferencesDialog(tk.Toplevel): self.cmdrchanged() self.themevarchanged() + # Init hotkey attributes to avoid linter errors + self.hotkey_text: ttk.Entry + self.hotkey_only_btn: nb.Checkbutton + self.hotkey_play_btn: nb.Checkbutton + # disable hotkey for the duration hotkeymgr.unregister() diff --git a/util_ships.py b/util_ships.py index 8abbe20f..4f99e731 100644 --- a/util_ships.py +++ b/util_ships.py @@ -6,6 +6,7 @@ Licensed under the GNU General Public License. See LICENSE file. """ import os +import sys from pathlib import Path from edmc_data import ship_name_map @@ -18,7 +19,7 @@ def ship_file_name(ship_name: str, ship_type: str) -> str: name = Path(name).with_suffix("").name # Check if the name is a reserved filename - if os.path.isreserved(name): + if sys.platform == 'win32' and os.path.isreserved(name): name += "_" return name.translate( From 9fd04e5c02f2f1a6ace93c95c0f6ad7cc4ca1f1e Mon Sep 17 00:00:00 2001 From: Inutt <1228850-inutt@users.noreply.gitlab.com> Date: Sat, 29 Nov 2025 01:25:19 +0000 Subject: [PATCH 68/84] Add localisation of stations names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This currently only affects system colonisation ships, which have '$EXT_PANEL_ColonisationShip;' in their StationName entries in the journal. Other strings may need to be added in future. Fixes #2404 diff --git a/L10n/en.template b/L10n/en.template index faac3259..f670e39c 100644 --- a/L10n/en.template +++ b/L10n/en.template @@ -839,3 +839,9 @@ /* edastro_core.py: Settings>EDAstro - Label on checkbox for 'send data'; */ "Send data to EDAstro" = "Send data to EDAstro"; + +/* common_coreutils.py: Colonisation ship name, with title; In files: common_coreutils.py:81:81 */ +"System Colonisation Ship {NAME}" = "System Colonisation Ship {NAME}"; + +/* common_coreutils.py: Unidentified colonisation ship; In files: common_coreutils.py:84:84 */ +"System Colonisation Ship" = "System Colonisation Ship"; diff --git a/plugins/common_coreutils.py b/plugins/common_coreutils.py index 6b90d4dc..a488de46 100644 --- a/plugins/common_coreutils.py +++ b/plugins/common_coreutils.py @@ -29,6 +29,7 @@ import gzip import io import json import os +import re import myNotebook as nb # noqa: N813 from EDMCLogging import get_main_logger from companion import CAPIData @@ -47,6 +48,49 @@ SEPY = 10 # seperator line spacing STATION_UNDOCKED = '×' # "Station" name to display when not docked = U+00D7 +# Known colonisation ship names match one of the following: +# "$EXT_PANEL_ColonisationShip;" +# "$EXT_PANEL_ColonisationShip; " with "" being eg; "Okawara Horizons" +# "$EXT_PANEL_ColonisationShip:#index=;" +# "$EXT_PANEL_ColonisationShip:#index=; " +_RE_COLONISATION_SHIP = re.compile(r'\$EXT_PANEL_ColonisationShip(?::#index=(\d+))?;(?: (.+))?') + + +def localised_name(value: str | None) -> str | None: + """ + Handle localisation of strings in places like station names. + + This is currently an issue for system colonisation ships that have a station name along the + lines of "$EXT_PANEL_ColonisationShip; Okawara Horizons" when written to the journal, but would + be better displayed as "System Colonisation Ship Okawara Horizona" (or other appropriately + localised equivalent). + + If no (known) localisable strings are present, the input will be returned unmodified. + + :param value: The non-localised string. + :return: The localised string, or None if the input was None. + """ + if value is None: + return None + + colonisation_ship_match = _RE_COLONISATION_SHIP.match(value) + if colonisation_ship_match: + ship_index = colonisation_ship_match.group(1) + ship_name = colonisation_ship_match.group(2) + # Use the ship's index as its name if no name was provided. + ship_id = ship_name or ship_index + + if ship_id: + # LANG: Colonisation ship name, with title + value = tr.tl("System Colonisation Ship {NAME}").format(NAME=ship_id) + + else: + # LANG: Unidentified colonisation ship + value = tr.tl("System Colonisation Ship") + + return value + + def plugin_start3(plugin_dir: str) -> str: """ Start the plugin. @@ -121,7 +165,7 @@ def station_link_common(data: CAPIData, this): :param this: The module global from the calling module. """ if data['commander']['docked'] or this.on_foot and this.station_name: - this.station_link['text'] = this.station_name + this.station_link['text'] = localised_name(this.station_name) elif data['lastStarport']['name'] and data['lastStarport']['name'] != "": this.station_link['text'] = STATION_UNDOCKED else: @@ -163,12 +207,14 @@ def station_name_setter_common(this): :param this: The module global from the calling module. """ to_set: str = cast(str, this.station_name) + if not to_set: if this.system_population is not None and this.system_population > 0: to_set = STATION_UNDOCKED else: to_set = '' + to_set = str(localised_name(to_set)) this.station_link['text'] = to_set diff --git a/plugins/edsm.py b/plugins/edsm.py index e1e6b168..902e248b 100644 --- a/plugins/edsm.py +++ b/plugins/edsm.py @@ -43,7 +43,7 @@ from ttkHyperlinkLabel import HyperlinkLabel from l10n import translations as tr from plugins.common_coreutils import (api_keys_label_common, PADX, PADY, BUTTONX, SEPY, BOXY, STATION_UNDOCKED, show_pwd_var_common, station_link_common, this_format_common, - cmdr_data_initial_common) + cmdr_data_initial_common, localised_name) # TODO: @@ -543,7 +543,7 @@ entry: {entry!r}''' to_set = '' if this.station_link: - this.station_link['text'] = to_set + this.station_link['text'] = localised_name(to_set) this.station_link['url'] = station_url(str(this.system_name), str(this.station_name)) this.station_link.update_idletasks() --- L10n/en.template | 6 +++++ plugins/common_coreutils.py | 48 ++++++++++++++++++++++++++++++++++++- plugins/edsm.py | 4 ++-- 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/L10n/en.template b/L10n/en.template index faac3259..f670e39c 100644 --- a/L10n/en.template +++ b/L10n/en.template @@ -839,3 +839,9 @@ /* edastro_core.py: Settings>EDAstro - Label on checkbox for 'send data'; */ "Send data to EDAstro" = "Send data to EDAstro"; + +/* common_coreutils.py: Colonisation ship name, with title; In files: common_coreutils.py:81:81 */ +"System Colonisation Ship {NAME}" = "System Colonisation Ship {NAME}"; + +/* common_coreutils.py: Unidentified colonisation ship; In files: common_coreutils.py:84:84 */ +"System Colonisation Ship" = "System Colonisation Ship"; diff --git a/plugins/common_coreutils.py b/plugins/common_coreutils.py index 6b90d4dc..a488de46 100644 --- a/plugins/common_coreutils.py +++ b/plugins/common_coreutils.py @@ -29,6 +29,7 @@ import gzip import io import json import os +import re import myNotebook as nb # noqa: N813 from EDMCLogging import get_main_logger from companion import CAPIData @@ -47,6 +48,49 @@ SEPY = 10 # seperator line spacing STATION_UNDOCKED = '×' # "Station" name to display when not docked = U+00D7 +# Known colonisation ship names match one of the following: +# "$EXT_PANEL_ColonisationShip;" +# "$EXT_PANEL_ColonisationShip; " with "" being eg; "Okawara Horizons" +# "$EXT_PANEL_ColonisationShip:#index=;" +# "$EXT_PANEL_ColonisationShip:#index=; " +_RE_COLONISATION_SHIP = re.compile(r'\$EXT_PANEL_ColonisationShip(?::#index=(\d+))?;(?: (.+))?') + + +def localised_name(value: str | None) -> str | None: + """ + Handle localisation of strings in places like station names. + + This is currently an issue for system colonisation ships that have a station name along the + lines of "$EXT_PANEL_ColonisationShip; Okawara Horizons" when written to the journal, but would + be better displayed as "System Colonisation Ship Okawara Horizona" (or other appropriately + localised equivalent). + + If no (known) localisable strings are present, the input will be returned unmodified. + + :param value: The non-localised string. + :return: The localised string, or None if the input was None. + """ + if value is None: + return None + + colonisation_ship_match = _RE_COLONISATION_SHIP.match(value) + if colonisation_ship_match: + ship_index = colonisation_ship_match.group(1) + ship_name = colonisation_ship_match.group(2) + # Use the ship's index as its name if no name was provided. + ship_id = ship_name or ship_index + + if ship_id: + # LANG: Colonisation ship name, with title + value = tr.tl("System Colonisation Ship {NAME}").format(NAME=ship_id) + + else: + # LANG: Unidentified colonisation ship + value = tr.tl("System Colonisation Ship") + + return value + + def plugin_start3(plugin_dir: str) -> str: """ Start the plugin. @@ -121,7 +165,7 @@ def station_link_common(data: CAPIData, this): :param this: The module global from the calling module. """ if data['commander']['docked'] or this.on_foot and this.station_name: - this.station_link['text'] = this.station_name + this.station_link['text'] = localised_name(this.station_name) elif data['lastStarport']['name'] and data['lastStarport']['name'] != "": this.station_link['text'] = STATION_UNDOCKED else: @@ -163,12 +207,14 @@ def station_name_setter_common(this): :param this: The module global from the calling module. """ to_set: str = cast(str, this.station_name) + if not to_set: if this.system_population is not None and this.system_population > 0: to_set = STATION_UNDOCKED else: to_set = '' + to_set = str(localised_name(to_set)) this.station_link['text'] = to_set diff --git a/plugins/edsm.py b/plugins/edsm.py index e1e6b168..902e248b 100644 --- a/plugins/edsm.py +++ b/plugins/edsm.py @@ -43,7 +43,7 @@ from ttkHyperlinkLabel import HyperlinkLabel from l10n import translations as tr from plugins.common_coreutils import (api_keys_label_common, PADX, PADY, BUTTONX, SEPY, BOXY, STATION_UNDOCKED, show_pwd_var_common, station_link_common, this_format_common, - cmdr_data_initial_common) + cmdr_data_initial_common, localised_name) # TODO: @@ -543,7 +543,7 @@ entry: {entry!r}''' to_set = '' if this.station_link: - this.station_link['text'] = to_set + this.station_link['text'] = localised_name(to_set) this.station_link['url'] = station_url(str(this.system_name), str(this.station_name)) this.station_link.update_idletasks() From c5961cd91c183f2cbd57e2713ff10376dbe96b28 Mon Sep 17 00:00:00 2001 From: Inutt <1228850-inutt@users.noreply.gitlab.com> Date: Sat, 29 Nov 2025 03:26:21 +0000 Subject: [PATCH 69/84] Fix preference dialog not detecting tab change events --- myNotebook.py | 4 ++++ prefs.py | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/myNotebook.py b/myNotebook.py index 46f79622..7098fad3 100644 --- a/myNotebook.py +++ b/myNotebook.py @@ -14,6 +14,7 @@ import tkinter as tk from tkinter import ttk, messagebox from PIL import ImageGrab from l10n import translations as tr +from typing import Callable if sys.platform == 'win32': PAGEFG = 'SystemWindowText' @@ -171,6 +172,7 @@ class ScrollableNotebook(Notebook): self, master: ttk.Frame | None = None, tabmenu: bool = False, + on_tab_change: Callable | None = None, *args, **kwargs ) -> None: @@ -191,6 +193,8 @@ class ScrollableNotebook(Notebook): self.notebookTab: ttk.Notebook = ttk.Notebook(self, **kwargs) self.notebookTab.place(x=0, y=0) self.notebookTab.bind("<>", self._tab_changer) + if on_tab_change: + self.notebookTab.bind("<>", on_tab_change, add='+') # Sliding frame and controls slide_frame: ttk.Frame = ttk.Frame(self) diff --git a/prefs.py b/prefs.py index 71e03087..f122b9e3 100644 --- a/prefs.py +++ b/prefs.py @@ -276,8 +276,7 @@ class PreferencesDialog(tk.Toplevel): frame.rowconfigure(0, weight=1) frame.rowconfigure(1, weight=0) - notebook: nb.ScrollableNotebook = nb.ScrollableNotebook(frame, tabmenu=True) - notebook.bind('<>', self.tabchanged) # Recompute on tab change + notebook: nb.ScrollableNotebook = nb.ScrollableNotebook(frame, tabmenu=True, on_tab_change=self.tabchanged) self.PADX = 10 self.BUTTONX = 12 # indent Checkbuttons and Radiobuttons From 4fc73c39cd05d8b96404af762fe9951bb0dda901 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Dec 2025 18:49:07 +0000 Subject: [PATCH 70/84] Bump actions/checkout from 5 to 6 Bumps [actions/checkout](https://github.com/actions/checkout) from 5 to 6. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v5...v6) --- updated-dependencies: - dependency-name: actions/checkout dependency-version: '6' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/codeql.yml | 2 +- .github/workflows/pr-checks.yml | 2 +- .github/workflows/push-checks.yml | 2 +- .github/workflows/submodule-update.yml | 2 +- .github/workflows/windows-build.yml | 6 +++--- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index a9e5e523..e9044573 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -59,7 +59,7 @@ jobs: # your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages steps: - name: Checkout repository - uses: actions/checkout@v5 + uses: actions/checkout@v6 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index d49d970d..dd9ee099 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -28,7 +28,7 @@ jobs: # based on. - name: Checkout head commits # https://github.com/actions/checkout - uses: actions/checkout@v5 + uses: actions/checkout@v6 #with: #ref: ${{github.head.sha}} #repository: ${{github.event.pull_request.head.repo.full_name}} diff --git a/.github/workflows/push-checks.yml b/.github/workflows/push-checks.yml index 51c9d47b..f6a1b0ef 100644 --- a/.github/workflows/push-checks.yml +++ b/.github/workflows/push-checks.yml @@ -22,7 +22,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v6 with: fetch-depth: 0 - name: Set up Python diff --git a/.github/workflows/submodule-update.yml b/.github/workflows/submodule-update.yml index 5dbba221..e74e1020 100644 --- a/.github/workflows/submodule-update.yml +++ b/.github/workflows/submodule-update.yml @@ -24,7 +24,7 @@ jobs: OWNER: 'EDCD' steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v6 with: ref: '${{ env.CHECKOUT_BRANCH }}' submodules: true diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml index 8418c2dd..79cc024f 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -27,7 +27,7 @@ jobs: name: Linux environment build steps runs-on: "ubuntu-latest" steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v6 with: submodules: true - name: Create .gitversion @@ -81,7 +81,7 @@ jobs: shell: powershell steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v6 with: submodules: true @@ -158,7 +158,7 @@ jobs: shell: powershell steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v6 with: submodules: true From 98f1aed3f0448b363ecd135734c70a97e0286ed4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Dec 2025 19:12:23 +0000 Subject: [PATCH 71/84] Bump pre-commit from 4.4.0 to 4.5.0 Bumps [pre-commit](https://github.com/pre-commit/pre-commit) from 4.4.0 to 4.5.0. - [Release notes](https://github.com/pre-commit/pre-commit/releases) - [Changelog](https://github.com/pre-commit/pre-commit/blob/main/CHANGELOG.md) - [Commits](https://github.com/pre-commit/pre-commit/compare/v4.4.0...v4.5.0) --- updated-dependencies: - dependency-name: pre-commit dependency-version: 4.5.0 dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 7ad17560..5480fab3 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -23,7 +23,7 @@ types-setuptools==80.9.0.20250822 autopep8==2.3.2 # Git pre-commit checking -pre-commit==4.4.0 +pre-commit==4.5.0 # HTML changelogs mistune==3.1.4 From 77eee9e8be1aff54ae47f1d1f341923a1313460b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Dec 2025 19:12:30 +0000 Subject: [PATCH 72/84] Bump pytest from 9.0.0 to 9.0.1 Bumps [pytest](https://github.com/pytest-dev/pytest) from 9.0.0 to 9.0.1. - [Release notes](https://github.com/pytest-dev/pytest/releases) - [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest/compare/9.0.0...9.0.1) --- updated-dependencies: - dependency-name: pytest dependency-version: 9.0.1 dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 7ad17560..6fb23a2d 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -33,7 +33,7 @@ mistune==3.1.4 py2exe==0.14.0.0; sys_platform == 'win32' # Testing -pytest==9.0.0 +pytest==9.0.1 pytest-cov==7.0.0 # Pytest code coverage support coverage[toml]==7.11.2 # pytest-cov dep. This is here to ensure that it includes TOML support for pyproject.toml configs coverage-conditional-plugin==0.9.0 From 252e16cade327e465f5b87386b4f40ad0e299fd0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Dec 2025 19:12:36 +0000 Subject: [PATCH 73/84] Bump coverage[toml] from 7.11.2 to 7.12.0 Bumps [coverage[toml]](https://github.com/coveragepy/coveragepy) from 7.11.2 to 7.12.0. - [Release notes](https://github.com/coveragepy/coveragepy/releases) - [Changelog](https://github.com/coveragepy/coveragepy/blob/main/CHANGES.rst) - [Commits](https://github.com/coveragepy/coveragepy/compare/7.11.2...7.12.0) --- updated-dependencies: - dependency-name: coverage[toml] dependency-version: 7.12.0 dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 7ad17560..edd4879e 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -35,7 +35,7 @@ py2exe==0.14.0.0; sys_platform == 'win32' # Testing pytest==9.0.0 pytest-cov==7.0.0 # Pytest code coverage support -coverage[toml]==7.11.2 # pytest-cov dep. This is here to ensure that it includes TOML support for pyproject.toml configs +coverage[toml]==7.12.0 # pytest-cov dep. This is here to ensure that it includes TOML support for pyproject.toml configs coverage-conditional-plugin==0.9.0 From 834158a3c76cb6c673dc81df117e4bdd6eacdd50 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Dec 2025 19:12:41 +0000 Subject: [PATCH 74/84] Bump mypy from 1.18.2 to 1.19.0 Bumps [mypy](https://github.com/python/mypy) from 1.18.2 to 1.19.0. - [Changelog](https://github.com/python/mypy/blob/master/CHANGELOG.md) - [Commits](https://github.com/python/mypy/compare/v1.18.2...v1.19.0) --- updated-dependencies: - dependency-name: mypy dependency-version: 1.19.0 dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 7ad17560..5ae068ce 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -13,7 +13,7 @@ flake8-json==24.4.0 flake8-noqa==1.4.0 flake8-use-fstring==1.4 -mypy==1.18.2 +mypy==1.19.0 pep8-naming==0.15.1 safety==3.7.0 types-requests==2.32.4.20250913 From 6d9b200ea80adc95148d5772592a62bde0b5f37f Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Mon, 1 Dec 2025 21:46:47 -0500 Subject: [PATCH 75/84] [#2535] Redo CSV Exporter --- EDMarketConnector.py | 2 +- commodity.py | 84 ++++++++++++++++++++------------------------ theme.py | 4 +-- 3 files changed, 42 insertions(+), 48 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index e7bdf490..122a19dc 100644 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -612,7 +612,7 @@ class AppWindow: self.status.grid(columnspan=2, sticky=tk.EW) for child in frame.winfo_children(): - child.grid_configure(padx=self.PADX, pady=( + child.grid_configure(padx=self.PADX, pady=( # type: ignore sys.platform != 'win32' or isinstance(child, tk.Frame)) and 2 or 0) self.menubar = tk.Menu() diff --git a/commodity.py b/commodity.py index 52c0f8b8..52c13928 100644 --- a/commodity.py +++ b/commodity.py @@ -1,9 +1,10 @@ """Export various CSV formats.""" + # -*- coding: utf-8 -*- import time +import csv from pathlib import Path - from config import config from edmc_data import commodity_bracketmap as bracketmap @@ -12,7 +13,7 @@ from edmc_data import commodity_bracketmap as bracketmap (COMMODITY_DEFAULT, COMMODITY_CSV) = range(2) -def export(data, kind=COMMODITY_DEFAULT, filename=None) -> None: +def export(data, kind=COMMODITY_DEFAULT, filename=None) -> None: # noqa: CCR001 """ Export commodity data from the given CAPI data. @@ -21,55 +22,48 @@ def export(data, kind=COMMODITY_DEFAULT, filename=None) -> None: :param filename: Filename to write to, or None for a standard format name. :return: """ - querytime = config.get_int('querytime', default=int(time.time())) + querytime = config.get_int("querytime", default=int(time.time())) if not filename: - filename_system = data['lastSystem']['name'].strip() - filename_starport = data['lastStarport']['name'].strip() - filename_time = time.strftime('%Y-%m-%dT%H.%M.%S', time.localtime(querytime)) - filename_kind = 'csv' - filename = f'{filename_system}.{filename_starport}.{filename_time}.{filename_kind}' - filename = Path(config.get_str('outdir')) / filename - - if kind == COMMODITY_CSV: - sep = ';' # BUG: for fixing later after cleanup - header = sep.join(('System', 'Station', 'Commodity', 'Sell', 'Buy', 'Demand', '', 'Supply', '', 'Date', '\n')) - rowheader = sep.join((data['lastSystem']['name'], data['lastStarport']['name'])) - - else: - sep = ',' - header = sep.join( - ('System', 'Station', 'Commodity', 'Sell', 'Buy', 'Demand', '', 'Supply', '', 'Average', 'FDevID', 'Date\n') + sysname = data["lastSystem"]["name"].strip() + station = data["lastStarport"]["name"].strip() + timestamp = time.strftime("%Y-%m-%dT%H.%M.%S", time.localtime(querytime)) + ext = "csv" if kind == COMMODITY_CSV else "scsv" + filename = ( + Path(config.get_str("outdir")) / f"{sysname}.{station}.{timestamp}.{ext}" ) - rowheader = sep.join((data['lastSystem']['name'], data['lastStarport']['name'])) + system = data["lastSystem"]["name"] + station = data["lastStarport"]["name"] - with open(filename, 'wt') as h: # codecs can't automatically handle line endings, so encode manually where required - h.write(header) + if kind == COMMODITY_CSV: + header = ["System", "Station", "Commodity", "Sell", "Buy", "Demand", + "", "Supply", "", "Date"] + else: + header = ["System", "Station", "Commodity", "Sell", "Buy", "Demand", + "", "Supply", "", "Average", "FDevID", "Date"] - for commodity in data['lastStarport']['commodities']: - line = sep.join(( - rowheader, - commodity['name'], - commodity['sellPrice'] and str(int(commodity['sellPrice'])) or '', - commodity['buyPrice'] and str(int(commodity['buyPrice'])) or '', - str(int(commodity['demand'])) if commodity['demandBracket'] else '', - bracketmap[commodity['demandBracket']], - str(int(commodity['stock'])) if commodity['stockBracket'] else '', - bracketmap[commodity['stockBracket']] - )) + with open(filename, "w", newline="", encoding="utf-8") as output_file: + writer = csv.writer(output_file, delimiter=";" if kind == COMMODITY_DEFAULT else ",") + + writer.writerow(header) + + for commodity in data["lastStarport"]["commodities"]: + row = [ + system, + station, + commodity["name"], + int(commodity["sellPrice"]) if commodity.get("sellPrice") is not None else "", + int(commodity["buyPrice"]) if commodity.get("buyPrice") is not None else "", + int(commodity["demand"]) if commodity.get("demandBracket") is not None else "", + bracketmap.get(commodity.get("demandBracket"), ""), + int(commodity["stock"]) if commodity.get("stockBracket") is not None else "", + bracketmap.get(commodity.get("stockBracket"), ""), + ] if kind == COMMODITY_DEFAULT: - line = sep.join( - ( - line, - str(int(commodity['meanPrice'])), - str(commodity['id']), - data['timestamp'] + '\n' - ) - ) + mean = int(commodity["meanPrice"]) if commodity.get("meanPrice") is not None else "" + row.extend([mean, commodity["id"]]) - else: - line = sep.join((line, data['timestamp'] + '\n')) - - h.write(line) + row.append(data["timestamp"]) + writer.writerow(row) diff --git a/theme.py b/theme.py index 20ffe51f..d4331291 100644 --- a/theme.py +++ b/theme.py @@ -208,7 +208,7 @@ class _Theme: if isinstance(widget, (tk.Frame, ttk.Frame)): for child in widget.winfo_children(): - self.register(child) + self.register(child) # type: ignore def register_alternate(self, pair: tuple, gridopts: dict) -> None: self.widgets_pair.append((pair, gridopts)) @@ -313,7 +313,7 @@ class _Theme: self._update_widget(widget) if isinstance(widget, (tk.Frame, ttk.Frame)): for child in widget.winfo_children(): - self._update_widget(child) + self._update_widget(child) # type: ignore # Apply current theme to a single widget def _update_widget(self, widget: tk.Widget | tk.BitmapImage) -> None: # noqa: CCR001, C901 From b63b4b90caa498ea76490138ed3a0a6d0cb3e9f8 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Mon, 1 Dec 2025 21:54:14 -0500 Subject: [PATCH 76/84] [Minor] Move Linter Warning --- plug.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plug.py b/plug.py index 8890c80f..e573a218 100644 --- a/plug.py +++ b/plug.py @@ -48,13 +48,13 @@ last_error = LastError() class Plugin: """An EDMC plugin.""" - def __init__( + def __init__( # noqa: CCR001 self, name: str, loadfile: Path | None, plugin_logger: logging.Logger | None, internal: bool = False - ): # noqa: CCR001 + ): """ Load a single plugin. From 2041b3d3d3f1ebaec1bfc80d132cb0c73520aaa4 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Mon, 1 Dec 2025 22:04:28 -0500 Subject: [PATCH 77/84] [Minor] Update Type Hints and Alias Usages --- EDMCLogging.py | 12 ++++++------ EDMarketConnector.py | 10 +++++----- companion.py | 9 +++++---- config/__init__.py | 5 +++-- config/linux.py | 2 +- config/windows.py | 2 +- debug_webserver.py | 3 ++- edshipyard.py | 4 ++-- hotkey/linux.py | 2 +- hotkey/windows.py | 2 +- journal_lock.py | 2 +- killswitch.py | 5 +++-- l10n.py | 3 ++- loadout.py | 6 +++--- monitor.py | 15 ++++++++------- myNotebook.py | 2 +- outfitting.py | 2 +- plug.py | 3 ++- plugins/common_coreutils.py | 3 ++- plugins/coriolis.py | 3 ++- plugins/eddn.py | 5 +++-- plugins/edsm.py | 3 ++- plugins/edsy.py | 3 ++- plugins/inara.py | 3 ++- prefs.py | 20 ++++++++++---------- protocol.py | 6 +++--- scripts/find_localised_strings.py | 2 +- stats.py | 3 ++- td.py | 12 ++++++------ tests/journal_lock.py/test_journal_lock.py | 2 +- theme.py | 2 +- 31 files changed, 85 insertions(+), 71 deletions(-) diff --git a/EDMCLogging.py b/EDMCLogging.py index 201648a2..a05ad107 100644 --- a/EDMCLogging.py +++ b/EDMCLogging.py @@ -193,7 +193,7 @@ class Logger: self.logger_channel_rotating.setFormatter(self.logger_formatter) self.logger.addHandler(self.logger_channel_rotating) - def get_logger(self) -> 'LoggerMixin': + def get_logger(self) -> LoggerMixin: """ Obtain the self.logger of the class instance. @@ -232,7 +232,7 @@ class Logger: logger.trace("Not changing log level because it's TRACE") # type: ignore -def get_plugin_logger(plugin_name: str, loglevel: int = _default_loglevel) -> 'LoggerMixin': +def get_plugin_logger(plugin_name: str, loglevel: int = _default_loglevel) -> LoggerMixin: """ Return a logger suitable for a plugin. @@ -352,7 +352,7 @@ class EDMCContextFilter(logging.Filter): try: args, _, _, value_dict = inspect.getargvalues(frame) if len(args) and args[0] in ('self', 'cls'): - frame_class: 'object' = value_dict[args[0]] + frame_class: object = value_dict[args[0]] if frame_class: # See https://en.wikipedia.org/wiki/Name_mangling#Python for how name mangling works. @@ -450,7 +450,7 @@ class EDMCContextFilter(logging.Filter): # Go up through stack frames until we find the first with a # type(f_locals.self) of logging.Logger. This should be the start # of the frames internal to logging. - frame: 'FrameType' = getframe(0) + frame: FrameType = getframe(0) while frame: if isinstance(frame.f_locals.get('self'), logging.Logger): frame = cast('FrameType', frame.f_back) # Want to start on the next frame below @@ -518,7 +518,7 @@ class EDMCContextFilter(logging.Filter): return module_name -def get_main_logger(sublogger_name: str = '') -> 'LoggerMixin': +def get_main_logger(sublogger_name: str = '') -> LoggerMixin: """Return the correct logger for how the program is being run.""" if not os.getenv("EDMC_NO_UI"): # GUI app being run @@ -537,4 +537,4 @@ base_logger_name = appcmdname if os.getenv('EDMC_NO_UI') else appname edmclogger = Logger(base_logger_name, loglevel=loglevel) for h in config_logger.handlers[:]: config_logger.removeHandler(h) -logger: 'LoggerMixin' = edmclogger.get_logger() +logger: LoggerMixin = edmclogger.get_logger() diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 122a19dc..762afd41 100644 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -54,7 +54,7 @@ if __name__ == '__main__': log_file_path.mkdir(exist_ok=True) log_file_path /= f'{appname}.log' - sys.stdout = sys.stderr = open(log_file_path, mode='wt', buffering=1) # Do NOT use WITH here. + sys.stdout = sys.stderr = open(log_file_path, mode='w', buffering=1) # Do NOT use WITH here. # TODO: Test: Make *sure* this redirect is working, else py2exe is going to cause an exit popup @@ -216,7 +216,7 @@ if __name__ == '__main__': # noqa: C901 if args.capi_use_debug_access_token: import config as conf_module - with open(conf_module.config.app_dir_path / 'access_token.txt', 'r') as at: + with open(conf_module.config.app_dir_path / 'access_token.txt') as at: conf_module.capi_debug_access_token = at.readline().strip() level_to_set: int | None = None @@ -476,7 +476,7 @@ class AppWindow: if sys.platform == 'win32' and not bool(config.get_int('no_systray')): from simplesystray import SysTrayIcon - def open_window(systray: 'SysTrayIcon', *args) -> None: + def open_window(systray: SysTrayIcon, *args) -> None: self.w.deiconify() logfile_loc = pathlib.Path(config.app_dir_path / 'logs') @@ -953,7 +953,7 @@ class AppWindow: self.cooldown() - def export_market_data(self, data: 'CAPIData') -> bool: # noqa: CCR001 + def export_market_data(self, data: CAPIData) -> bool: # noqa: CCR001 """ Export CAPI market data. @@ -1872,7 +1872,7 @@ class AppWindow: h.write(str(companion.session.capi_raw_data).encode(encoding='utf-8')) if sys.platform == 'win32': - def exit_tray(self, systray: 'SysTrayIcon') -> None: + def exit_tray(self, systray: SysTrayIcon) -> None: """Tray icon is shutting down.""" exit_thread = threading.Thread( target=self.onexit, diff --git a/companion.py b/companion.py index 19f12a14..2c920144 100644 --- a/companion.py +++ b/companion.py @@ -29,7 +29,8 @@ import webbrowser from email.utils import parsedate from pathlib import Path from queue import Queue -from typing import TYPE_CHECKING, Any, Mapping, TypeVar +from typing import TYPE_CHECKING, Any, TypeVar +from collections.abc import Mapping import requests import config as conf_module import killswitch @@ -69,7 +70,7 @@ class CAPIData(UserDict): def __init__( self, - data: str | dict[str, Any] | 'CAPIData' | None = None, + data: str | dict[str, Any] | CAPIData | None = None, source_host: str | None = None, source_endpoint: str | None = None, request_cmdr: str | None = None @@ -1204,7 +1205,7 @@ def fixup(data: CAPIData) -> CAPIData: # noqa: C901, CCR001 # Can't be usefully if not (config.app_dir_path / 'FDevIDs' / f).is_file(): logger.warning(f'FDevID file {f} not found! Generating output without these commodity name rewrites.') continue - with open(config.app_dir_path / 'FDevIDs' / f, 'r') as csvfile: + with open(config.app_dir_path / 'FDevIDs' / f) as csvfile: reader = csv.DictReader(csvfile) for row in reader: @@ -1325,7 +1326,7 @@ def index_possibly_sparse_list(data: Mapping[str, V] | list[V], key: int) -> V: if isinstance(data, list): return data[key] - if isinstance(data, (dict, dict)): + if isinstance(data, dict): return data[str(key)] raise ValueError(f'Unexpected data type {type(data)}') diff --git a/config/__init__.py b/config/__init__.py index 3fe9a255..3892f3c7 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -43,7 +43,8 @@ import sys import tomllib import tomli_w from time import gmtime -from typing import Any, Callable, Type, TypeVar +from typing import Any, TypeVar +from collections.abc import Callable import semantic_version from constants import GITVERSION_FILE, applongname, appname @@ -474,7 +475,7 @@ class Config: @staticmethod def _suppress_call( func: Callable[..., _T], - exceptions: Type[BaseException] | list[Type[BaseException]] = Exception, + exceptions: type[BaseException] | list[type[BaseException]] = Exception, *args: Any, **kwargs: Any, ) -> _T | None: diff --git a/config/linux.py b/config/linux.py index 1b5ac924..9fba0ef0 100644 --- a/config/linux.py +++ b/config/linux.py @@ -12,7 +12,7 @@ import sys from config import config_logger if sys.platform != "linux": - raise EnvironmentError("This file is for Linux only.") + raise OSError("This file is for Linux only.") import pathlib diff --git a/config/windows.py b/config/windows.py index 6789bc4e..0f01e681 100644 --- a/config/windows.py +++ b/config/windows.py @@ -21,7 +21,7 @@ if TYPE_CHECKING: from . import Config if sys.platform != "win32": - raise EnvironmentError("This file is for Windows only.") + raise OSError("This file is for Windows only.") REG_RESERVED_ALWAYS_ZERO = 0 diff --git a/debug_webserver.py b/debug_webserver.py index c4be2be3..545e62bd 100644 --- a/debug_webserver.py +++ b/debug_webserver.py @@ -7,7 +7,8 @@ import pathlib import threading import zlib from http import server -from typing import Any, Callable, Literal +from typing import Any, Literal +from collections.abc import Callable from urllib.parse import parse_qs from config import config from EDMCLogging import get_main_logger diff --git a/edshipyard.py b/edshipyard.py index f7bceb75..e1c14e23 100644 --- a/edshipyard.py +++ b/edshipyard.py @@ -189,7 +189,7 @@ def export(data, filename=None) -> None: # noqa: C901, CCR001 raise if filename: - with open(filename, 'wt') as h: + with open(filename, 'w') as h: h.write(string) return @@ -206,5 +206,5 @@ def export(data, filename=None) -> None: # noqa: C901, CCR001 timestamp = time.strftime('%Y-%m-%dT%H.%M.%S', time.localtime(querytime)) filename = pathlib.Path(config.get_str('outdir')) / f'{ship}.{timestamp}.txt' - with open(filename, 'wt') as h: + with open(filename, 'w') as h: h.write(string) diff --git a/hotkey/linux.py b/hotkey/linux.py index 7e4b9862..33e9cd7e 100644 --- a/hotkey/linux.py +++ b/hotkey/linux.py @@ -6,7 +6,7 @@ from EDMCLogging import get_main_logger from hotkey import AbstractHotkeyMgr if sys.platform != 'linux': - raise EnvironmentError("This file is for Linux only.") + raise OSError("This file is for Linux only.") logger = get_main_logger() diff --git a/hotkey/windows.py b/hotkey/windows.py index b292e7a7..9d32edaa 100644 --- a/hotkey/windows.py +++ b/hotkey/windows.py @@ -16,7 +16,7 @@ from EDMCLogging import get_main_logger from hotkey import AbstractHotkeyMgr if sys.platform != 'win32': - raise EnvironmentError("This file is for Windows only.") + raise OSError("This file is for Windows only.") logger = get_main_logger() diff --git a/journal_lock.py b/journal_lock.py index 3e16b309..8d90314e 100644 --- a/journal_lock.py +++ b/journal_lock.py @@ -13,7 +13,7 @@ import tkinter as tk from enum import Enum from os import getpid as os_getpid from tkinter import ttk -from typing import Callable +from collections.abc import Callable from l10n import translations as tr from config import config from EDMCLogging import get_main_logger diff --git a/killswitch.py b/killswitch.py index 22a40049..bec23ba8 100644 --- a/killswitch.py +++ b/killswitch.py @@ -11,9 +11,10 @@ import json import threading from copy import deepcopy from typing import ( - TYPE_CHECKING, Any, Callable, Mapping, MutableMapping, MutableSequence, NamedTuple, Sequence, + TYPE_CHECKING, Any, NamedTuple, TypedDict, TypeVar, cast, Union ) +from collections.abc import Callable, Mapping, MutableMapping, MutableSequence, Sequence import requests import semantic_version from semantic_version.base import Version @@ -217,7 +218,7 @@ class KillSwitchSet: def __init__(self, kill_switches: list[KillSwitches]) -> None: self.kill_switches = kill_switches - def get_disabled(self, id: str, *, version: Union[Version, str] = _current_version) -> DisabledResult: + def get_disabled(self, id: str, *, version: Version | str = _current_version) -> DisabledResult: """ Return whether the given feature ID is disabled by a killswitch for the given version. diff --git a/l10n.py b/l10n.py index 57c8651b..48197592 100755 --- a/l10n.py +++ b/l10n.py @@ -16,7 +16,8 @@ import re import sys from contextlib import suppress from os import listdir, sep -from typing import Iterable, TextIO, cast +from typing import TextIO, cast +from collections.abc import Iterable import pathlib from config import config from EDMCLogging import get_main_logger diff --git a/loadout.py b/loadout.py index 144439c0..c465cdbd 100644 --- a/loadout.py +++ b/loadout.py @@ -33,7 +33,7 @@ def export(data: companion.CAPIData, requested_filename: str | None = None) -> N ) # pretty print if requested_filename is not None and requested_filename: - with open(requested_filename, 'wt') as h: + with open(requested_filename, 'w') as h: h.write(string) return if not requested_filename: @@ -45,7 +45,7 @@ def export(data: companion.CAPIData, requested_filename: str | None = None) -> N regexp = re.compile(re.escape(ship) + r'\.\d\d\d\d-\d\d-\d\dT\d\d\.\d\d\.\d\d\.txt') oldfiles = sorted([x for x in listdir(config.get_str('outdir')) if regexp.match(x)]) if oldfiles: - with open(Path(config.get_str('outdir')) / Path(oldfiles[-1]), 'rU') as h: + with open(Path(config.get_str('outdir')) / Path(oldfiles[-1])) as h: if h.read() == string: return # same as last time - don't write @@ -57,5 +57,5 @@ def export(data: companion.CAPIData, requested_filename: str | None = None) -> N ship_time = time.strftime('%Y-%m-%dT%H.%M.%S', time.localtime(query_time)) file_path = output_directory / f"{ship}.{ship_time}.txt" - with open(file_path, 'wt') as h: + with open(file_path, 'w') as h: h.write(string) diff --git a/monitor.py b/monitor.py index 3df0f85c..c00cfbaf 100644 --- a/monitor.py +++ b/monitor.py @@ -18,7 +18,8 @@ from collections import defaultdict from os import SEEK_END, SEEK_SET, listdir from os.path import basename, expanduser, getctime, isdir, join from time import gmtime, localtime, mktime, sleep, strftime, strptime, time -from typing import TYPE_CHECKING, Any, BinaryIO, MutableMapping +from typing import TYPE_CHECKING, Any, BinaryIO +from collections.abc import MutableMapping import psutil import semantic_version import util_ships @@ -347,7 +348,7 @@ class EDLogs(FileSystemEventHandler): """ return bool(self.thread and self.thread.is_alive()) - def on_created(self, event: 'FileSystemEvent') -> None: + def on_created(self, event: FileSystemEvent) -> None: """Watchdog callback when, e.g. client (re)started.""" if not event.is_directory and self._RE_LOGFILE.search(str(basename(event.src_path))): @@ -2267,7 +2268,7 @@ class EDLogs(FileSystemEventHandler): string = json.dumps(self.ship(False), ensure_ascii=False, indent=2, separators=(',', ': ')) # pretty print if filename: try: - with open(filename, 'wt', encoding='utf-8') as h: + with open(filename, 'w', encoding='utf-8') as h: h.write(string) except UnicodeError: @@ -2276,7 +2277,7 @@ class EDLogs(FileSystemEventHandler): ) try: - with open(filename, 'wt') as h: + with open(filename, 'w') as h: h.write(string) except OSError: @@ -2291,7 +2292,7 @@ class EDLogs(FileSystemEventHandler): ship = util_ships.ship_file_name(self.state['ShipName'], self.state['ShipType']) regexp = re.compile(re.escape(ship) + r'\.\d{4}-\d\d-\d\dT\d\d\.\d\d\.\d\d\.txt') - oldfiles = sorted((x for x in listdir(config.get_str('outdir')) if regexp.match(x))) + oldfiles = sorted(x for x in listdir(config.get_str('outdir')) if regexp.match(x)) if oldfiles: try: with open(join(config.get_str('outdir'), oldfiles[-1]), encoding='utf-8') as h: @@ -2323,13 +2324,13 @@ class EDLogs(FileSystemEventHandler): filename = join(config.get_str('outdir'), f'{ship}.{ts}.txt') try: - with open(filename, 'wt', encoding='utf-8') as h: + with open(filename, 'w', encoding='utf-8') as h: h.write(string) except UnicodeError: logger.exception("UnicodeError writing ship loadout to new filename with utf-8 encoding, trying without...") try: - with open(filename, 'wt') as h: + with open(filename, 'w') as h: h.write(string) except OSError: diff --git a/myNotebook.py b/myNotebook.py index 119f33bb..c28d7873 100644 --- a/myNotebook.py +++ b/myNotebook.py @@ -14,7 +14,7 @@ import tkinter as tk from tkinter import ttk, messagebox from PIL import ImageGrab from l10n import translations as tr -from typing import Callable +from collections.abc import Callable if sys.platform == 'win32': PAGEFG = 'SystemWindowText' diff --git a/outfitting.py b/outfitting.py index 4b014e48..3256da31 100644 --- a/outfitting.py +++ b/outfitting.py @@ -296,7 +296,7 @@ def export(data, filename) -> None: header = 'System,Station,Category,Name,Mount,Guidance,Ship,Class,Rating,FDevID,Date\n' rowheader = f'{data["lastSystem"]["name"]},{data["lastStarport"]["name"]}' - with open(filename, 'wt') as h: + with open(filename, 'w') as h: h.write(header) for v in data["lastStarport"].get("modules", {}).values(): try: diff --git a/plug.py b/plug.py index e573a218..77d73f9e 100644 --- a/plug.py +++ b/plug.py @@ -18,7 +18,8 @@ import tkinter as tk from datetime import datetime, timedelta, timezone from pathlib import Path from tkinter import ttk -from typing import Any, Mapping, MutableMapping +from typing import Any +from collections.abc import Mapping, MutableMapping import companion import myNotebook as nb # noqa: N813 diff --git a/plugins/common_coreutils.py b/plugins/common_coreutils.py index a488de46..2e3b58ae 100644 --- a/plugins/common_coreutils.py +++ b/plugins/common_coreutils.py @@ -22,7 +22,8 @@ referenced in this file (or only in any other core plugin), and if so... # pylint: disable=import-error from __future__ import annotations -from typing import Any, Mapping, cast +from typing import Any, cast +from collections.abc import Mapping import tkinter as tk import base64 import gzip diff --git a/plugins/coriolis.py b/plugins/coriolis.py index 89f128f7..be0bd4be 100644 --- a/plugins/coriolis.py +++ b/plugins/coriolis.py @@ -22,7 +22,8 @@ referenced in this file (or only in any other core plugin), and if so... # pylint: disable=import-error from __future__ import annotations -from typing import Any, Mapping +from typing import Any +from collections.abc import Mapping import tkinter as tk from tkinter import ttk import myNotebook as nb # noqa: N813 # its not my fault. diff --git a/plugins/eddn.py b/plugins/eddn.py index 6410d0b2..8b783c8f 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -33,7 +33,8 @@ from tkinter import ttk from platform import system from textwrap import dedent from threading import Lock -from typing import Any, Iterator, Mapping, MutableMapping +from typing import Any +from collections.abc import Iterator, Mapping, MutableMapping import requests import companion import edmc_data @@ -152,7 +153,7 @@ class EDDNSender: r"unable to validate.',\)]$" ) - def __init__(self, eddn: 'EDDN', eddn_endpoint: str) -> None: + def __init__(self, eddn: EDDN, eddn_endpoint: str) -> None: """ Prepare the system for processing messages. diff --git a/plugins/edsm.py b/plugins/edsm.py index 902e248b..46c8ef4e 100644 --- a/plugins/edsm.py +++ b/plugins/edsm.py @@ -29,7 +29,8 @@ from queue import Queue from threading import Thread from time import sleep from tkinter import ttk -from typing import Any, Literal, Mapping, MutableMapping, cast, Sequence +from typing import Any, Literal, cast +from collections.abc import Mapping, MutableMapping, Sequence import requests import killswitch import monitor diff --git a/plugins/edsy.py b/plugins/edsy.py index b1bdbaf1..109bb2f0 100644 --- a/plugins/edsy.py +++ b/plugins/edsy.py @@ -20,7 +20,8 @@ referenced in this file (or only in any other core plugin), and if so... """ from __future__ import annotations -from typing import Any, Mapping +from typing import Any +from collections.abc import Mapping from plugins.common_coreutils import shipyard_url_common # pylint: disable=E0401 diff --git a/plugins/inara.py b/plugins/inara.py index 56df1e0e..8fcf110c 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -31,7 +31,8 @@ from datetime import datetime, timedelta, timezone from operator import itemgetter from threading import Lock, Thread from tkinter import ttk -from typing import Any, Callable, Deque, Mapping, NamedTuple, Sequence, cast, Union +from typing import Any, Deque, NamedTuple, cast, Union +from collections.abc import Callable, Mapping, Sequence import requests import edmc_data import killswitch diff --git a/prefs.py b/prefs.py index 65feb24b..9b82704a 100644 --- a/prefs.py +++ b/prefs.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """EDMC preferences library.""" from __future__ import annotations @@ -14,7 +13,8 @@ from os import system from tkinter import colorchooser as tkColorChooser # type: ignore # noqa: N812 from tkinter import ttk from types import TracebackType -from typing import Any, Callable, Optional, Type +from typing import Any +from collections.abc import Callable import myNotebook as nb # noqa: N813 import plug from config import appversion_nobuild, config @@ -170,8 +170,8 @@ class AutoInc(contextlib.AbstractContextManager): def __exit__( self, - exc_type: Optional[Type[BaseException]], exc_value: Optional[BaseException], traceback: Optional[TracebackType] - ) -> Optional[bool]: + exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None + ) -> bool | None: """Do nothing.""" return None @@ -241,7 +241,7 @@ if sys.platform == 'win32': class PreferencesDialog(tk.Toplevel): """The EDMC preferences dialog.""" - def __init__(self, parent: tk.Tk, callback: Optional[Callable]): + def __init__(self, parent: tk.Tk, callback: Callable | None): super().__init__(parent) self.parent = parent @@ -265,7 +265,7 @@ class PreferencesDialog(tk.Toplevel): self.cmdr: str | bool | None = False # Note if Cmdr changes in the Journal self.is_beta: bool = False # Note if Beta status changes in the Journal - self.cmdrchanged_alarm: Optional[str] = None # This stores an ID that can be used to cancel a scheduled call + self.cmdrchanged_alarm: str | None = None # This stores an ID that can be used to cancel a scheduled call # Set up the main frame frame = ttk.Frame(self) @@ -1136,7 +1136,7 @@ class PreferencesDialog(tk.Toplevel): """Handle preferences active tab changing.""" self.outvarchanged() - def outvarchanged(self, event: Optional[tk.Event] = None) -> None: + def outvarchanged(self, event: tk.Event | None = None) -> None: """Handle Output tab variable changes.""" self.displaypath(self.outdir, self.outdir_entry) self.displaypath(self.logdir, self.logdir_entry) @@ -1240,14 +1240,14 @@ class PreferencesDialog(tk.Toplevel): self.theme_button_0['state'] = state self.theme_button_1['state'] = state - def hotkeystart(self, event: 'tk.Event[Any]') -> None: + def hotkeystart(self, event: tk.Event[Any]) -> None: """Start listening for hotkeys.""" event.widget.bind('', self.hotkeylisten) event.widget.bind('', self.hotkeylisten) event.widget.delete(0, tk.END) hotkeymgr.acquire_start() - def hotkeyend(self, event: 'tk.Event[Any]') -> None: + def hotkeyend(self, event: tk.Event[Any]) -> None: """Stop listening for hotkeys.""" event.widget.unbind('') event.widget.unbind('') @@ -1258,7 +1258,7 @@ class PreferencesDialog(tk.Toplevel): # LANG: No hotkey/shortcut set hotkeymgr.display(self.hotkey_code, self.hotkey_mods) if self.hotkey_code else tr.tl('None')) - def hotkeylisten(self, event: 'tk.Event[Any]') -> str: + def hotkeylisten(self, event: tk.Event[Any]) -> str: """ Hotkey handler. diff --git a/protocol.py b/protocol.py index cec4333a..774a012e 100644 --- a/protocol.py +++ b/protocol.py @@ -12,7 +12,7 @@ import os import sys import threading from urllib import parse -from typing import TYPE_CHECKING, Type +from typing import TYPE_CHECKING from config import config from constants import appname, protocolhandler_redirect from EDMCLogging import get_main_logger @@ -61,7 +61,7 @@ if config.auth_force_edmc_protocol or ( # noqa: C901 ): # This could be false if you use auth_force_edmc_protocol, but then you get to keep the pieces if sys.platform != "win32": - raise EnvironmentError("This code is for Windows only.") + raise OSError("This code is for Windows only.") # spell-checker: words HBRUSH HICON WPARAM wstring WNDCLASS HMENU HGLOBAL from ctypes import ( # type: ignore windll, @@ -434,7 +434,7 @@ else: # Linux / Run from source ) -def get_handler_impl() -> Type[GenericProtocolHandler]: +def get_handler_impl() -> type[GenericProtocolHandler]: """ Get the appropriate GenericProtocolHandler for the current system and config. diff --git a/scripts/find_localised_strings.py b/scripts/find_localised_strings.py index 19a5efb6..02f928e3 100644 --- a/scripts/find_localised_strings.py +++ b/scripts/find_localised_strings.py @@ -188,7 +188,7 @@ class FileLocation: line_end_col: int | None @staticmethod - def from_call(path: pathlib.Path, c: ast.Call) -> "FileLocation": + def from_call(path: pathlib.Path, c: ast.Call) -> FileLocation: """ Create a FileLocation from a Call and Path. diff --git a/stats.py b/stats.py index c16ec880..67fc9379 100644 --- a/stats.py +++ b/stats.py @@ -12,7 +12,8 @@ import json import sys import tkinter as tk from tkinter import ttk -from typing import Any, AnyStr, Callable, NamedTuple, Sequence, cast +from typing import Any, AnyStr, NamedTuple, cast +from collections.abc import Callable, Sequence import companion import EDMCLogging import myNotebook as nb # noqa: N813 diff --git a/td.py b/td.py index 484e8d29..a5f0d6cd 100644 --- a/td.py +++ b/td.py @@ -30,18 +30,18 @@ def export(data: CAPIData) -> None: # required 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')) + h.write(b'#! trade.py import -\n') this_platform = 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') + f'# Created by {applongname} {appversion()} on {this_platform} for Cmdr {cmdr_name}.\n'.encode() ) h.write( - '#\n# \n\n'.encode('utf-8') + b'#\n# \n\n' ) system_name = data['lastSystem']['name'].strip() starport_name = data['lastStarport']['name'].strip() - h.write(f'@ {system_name}/{starport_name}\n'.encode('utf-8')) + h.write(f'@ {system_name}/{starport_name}\n'.encode()) # sort commodities by category by_category = defaultdict(list) @@ -50,7 +50,7 @@ def export(data: CAPIData) -> None: timestamp = time.strftime('%Y-%m-%d %H:%M:%S', time.strptime(data['timestamp'], '%Y-%m-%dT%H:%M:%SZ')) for category in sorted(by_category): - h.write(f' + {format(category)}\n'.encode('utf-8')) + h.write(f' + {format(category)}\n'.encode()) # corrections to commodity names can change the sort order for commodity in sorted(by_category[category], key=itemgetter('name')): h.write( @@ -61,5 +61,5 @@ def export(data: CAPIData) -> None: f"{demandbracketmap[commodity['demandBracket']]:1}" f" {int(commodity['stock']) if commodity['stockBracket'] else '':8}" f"{stockbracketmap[commodity['stockBracket']]:1}" - f" {timestamp}\n".encode('utf-8') + f" {timestamp}\n".encode() ) diff --git a/tests/journal_lock.py/test_journal_lock.py b/tests/journal_lock.py/test_journal_lock.py index 649140c8..438d1dd5 100644 --- a/tests/journal_lock.py/test_journal_lock.py +++ b/tests/journal_lock.py/test_journal_lock.py @@ -5,7 +5,7 @@ import multiprocessing as mp import os import pathlib import sys -from typing import Generator +from collections.abc import Generator import pytest from pytest import MonkeyPatch, TempdirFactory, TempPathFactory from config import config diff --git a/theme.py b/theme.py index d4331291..fe431ebb 100644 --- a/theme.py +++ b/theme.py @@ -15,7 +15,7 @@ import sys import tkinter as tk from tkinter import font as tk_font from tkinter import ttk -from typing import Callable +from collections.abc import Callable from l10n import translations as tr from config import config from EDMCLogging import get_main_logger From 0e28cd49620215d4a9a2f1efd3e514d6e0848a0e Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Mon, 1 Dec 2025 22:08:16 -0500 Subject: [PATCH 78/84] [Minor] Remove Unneeded Keys Calls --- coriolis-update-files.py | 2 +- edmc_data.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/coriolis-update-files.py b/coriolis-update-files.py index 40d25fb3..f15d4067 100755 --- a/coriolis-update-files.py +++ b/coriolis-update-files.py @@ -45,7 +45,7 @@ if __name__ == "__main__": # noqa: C901 # Symbolic name from in-game name reverse_ship_map = {v: k for k, v in list(ship_name_map.items())} - bulkheads = list(outfitting.armour_map.keys()) + bulkheads = list(outfitting.armour_map) ships = {} modules = {} diff --git a/edmc_data.py b/edmc_data.py index f29795f4..1a94b3ab 100644 --- a/edmc_data.py +++ b/edmc_data.py @@ -605,7 +605,7 @@ edmc_suit_symbol_localised = { # This is sourced from what the game is passed by the launcher, caveat emptor. It was mentioned that / is also # an option # This is only run once when this file is imported by something, no runtime cost or repeated expansions will occur -__keys = list(edmc_suit_symbol_localised.keys()) +__keys = list(edmc_suit_symbol_localised) for lang in __keys: new_lang = lang.replace('\\', r'\\') new_lang_2 = lang.replace('\\', '/') From 733a5183419691ca9a6078da66838a62f0b6ac17 Mon Sep 17 00:00:00 2001 From: Inutt <1228850-inutt@users.noreply.gitlab.com> Date: Thu, 4 Dec 2025 23:54:38 +0000 Subject: [PATCH 79/84] Set player's multicrew role to idle when physically boarding another player's ship --- monitor.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/monitor.py b/monitor.py index c00cfbaf..bc1d44f0 100644 --- a/monitor.py +++ b/monitor.py @@ -812,6 +812,10 @@ class EDLogs(FileSystemEventHandler): self.state['OnFoot'] = False self.state['Taxi'] = entry['Taxi'] + if entry['Multicrew']: + # Player has boarded another player's ship, but has not selected a role yet + self.state['Role'] = 'Idle' + # We can't now have anything in the BackPack, it's all in the # ShipLocker. self.backpack_set_empty() @@ -847,6 +851,10 @@ class EDLogs(FileSystemEventHandler): self.state['Taxi'] = False self.state['Dropship'] = False + # Since the player is now on foot, it's no longer possible to be multicrewing, so no + # need to actually check the multicrew parameter. + self.state['Role'] = None + elif event_type == 'dropshipdeploy': # We're definitely on-foot now self.state['OnFoot'] = True From 26e3407f5392a67a4eb8d9186c8dd14e11cd3182 Mon Sep 17 00:00:00 2001 From: Inutt <1228850-inutt@users.noreply.gitlab.com> Date: Fri, 5 Dec 2025 00:20:14 +0000 Subject: [PATCH 80/84] Revert "Add Multicrew Check Too" This reverts commit a8e34f2a3b1348e967dd6a0e7526d1b3b392f82f. --- plugins/inara.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/inara.py b/plugins/inara.py index 8fcf110c..bf1a36f9 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -537,11 +537,9 @@ def journal_entry( # noqa: C901, CCR001 # Handle Embark/Disembark Events if event_name == 'Embark': this.embarked = True - this.multicrew = True if event_name == 'Disembark': this.embarked = False - this.multicrew = False # Ship change if event_name == 'Loadout' and this.shipswap: From 140f0fbc418a1b3cdc118af00426b6fd9a1b7fbf Mon Sep 17 00:00:00 2001 From: Inutt <1228850-inutt@users.noreply.gitlab.com> Date: Fri, 5 Dec 2025 00:21:48 +0000 Subject: [PATCH 81/84] Revert "[#2532] Ignore Loadout If Embarked" This reverts commit b85705c13ab1f2e02ae612894fdd743b06fe269b. --- plugins/inara.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/plugins/inara.py b/plugins/inara.py index bf1a36f9..33b43094 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -106,7 +106,6 @@ class This: self.materials: list[dict[str, Any]] | None = None self.last_credits: int = 0 # Send credit update soon after Startup / new game self.storedmodules: list[dict[str, Any]] | None = None - self.embarked: bool = False # Boarded Someone Else's Ship? Should always start as False. self.loadout: dict[str, Any] | None = None self.fleet: list[dict[str, Any]] | None = None self.shipswap: bool = False # just swapped ship @@ -534,13 +533,6 @@ def journal_entry( # noqa: C901, CCR001 power_data = {'powerName': entry["Power"], 'rankValue': entry["Rank"]} new_add_event('setCommanderRankPower', entry['timestamp'], power_data) - # Handle Embark/Disembark Events - if event_name == 'Embark': - this.embarked = True - - if event_name == 'Disembark': - this.embarked = False - # Ship change if event_name == 'Loadout' and this.shipswap: this.loadout = make_loadout(state) @@ -830,7 +822,7 @@ def journal_entry( # noqa: C901, CCR001 for ship in this.fleet: new_add_event('setCommanderShip', entry['timestamp'], ship) # Loadout - if event_name == 'Loadout' and not this.embarked: # Ignore Loadout Events if Embarked + if event_name == 'Loadout': loadout = make_loadout(state) if this.loadout != loadout: this.loadout = loadout From 523f890e7b50df361670fddc3252a94eebadd56b Mon Sep 17 00:00:00 2001 From: Inutt <1228850-inutt@users.noreply.gitlab.com> Date: Fri, 5 Dec 2025 00:25:44 +0000 Subject: [PATCH 82/84] Fix if->elif left over from reverts --- plugins/inara.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/inara.py b/plugins/inara.py index 33b43094..be3f517b 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -534,7 +534,7 @@ def journal_entry( # noqa: C901, CCR001 new_add_event('setCommanderRankPower', entry['timestamp'], power_data) # Ship change - if event_name == 'Loadout' and this.shipswap: + elif event_name == 'Loadout' and this.shipswap: this.loadout = make_loadout(state) new_add_event('setCommanderShipLoadout', entry['timestamp'], this.loadout) this.shipswap = False From cd3dbd2397b537d524f92bcc04ba4f6e1aae6a42 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Fri, 5 Dec 2025 09:22:54 -0500 Subject: [PATCH 83/84] Update linux.py --- config/linux.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/linux.py b/config/linux.py index 319e7e87..516b99d0 100644 --- a/config/linux.py +++ b/config/linux.py @@ -81,7 +81,7 @@ class LinuxConfigMinimal: return "".join(out) - def _get_settings_dict(self) -> dict[str, Any]: + def _get_settings_dict(self) -> dict[str, Any]: #noqa: CCR001 """ Return all keys/values from SECTION as a dict of strings or lists. From 051acf17223f1d1c09d6357041a203be984aa809 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Fri, 5 Dec 2025 09:25:31 -0500 Subject: [PATCH 84/84] stupid linter --- config/linux.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/linux.py b/config/linux.py index 516b99d0..39e98793 100644 --- a/config/linux.py +++ b/config/linux.py @@ -81,7 +81,7 @@ class LinuxConfigMinimal: return "".join(out) - def _get_settings_dict(self) -> dict[str, Any]: #noqa: CCR001 + def _get_settings_dict(self) -> dict[str, Any]: # noqa: CCR001 """ Return all keys/values from SECTION as a dict of strings or lists.