quizzy 0.3.1__tar.gz → 0.4.0__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,10 @@
1
1
 
2
2
  # Changelog
3
3
 
4
+ ## v0.4.0
5
+
6
+ * Add `--serve` flag to serve the application in a browser
7
+
4
8
  ## v0.3.1
5
9
 
6
10
  * Fixed the lockfile for this version
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: quizzy
3
- Version: 0.3.1
3
+ Version: 0.4.0
4
4
  Summary: A Python TUI quiz app
5
5
  Author-email: Jonas Ehrlich <jonas.ehrlich@gmail.com>
6
6
  License-Expression: MIT
@@ -8,6 +8,7 @@ License-File: LICENSE
8
8
  Requires-Python: >=3.10
9
9
  Requires-Dist: pydantic>=2.10.3
10
10
  Requires-Dist: pyyaml>=6.0.2
11
+ Requires-Dist: textual-serve>=1.1.1
11
12
  Requires-Dist: textual>=1.0.0
12
13
  Description-Content-Type: text/markdown
13
14
 
@@ -63,7 +64,7 @@ uv run quizzy examples/quizzy.yaml
63
64
  Serve on a webserver using textual:
64
65
 
65
66
  ``` sh
66
- uv run textual serve "uv run quizzy examples/quizzy.yaml"
67
+ uvx quizzy --serve examples/quizzy.yaml
67
68
  ```
68
69
 
69
70
  Run in development mode:
@@ -50,7 +50,7 @@ uv run quizzy examples/quizzy.yaml
50
50
  Serve on a webserver using textual:
51
51
 
52
52
  ``` sh
53
- uv run textual serve "uv run quizzy examples/quizzy.yaml"
53
+ uvx quizzy --serve examples/quizzy.yaml
54
54
  ```
55
55
 
56
56
  Run in development mode:
@@ -1,12 +1,17 @@
1
1
 
2
2
  [project]
3
3
  name = "quizzy"
4
- version = "0.3.1"
4
+ version = "0.4.0"
5
5
  description = "A Python TUI quiz app"
6
6
  authors = [{ name = "Jonas Ehrlich", email = "jonas.ehrlich@gmail.com" }]
7
7
  readme = "README.md"
8
8
  requires-python = ">=3.10"
9
- dependencies = ["pydantic>=2.10.3", "pyyaml>=6.0.2", "textual>=1.0.0"]
9
+ dependencies = [
10
+ "pydantic>=2.10.3",
11
+ "pyyaml>=6.0.2",
12
+ "textual-serve>=1.1.1",
13
+ "textual>=1.0.0",
14
+ ]
10
15
  license = "MIT"
11
16
 
12
17
  [project.scripts]
@@ -0,0 +1,3 @@
1
+ from quizzy.app import main
2
+
3
+ main()
@@ -2,22 +2,18 @@ from __future__ import annotations
2
2
 
3
3
  import argparse
4
4
  import pathlib
5
+ import shlex
6
+ import sys
7
+ from typing import NoReturn
5
8
 
6
9
  from textual import app, binding, containers, log, message, reactive, screen, widgets
10
+ from textual_serve import server
7
11
 
8
12
  from quizzy import __version__, models
9
13
 
10
14
  NoCorrectAnswerType = type("NoCorrectAnswerType", (object,), {})
11
15
  NoCorrectAnswer = NoCorrectAnswerType()
12
16
 
13
-
14
- def get_arg_parser() -> argparse.ArgumentParser:
15
- parser = argparse.ArgumentParser(prog=__name__.split(".")[0], description="A terminal quiz app")
16
- parser.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
17
- parser.add_argument("quizfile", type=pathlib.Path, help="Quiz file")
18
- return parser
19
-
20
-
21
17
  QuestionScreenResult = models.Team | NoCorrectAnswerType | None
22
18
 
23
19
 
@@ -230,12 +226,9 @@ class QuestionBoard(containers.HorizontalGroup):
230
226
  class QuizzyApp(app.App[None]):
231
227
  CSS_PATH = "quizzy.tcss"
232
228
 
233
- def __init__(self) -> None:
229
+ def __init__(self, config: models.Config) -> None:
234
230
  super().__init__()
235
- parser = get_arg_parser()
236
- namespace = parser.parse_args()
237
-
238
- self.config = models.load_config(namespace.quizfile)
231
+ self.config = config
239
232
  self.scoreboard_widget = Scoreboard(self.config.teams)
240
233
 
241
234
  def compose(self) -> app.ComposeResult:
@@ -248,3 +241,33 @@ class QuizzyApp(app.App[None]):
248
241
 
249
242
  def on_mount(self) -> None:
250
243
  self.theme = "textual-light"
244
+
245
+
246
+ def get_arg_parser() -> argparse.ArgumentParser:
247
+ parser = argparse.ArgumentParser(prog=__name__.split(".")[0], description="A terminal quiz app")
248
+ parser.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
249
+
250
+ serve_group = parser.add_argument_group("Serve options")
251
+ serve_group.add_argument("--serve", action="store_true", help="Serve the app through the browser")
252
+ serve_group.add_argument("--host", default="localhost", help="Host to serve the app on")
253
+ serve_group.add_argument("--port", type=int, default=8000, help="Port to serve the app on")
254
+
255
+ parser.add_argument("quizfile", type=pathlib.Path, help="Quiz file")
256
+ return parser
257
+
258
+
259
+ def main() -> NoReturn:
260
+ parser = get_arg_parser()
261
+ namespace = parser.parse_args()
262
+
263
+ if namespace.serve:
264
+ # The --serve flag is set, drop it from the args and serve the app instead through textual-serve
265
+ args = list(sys.argv)
266
+ args.remove("--serve")
267
+
268
+ server.Server(shlex.join(args), host=namespace.host, port=namespace.port).serve()
269
+ else:
270
+ config = models.load_config(namespace.quizfile)
271
+ app = QuizzyApp(config)
272
+ app.run()
273
+ sys.exit(0)
@@ -840,12 +840,13 @@ wheels = [
840
840
 
841
841
  [[package]]
842
842
  name = "quizzy"
843
- version = "0.3.1"
843
+ version = "0.4.0"
844
844
  source = { editable = "." }
845
845
  dependencies = [
846
846
  { name = "pydantic" },
847
847
  { name = "pyyaml" },
848
848
  { name = "textual" },
849
+ { name = "textual-serve" },
849
850
  ]
850
851
 
851
852
  [package.dev-dependencies]
@@ -863,6 +864,7 @@ requires-dist = [
863
864
  { name = "pydantic", specifier = ">=2.10.3" },
864
865
  { name = "pyyaml", specifier = ">=6.0.2" },
865
866
  { name = "textual", specifier = ">=1.0.0" },
867
+ { name = "textual-serve", specifier = ">=1.1.1" },
866
868
  ]
867
869
 
868
870
  [package.metadata.requires-dev]
@@ -1,9 +0,0 @@
1
- from quizzy.app import QuizzyApp
2
-
3
-
4
- def main() -> None:
5
- QuizzyApp().run()
6
-
7
-
8
- if __name__ == "__main__":
9
- main()
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