• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SPF-OST / pytrnsys_gui / 11576810878

29 Oct 2024 03:09PM UTC coverage: 67.508% (-0.08%) from 67.591%
11576810878

push

github

web-flow
Merge pull request #564 from SPF-OST/560-black-change-line-length-to-pep8-standard-of-79-and-check-ci-reaction

changed line length in black to 79

1054 of 1475 new or added lines in 174 files covered. (71.46%)

150 existing lines in 74 files now uncovered.

10399 of 15404 relevant lines covered (67.51%)

0.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.61
/trnsysGUI/settings.py
1
# pylint: skip-file
2
# type: ignore
3

4
import dataclasses as _dc
1✔
5
import pathlib as _pl
1✔
6
import typing as _tp
1✔
7
import uuid as _uuid
1✔
8

9
import appdirs as _ad
1✔
10

11
import pytrnsys.utils.serialization as _ser
1✔
12

13

14
@_dc.dataclass
1✔
15
class SettingsVersion0(_ser.UpgradableJsonSchemaMixinVersion0):
1✔
16
    @classmethod
1✔
17
    def getVersion(cls) -> _uuid.UUID:
1✔
18
        return _uuid.UUID("f7a2c37c-ce82-4a4a-9869-80f00083275b")
1✔
19

20
    trnsysBinaryDirPath: str
1✔
21

22

23
@_dc.dataclass
1✔
24
class SettingsVersion1(_ser.UpgradableJsonSchemaMixin):
1✔
25
    @classmethod
1✔
26
    def getVersion(cls) -> _uuid.UUID:
1✔
27
        return _uuid.UUID("e5ea1fbd-1be9-4415-b3e9-7f3a2a11d216")
1✔
28

29
    trnsysBinaryPath: str
1✔
30

31
    @classmethod
1✔
32
    def getSupersededClass(cls) -> _tp.Type[SettingsVersion0]:
1✔
33
        return SettingsVersion0
1✔
34

35
    @classmethod
1✔
36
    def upgrade(cls, superseded: SettingsVersion0) -> "Settings":
1✔
NEW
37
        trnsysBinaryPath = (
×
38
            _pl.Path(superseded.trnsysBinaryDirPath) / "TRNExe.exe"
39
        )
UNCOV
40
        return Settings.create(trnsysBinaryPath)
×
41

42

43
@_dc.dataclass
1✔
44
class Settings(_ser.UpgradableJsonSchemaMixin):
1✔
45
    @staticmethod
1✔
46
    def create(
1✔
47
        trnsysBinaryDirPath: _pl.Path, recentProjects: list[_pl.Path]
48
    ) -> "Settings":
UNCOV
49
        return Settings(str(trnsysBinaryDirPath), list(recentProjects))
×
50

51
    _SETTINGS_FILE_NAME = "settings.json"
1✔
52

53
    trnsysBinaryPath: str
1✔
54

55
    recentProjects: list
1✔
56

57
    @classmethod
1✔
58
    def tryLoadOrNone(cls) -> _tp.Optional["Settings"]:
1✔
59
        settingsFilePath = cls._getSettingsFilePath()
1✔
60

61
        if not settingsFilePath.exists():
1✔
62
            return None
×
63

64
        data = settingsFilePath.read_text()
1✔
65

66
        return Settings.from_json(data)
1✔
67

68
    @classmethod
1✔
69
    def load(cls) -> "Settings":
1✔
70
        settings = cls.tryLoadOrNone()
1✔
71

72
        if not settings:
1✔
73
            raise RuntimeError("No settings found.")
×
74

75
        return settings
1✔
76

77
    def save(self) -> None:
1✔
78
        settingsFilePath = self._getSettingsFilePath()
×
79

80
        settingsDirPath = settingsFilePath.parent
×
81
        if not settingsDirPath.exists():
×
82
            settingsDirPath.mkdir(parents=True)
×
83

84
        data = self.to_json(indent=4)
×
85
        settingsFilePath.write_text(data)
×
86

87
    @classmethod
1✔
88
    def _getSettingsFilePath(cls) -> _pl.Path:
1✔
NEW
89
        userConfigDirPath = _pl.Path(
×
90
            _ad.user_config_dir("pytrnsys-gui", "SPF OST")
91
        )
92
        settingsFilePath = userConfigDirPath / cls._SETTINGS_FILE_NAME
×
93
        return settingsFilePath
×
94

95
    @classmethod
1✔
96
    def getSupersededClass(cls) -> _tp.Type[SettingsVersion1]:
1✔
97
        return SettingsVersion1
1✔
98

99
    @classmethod
1✔
100
    def upgrade(cls, superseded: SettingsVersion1) -> "Settings":
1✔
101
        return Settings.create(_pl.Path(superseded.trnsysBinaryPath), [])
×
102

103
    @classmethod
1✔
104
    def getVersion(cls) -> _uuid.UUID:
1✔
105
        return _uuid.UUID("c49c052a-f41a-481f-9849-2f6e7185e3cd")
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc