station-appkit 1.1.2__tar.gz → 1.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {station_appkit-1.1.2 → station_appkit-1.2.0}/PKG-INFO +1 -1
- {station_appkit-1.1.2 → station_appkit-1.2.0}/pyproject.toml +1 -1
- {station_appkit-1.1.2 → station_appkit-1.2.0}/station_appkit/__init__.py +1 -1
- station_appkit-1.2.0/station_appkit/report.py +88 -0
- station_appkit-1.2.0/tests/test_report.py +85 -0
- {station_appkit-1.1.2 → station_appkit-1.2.0}/.gitignore +0 -0
- {station_appkit-1.1.2 → station_appkit-1.2.0}/LICENSE +0 -0
- {station_appkit-1.1.2 → station_appkit-1.2.0}/README.md +0 -0
- {station_appkit-1.1.2 → station_appkit-1.2.0}/station_appkit/applog.py +0 -0
- {station_appkit-1.1.2 → station_appkit-1.2.0}/station_appkit/login.py +0 -0
- {station_appkit-1.1.2 → station_appkit-1.2.0}/station_appkit/macwindow.py +0 -0
- {station_appkit-1.1.2 → station_appkit-1.2.0}/station_appkit/selfupdate.py +0 -0
- {station_appkit-1.1.2 → station_appkit-1.2.0}/station_appkit/testing.py +0 -0
- {station_appkit-1.1.2 → station_appkit-1.2.0}/station_appkit/updates.py +0 -0
- {station_appkit-1.1.2 → station_appkit-1.2.0}/station_appkit/window.py +0 -0
- {station_appkit-1.1.2 → station_appkit-1.2.0}/tests/conftest.py +0 -0
- {station_appkit-1.1.2 → station_appkit-1.2.0}/tests/test_applog.py +0 -0
- {station_appkit-1.1.2 → station_appkit-1.2.0}/tests/test_login.py +0 -0
- {station_appkit-1.1.2 → station_appkit-1.2.0}/tests/test_macwindow.py +0 -0
- {station_appkit-1.1.2 → station_appkit-1.2.0}/tests/test_selfupdate.py +0 -0
- {station_appkit-1.1.2 → station_appkit-1.2.0}/tests/test_updates.py +0 -0
- {station_appkit-1.1.2 → station_appkit-1.2.0}/tests/test_window.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: station-appkit
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.2.0
|
|
4
4
|
Summary: Update check, self-updater and app window shared by Station Studio, Station Player and Station Server
|
|
5
5
|
Project-URL: Homepage, https://github.com/raby/station-studio
|
|
6
6
|
Project-URL: Repository, https://github.com/raby/station-studio
|
|
@@ -15,7 +15,7 @@ build-backend = "hatchling.build"
|
|
|
15
15
|
|
|
16
16
|
[project]
|
|
17
17
|
name = "station-appkit"
|
|
18
|
-
version = "1.
|
|
18
|
+
version = "1.2.0"
|
|
19
19
|
description = "Update check, self-updater and app window shared by Station Studio, Station Player and Station Server"
|
|
20
20
|
readme = "README.md"
|
|
21
21
|
license = { file = "LICENSE" }
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"""Report a problem: a link to a new GitHub issue with the app, its version
|
|
2
|
+
and the computer already filled in, and where the app's log file is.
|
|
3
|
+
|
|
4
|
+
The issue gets what helps and nothing personal: the app and version, how
|
|
5
|
+
it was installed, the system and Python. Not the log file's path (it holds
|
|
6
|
+
the user's name on most computers): that's shown in the app instead, so
|
|
7
|
+
the person can look at the log and attach it if they choose.
|
|
8
|
+
"""
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import logging
|
|
12
|
+
import platform
|
|
13
|
+
import sys
|
|
14
|
+
import urllib.parse
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
ISSUES_NEW = "https://github.com/raby/station-studio/issues/new"
|
|
18
|
+
|
|
19
|
+
# How each install kind reads in a report. None (pip, pipx, a checkout)
|
|
20
|
+
# is "installed with pip", the commonest of those; in a container, "Docker".
|
|
21
|
+
INSTALLED = {"mac": "downloaded Mac app", "windows": "downloaded Windows app", None: "installed with pip"}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def in_docker() -> bool:
|
|
25
|
+
"""Running in a Docker container (Station Studio's image): its log is
|
|
26
|
+
the container's (docker compose logs), not a file or a terminal."""
|
|
27
|
+
return Path("/.dockerenv").exists()
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def system(platform_name: str | None = None) -> str:
|
|
31
|
+
"""The operating system, as people know it: "macOS 15.1 (Apple Silicon)",
|
|
32
|
+
"Windows 11 (10.0.22631)", "Ubuntu 24.04.1 LTS"."""
|
|
33
|
+
platform_name = platform_name or sys.platform
|
|
34
|
+
machine = platform.machine()
|
|
35
|
+
if platform_name == "darwin":
|
|
36
|
+
chip = "Apple Silicon" if machine == "arm64" else "Intel"
|
|
37
|
+
return f"macOS {platform.mac_ver()[0] or platform.release()} ({chip})"
|
|
38
|
+
if platform_name == "win32":
|
|
39
|
+
return f"Windows {platform.release()} ({platform.version()})"
|
|
40
|
+
try:
|
|
41
|
+
name = platform.freedesktop_os_release().get("PRETTY_NAME")
|
|
42
|
+
except (OSError, AttributeError):
|
|
43
|
+
name = None
|
|
44
|
+
return f"{name or 'Linux ' + platform.release()} ({machine})"
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def log_file() -> Path | None:
|
|
48
|
+
"""The file this app is logging to (station_appkit.applog), or None when
|
|
49
|
+
it logs to the terminal it was started from."""
|
|
50
|
+
for handler in logging.getLogger().handlers:
|
|
51
|
+
name = getattr(handler, "baseFilename", None)
|
|
52
|
+
if name:
|
|
53
|
+
return Path(name)
|
|
54
|
+
return None
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def details(app_name: str, version: str, kind: str | None) -> dict:
|
|
58
|
+
"""What a report says about this copy, and what the app shows beside it."""
|
|
59
|
+
log = log_file()
|
|
60
|
+
docker = kind is None and in_docker()
|
|
61
|
+
about = {
|
|
62
|
+
"app": app_name,
|
|
63
|
+
"version": version,
|
|
64
|
+
"installed": "Docker" if docker else INSTALLED.get(kind, INSTALLED[None]),
|
|
65
|
+
"system": system(),
|
|
66
|
+
"python": platform.python_version(),
|
|
67
|
+
}
|
|
68
|
+
return {**about, "log_file": str(log) if log else None, "in_docker": docker, "issue_url": issue_url(about)}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def issue_url(about: dict) -> str:
|
|
72
|
+
"""A new issue, titled with the app and with its details in the body."""
|
|
73
|
+
body = "\n".join([
|
|
74
|
+
"**What happened**",
|
|
75
|
+
"",
|
|
76
|
+
"",
|
|
77
|
+
"**What I expected**",
|
|
78
|
+
"",
|
|
79
|
+
"",
|
|
80
|
+
"**Steps to make it happen again**",
|
|
81
|
+
"1. ",
|
|
82
|
+
"",
|
|
83
|
+
"---",
|
|
84
|
+
f"- App: {about['app']} {about['version']} ({about['installed']})",
|
|
85
|
+
f"- System: {about['system']}",
|
|
86
|
+
f"- Python: {about['python']}",
|
|
87
|
+
])
|
|
88
|
+
return ISSUES_NEW + "?" + urllib.parse.urlencode({"title": f"[{about['app']}] ", "body": body})
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import logging.handlers
|
|
3
|
+
import urllib.parse
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
from station_appkit import report
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _query(url: str) -> dict:
|
|
11
|
+
base, _, query = url.partition("?")
|
|
12
|
+
assert base == "https://github.com/raby/station-studio/issues/new"
|
|
13
|
+
return {k: v[0] for k, v in urllib.parse.parse_qs(query).items()}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def test_the_issue_has_the_app_version_and_computer_filled_in(monkeypatch):
|
|
17
|
+
monkeypatch.setattr(report, "system", lambda: "macOS 15.1 (Apple Silicon)")
|
|
18
|
+
monkeypatch.setattr(report.platform, "python_version", lambda: "3.12.7")
|
|
19
|
+
got = report.details("Station Player", "0.25.1", "mac")
|
|
20
|
+
assert got["installed"] == "downloaded Mac app"
|
|
21
|
+
q = _query(got["issue_url"])
|
|
22
|
+
assert q["title"] == "[Station Player] "
|
|
23
|
+
assert "- App: Station Player 0.25.1 (downloaded Mac app)" in q["body"]
|
|
24
|
+
assert "- System: macOS 15.1 (Apple Silicon)" in q["body"]
|
|
25
|
+
assert "- Python: 3.12.7" in q["body"]
|
|
26
|
+
assert "**What happened**" in q["body"]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@pytest.fixture(autouse=True)
|
|
30
|
+
def not_in_docker(monkeypatch):
|
|
31
|
+
monkeypatch.setattr(report, "in_docker", lambda: False)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_in_docker_it_says_so(monkeypatch):
|
|
35
|
+
monkeypatch.setattr(report, "in_docker", lambda: True)
|
|
36
|
+
got = report.details("Station Studio", "1.24.0", None)
|
|
37
|
+
assert got["installed"] == "Docker" and got["in_docker"] is True
|
|
38
|
+
assert "(Docker)" in urllib.parse.unquote_plus(got["issue_url"])
|
|
39
|
+
# A downloaded app is never "Docker", whatever the computer has at /.dockerenv.
|
|
40
|
+
assert report.details("Station Studio", "1.24.0", "mac")["in_docker"] is False
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@pytest.mark.parametrize("kind, says", [("windows", "downloaded Windows app"), (None, "installed with pip"),
|
|
44
|
+
("something new", "installed with pip")])
|
|
45
|
+
def test_how_it_was_installed(kind, says):
|
|
46
|
+
assert report.details("Station Server", "0.24.1", kind)["installed"] == says
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def test_the_log_file_is_shown_but_never_put_in_the_issue(tmp_path, monkeypatch):
|
|
50
|
+
log = tmp_path / "Rob" / "station-studio.log"
|
|
51
|
+
log.parent.mkdir()
|
|
52
|
+
handler = logging.handlers.RotatingFileHandler(log, encoding="utf-8")
|
|
53
|
+
root = logging.getLogger()
|
|
54
|
+
monkeypatch.setattr(root, "handlers", [handler])
|
|
55
|
+
try:
|
|
56
|
+
got = report.details("Station Studio", "1.23.1", None)
|
|
57
|
+
assert got["log_file"] == str(log)
|
|
58
|
+
assert "Rob" not in got["issue_url"] and "station-studio.log" not in got["issue_url"]
|
|
59
|
+
finally:
|
|
60
|
+
handler.close()
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def test_no_log_file_when_it_logs_to_the_terminal(monkeypatch):
|
|
64
|
+
monkeypatch.setattr(logging.getLogger(), "handlers", [logging.StreamHandler()])
|
|
65
|
+
assert report.log_file() is None
|
|
66
|
+
assert report.details("Station Studio", "1.23.1", None)["log_file"] is None
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def test_the_system_as_people_know_it(monkeypatch):
|
|
70
|
+
monkeypatch.setattr(report.platform, "machine", lambda: "arm64")
|
|
71
|
+
monkeypatch.setattr(report.platform, "mac_ver", lambda: ("15.1", ("", "", ""), "arm64"))
|
|
72
|
+
assert report.system("darwin") == "macOS 15.1 (Apple Silicon)"
|
|
73
|
+
monkeypatch.setattr(report.platform, "machine", lambda: "x86_64")
|
|
74
|
+
assert report.system("darwin") == "macOS 15.1 (Intel)"
|
|
75
|
+
monkeypatch.setattr(report.platform, "release", lambda: "11")
|
|
76
|
+
monkeypatch.setattr(report.platform, "version", lambda: "10.0.22631")
|
|
77
|
+
assert report.system("win32") == "Windows 11 (10.0.22631)"
|
|
78
|
+
monkeypatch.setattr(report.platform, "freedesktop_os_release", lambda: {"PRETTY_NAME": "Ubuntu 24.04.1 LTS"})
|
|
79
|
+
assert report.system("linux") == "Ubuntu 24.04.1 LTS (x86_64)"
|
|
80
|
+
|
|
81
|
+
def missing():
|
|
82
|
+
raise OSError("no os-release")
|
|
83
|
+
monkeypatch.setattr(report.platform, "freedesktop_os_release", missing)
|
|
84
|
+
monkeypatch.setattr(report.platform, "release", lambda: "6.8.0")
|
|
85
|
+
assert report.system("linux") == "Linux 6.8.0 (x86_64)"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|