apexcodexpy 0.2.1__tar.gz → 0.2.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: apexcodexpy
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Summary: The Non-Destructive Configuration Steward for Python Projects.
5
5
  License-File: LICENSE
6
6
  Author: Apex Dev
@@ -230,9 +230,9 @@ def _(
230
230
  ),
231
231
  ) -> None:
232
232
  (
233
- Codex(target=Path("./tests/integration"))
233
+ Codex(target=Path("."))
234
234
  .ci(on=ci)
235
- .test()
235
+ .test_integration()
236
236
  .report(using=DefaultReporter())
237
237
  .exit(using=typer.Exit)
238
238
  )
@@ -8,34 +8,14 @@ from codex.tasks import ComboResult, DependabotYaml, PyProjectToml, TaskResult
8
8
  from codex.tools import MyPy, Pip, Poetry, Program, Ruff
9
9
 
10
10
 
11
- @dataclass(frozen=True)
12
- class CiMode:
13
- codex: Codex
14
-
15
- def lint(self) -> TaskResult:
16
- return (
17
- ComboResult()
18
- .attach(install=self.codex.install())
19
- .attach(lint=self.codex.lint())
20
- )
21
-
22
- def test(self) -> TaskResult:
23
- return (
24
- ComboResult()
25
- .attach(install=self.codex.install())
26
- .attach(pytest=Poetry().run(Pytest.on(self.codex.target).run()))
27
- )
28
-
29
-
30
11
  @dataclass(frozen=True)
31
12
  class Codex:
32
13
  target: Path
33
14
 
34
- def ci(self, on: bool) -> CiMode | Codex:
35
- if on:
36
- return CiMode(self)
15
+ in_ci: bool = False
37
16
 
38
- return self
17
+ def ci(self, on: bool) -> Codex:
18
+ return Codex(self.target, in_ci=on)
39
19
 
40
20
  def sync(self, dry_run: bool = False) -> TaskResult:
41
21
  return (
@@ -45,10 +25,17 @@ class Codex:
45
25
  )
46
26
 
47
27
  def install(self) -> TaskResult:
28
+ return self._install(when=True)
29
+
30
+ def _install(self, when: bool) -> ComboResult:
48
31
  return (
49
- ComboResult()
50
- .attach(tools=Pip().install("pip", "poetry"))
51
- .attach(dependencies=Poetry().install())
32
+ (
33
+ ComboResult()
34
+ .attach(tools=Pip().install("pip", "poetry"))
35
+ .attach(dependencies=Poetry().install())
36
+ )
37
+ if when
38
+ else ComboResult()
52
39
  )
53
40
 
54
41
  def lock(self) -> TaskResult:
@@ -59,7 +46,7 @@ class Codex:
59
46
 
60
47
  def lint(self) -> TaskResult:
61
48
  return (
62
- ComboResult()
49
+ self._install(when=self.in_ci)
63
50
  .attach(poetry=Poetry().lint(self.target))
64
51
  .attach(black=Poetry().run(Ruff(on=self.target).format().flag(check=True)))
65
52
  .attach(ruff=Poetry().run(Ruff(on=self.target).lint()))
@@ -78,21 +65,16 @@ class Codex:
78
65
  )
79
66
 
80
67
  def test(self) -> TaskResult:
81
- return ComboResult().attach(
82
- pytest=Poetry().run(
83
- Pytest.on(self.target).run(
84
- with_coverage=True,
85
- last_failed=True,
86
- )
87
- )
88
- )
68
+ return self._install(when=self.in_ci).attach(self.test_unit())
69
+
70
+ def test_unit(self) -> TaskResult:
71
+ return CodexTest(self.target).ci(on=self.in_ci).unit()
72
+
73
+ def test_integration(self) -> TaskResult:
74
+ return CodexTest(self.target).integration()
89
75
 
90
76
  def test_behaviour(self) -> TaskResult:
91
- return ComboResult().attach(
92
- behave=Poetry().run(
93
- Program("behave").append(self.target / "tests" / "features")
94
- )
95
- )
77
+ return CodexTest(self.target).behaviour()
96
78
 
97
79
  def build(self, tag: str) -> TaskResult:
98
80
  return (
@@ -121,6 +103,56 @@ class Codex:
121
103
  )
122
104
 
123
105
 
106
+ @dataclass(frozen=True)
107
+ class CodexTest:
108
+ target: Path
109
+
110
+ in_ci: bool = False
111
+
112
+ def ci(self, on: bool = False) -> CodexTest:
113
+ return CodexTest(self.target, in_ci=on)
114
+
115
+ def unit(self) -> TaskResult:
116
+ return ComboResult().attach(
117
+ pytest=Poetry().run(
118
+ Pytest.on(self.target).run(
119
+ with_coverage=self._when_not_in_ci(),
120
+ last_failed=self._when_not_in_ci(),
121
+ )
122
+ )
123
+ )
124
+
125
+ def _when_not_in_ci(self) -> bool | None:
126
+ return None if self.in_ci else True
127
+
128
+ def integration(self) -> TaskResult:
129
+ return (
130
+ ComboResult()
131
+ .attach(
132
+ setup=(
133
+ ComboResult()
134
+ .attach(tools=Pip().install("poetry", "poetry-plugin-export"))
135
+ .attach(export=Poetry().export(self.target))
136
+ )
137
+ )
138
+ .attach(
139
+ pytest=Poetry().run(
140
+ Pytest.on(self.target / "tests" / "integration").run()
141
+ )
142
+ )
143
+ .attach(
144
+ teardown=Program("rm").append(self.target / "requirements.txt").run()
145
+ )
146
+ )
147
+
148
+ def behaviour(self) -> TaskResult:
149
+ return ComboResult().attach(
150
+ behave=Poetry().run(
151
+ Program("behave").append(self.target / "tests" / "features")
152
+ )
153
+ )
154
+
155
+
124
156
  @dataclass(frozen=True)
125
157
  class Pytest:
126
158
  target: Path | None = None
@@ -37,10 +37,19 @@ class ComboResult:
37
37
 
38
38
  def attach(self, *args: TaskResult, **kwargs: TaskResult) -> ComboResult:
39
39
  for name, result in kwargs.items():
40
- self.results.append(result.named(name))
40
+ self._attach_one(result.named(name))
41
41
 
42
42
  for result in args:
43
- self.results.append(result)
43
+ self._attach_one(result)
44
+
45
+ return self
46
+
47
+ def _attach_one(self, result: TaskResult) -> ComboResult:
48
+ match result:
49
+ case ComboResult():
50
+ self.results.extend(result.results)
51
+ case _:
52
+ self.results.append(result)
44
53
 
45
54
  return self
46
55
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "apexcodexpy"
3
- version = "0.2.1"
3
+ version = "0.2.2"
4
4
  description = "The Non-Destructive Configuration Steward for Python Projects."
5
5
  readme = "README.md"
6
6
  authors = [
File without changes
File without changes
File without changes