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

SPF-OST / pytrnsys_gui / 11662562960

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

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

86.57
/trnsysGUI/configFileUpdater.py
1
from __future__ import annotations
1✔
2

3
import collections.abc as _cabc
1✔
4
import functools as _ft
1✔
5
import pathlib as _pl
1✔
6

7

8
class ConfigFileUpdater:
1✔
9
    def __init__(self, configFilePath: _pl.Path) -> None:  # type: ignore[name-defined]
1✔
10
        self._configFilePath = configFilePath
1✔
11

12
        configFileContents = _pl.Path(self._configFilePath).read_text("UTF8")
1✔
13
        self.lines = configFileContents.splitlines()
1✔
14

15
    def statementChecker(self, keyword: str) -> int:
1✔
16
        for i, line in enumerate(self.lines):
1✔
17
            if keyword in line:
1✔
18
                return i
×
19
        return -1
1✔
20

21
    def updateConfig(self):
1✔
22
        self.lines = [l for l in self.lines if not l.startswith("PROJECT$ ")]
1✔
23

24
        lineNameRef = self.statementChecker("string nameRef")
1✔
25
        projectDirName = self._projectDirPath.name
1✔
26
        if lineNameRef == -1:
1✔
27
            self.lines.append(f'string nameRef "{projectDirName}"')
1✔
28
        else:
29
            self.lines[lineNameRef] = f'string nameRef "{projectDirName}"'
×
30

31
        ddckDirPath = self._projectDirPath / "ddck"
1✔
32

33
        linePaths = self.statementChecker("#PATHS#")
1✔
34
        if linePaths == -1:
1✔
35
            self.lines.append(
1✔
36
                f'''\
37

38
"##################PATHS##################"
39

40
string PROJECT$ "{ddckDirPath}"'''
41
            )
42
        else:
43
            lineProjectPathDdck = self.statementChecker("PROJECT$ ")
×
44
            if lineProjectPathDdck == -1:
×
45
                self.lines.append(f'string PROJECT$ "{ddckDirPath}"')
×
46
            else:
NEW
47
                self.lines[lineProjectPathDdck] = (
×
48
                    f'string PROJECT$ "{ddckDirPath}"'
49
                )
50

51
        lineProjectPath = self.statementChecker("string projectPath")
1✔
52
        if lineProjectPath == -1:
1✔
53
            self.lines.append(f'string projectPath "{self._projectDirPath}"')
1✔
54
        else:
NEW
55
            self.lines[lineProjectPath] = (
×
56
                f'string projectPath "{self._projectDirPath}"'
57
            )
58

59
        lineDdck = self.statementChecker("USED DDCKs")
1✔
60
        if lineDdck == -1:
1✔
61
            self.lines.append("\n#############USED DDCKs##################\n")
1✔
62
            lineDdck = len(self.lines) - 2
1✔
63

64
        sortedDdckFilePaths = self._getSortedDdckFilePaths(ddckDirPath)
1✔
65

66
        for i, ddckFilePath in enumerate(sortedDdckFilePaths):
1✔
67
            ddckFilePathWithoutSuffix = ddckFilePath.with_suffix("")
1✔
68
            self.lines.insert(
1✔
69
                lineDdck + 2 + i, f"PROJECT$ {ddckFilePathWithoutSuffix}"
70
            )
71

72
        newConfigFileContents = "\n".join(self.lines)
1✔
73
        self._configFilePath.write_text(newConfigFileContents)
1✔
74

75
    @staticmethod
1✔
76
    def _getSortedDdckFilePaths(
1✔
77
        ddckDirPath: _pl.Path,
78
    ) -> _cabc.Sequence[_pl.Path]:
79
        @_ft.cmp_to_key
1✔
80
        def cmpHeadFirstEndLast(path1: _pl.Path, path2: _pl.Path) -> int:
1✔
81
            stem1 = path1.stem
1✔
82
            stem2 = path2.stem
1✔
83

84
            if stem1 == "head" and stem2 != "head":
1✔
85
                return -1
1✔
86
            if stem1 != "head" and stem2 == "head":
1✔
87
                return 1
×
88
            if stem1 == "end" and stem2 != "end":
1✔
89
                return 1
1✔
90
            if stem1 != "end" and stem2 == "end":
1✔
91
                return -1
1✔
92

93
            if path1 == path2:
1✔
94
                return 0
×
95

96
            return -1 if str(path1) < str(path2) else 1
1✔
97

98
        absoluteDdckFilePaths = ddckDirPath.rglob("*.ddck")
1✔
99
        relativeDdckFilePaths = [
1✔
100
            p.relative_to(ddckDirPath) for p in absoluteDdckFilePaths
101
        ]
102
        sortedDdckFilePaths = sorted(
1✔
103
            relativeDdckFilePaths, key=cmpHeadFirstEndLast
104
        )
105
        return sortedDdckFilePaths
1✔
106

107
    @property
1✔
108
    def _projectDirPath(self) -> _pl.Path:
1✔
109
        return self._configFilePath.parent
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