pixel-puzzle-game 0.4.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.
@@ -0,0 +1,10 @@
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # Virtual environments
10
+ .venv
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Luca Barden
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,124 @@
1
+ Metadata-Version: 2.4
2
+ Name: pixel-puzzle-game
3
+ Version: 0.4.0
4
+ Summary: A pixel art guessing quiz game
5
+ Project-URL: Homepage, https://github.com/luca/Pixel-Puzzle
6
+ Project-URL: Issues, https://github.com/luca/Pixel-Puzzle/issues
7
+ Author: Luca Barden
8
+ License: MIT
9
+ License-File: LICENSE
10
+ Keywords: fastapi,game,pixel-art,quiz
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Framework :: FastAPI
13
+ Classifier: Intended Audience :: End Users/Desktop
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Topic :: Games/Entertainment
19
+ Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
20
+ Requires-Python: >=3.14
21
+ Requires-Dist: fastapi>=0.100.0
22
+ Requires-Dist: python-dotenv>=1.0.0
23
+ Requires-Dist: uvicorn[standard]>=0.20.0
24
+ Provides-Extra: dev
25
+ Requires-Dist: httpx>=0.27.0; extra == 'dev'
26
+ Requires-Dist: pytest>=8.0.0; extra == 'dev'
27
+ Description-Content-Type: text/markdown
28
+
29
+ # Pixel Puzzle
30
+
31
+ A pixel art guessing quiz game. The server reads image files from a folder
32
+ you point it at, exposes a small JSON API listing them, and ships a static
33
+ front-end that turns those images into a guess-the-pixel-art quiz.
34
+
35
+ ## Features
36
+
37
+ - FastAPI backend with a single `/api/images` JSON endpoint.
38
+ - Static front-end (vanilla HTML/CSS/JS) bundled with the package.
39
+ - Long-lived cache headers for versioned assets, `no-cache` for `index.html`.
40
+ - GZip middleware for text payloads.
41
+ - Image-folder caching keyed on directory mtime.
42
+ - Environment-driven configuration (`HOST`, `PORT`, `IMAGE_FOLDER`).
43
+
44
+ ## Requirements
45
+
46
+ - Python 3.14 or newer.
47
+
48
+ ## Installation
49
+
50
+ Install with [`uv`](https://docs.astral.sh/uv/) as a standalone tool:
51
+
52
+ ```bash
53
+ uv tool install pixel-puzzle
54
+ ```
55
+
56
+ Or, alternatively, run it ephemerally:
57
+
58
+ ```bash
59
+ uvx pixel-puzzle
60
+ ```
61
+
62
+ Or, install it into a project virtual environment with:
63
+
64
+ ```bash
65
+ uv add pixel-puzzle
66
+ ```
67
+
68
+ ## Usage
69
+
70
+ Drop pixel art images (`.png`, `.jpg`, `.jpeg`) into a directory, then point
71
+ the server at it via the `IMAGE_FOLDER` environment variable (default: a
72
+ folder named `images` in the current working directory):
73
+
74
+ ```bash
75
+ IMAGE_FOLDER=/path/to/pixel-art pixel-puzzle
76
+ ```
77
+
78
+ Open <http://localhost:8000> and start guessing.
79
+
80
+ ### Configuration
81
+
82
+ | Variable | Default | Description |
83
+ |-----------------|----------------------|------------------------------------------|
84
+ | `HOST` | `0.0.0.0` | Interface for uvicorn to bind. |
85
+ | `PORT` | `8000` | TCP port for the HTTP server. |
86
+ | `IMAGE_FOLDER` | `./images` | Directory scanned for image files. |
87
+
88
+ ## Development
89
+
90
+ Clone the repository and sync the dev environment:
91
+
92
+ ```bash
93
+ git clone https://github.com/luca/Pixel-Puzzle.git
94
+ cd Pixel-Puzzle
95
+ uv sync --extra dev
96
+ ```
97
+
98
+ Run the test suite:
99
+
100
+ ```bash
101
+ uv run pytest
102
+ ```
103
+
104
+ Run the server from a working copy:
105
+
106
+ ```bash
107
+ uv run pixel-puzzle
108
+ ```
109
+
110
+ ## Project layout
111
+
112
+ ```
113
+ src/pixel_puzzle/
114
+ __init__.py
115
+ __main__.py # console-script entry point
116
+ app.py # FastAPI application
117
+ static/ # HTML, JS, CSS, fonts
118
+ tests/
119
+ pyproject.toml
120
+ ```
121
+
122
+ ## License
123
+
124
+ MIT. See the project metadata in `pyproject.toml` for the canonical notice.
@@ -0,0 +1,96 @@
1
+ # Pixel Puzzle
2
+
3
+ A pixel art guessing quiz game. The server reads image files from a folder
4
+ you point it at, exposes a small JSON API listing them, and ships a static
5
+ front-end that turns those images into a guess-the-pixel-art quiz.
6
+
7
+ ## Features
8
+
9
+ - FastAPI backend with a single `/api/images` JSON endpoint.
10
+ - Static front-end (vanilla HTML/CSS/JS) bundled with the package.
11
+ - Long-lived cache headers for versioned assets, `no-cache` for `index.html`.
12
+ - GZip middleware for text payloads.
13
+ - Image-folder caching keyed on directory mtime.
14
+ - Environment-driven configuration (`HOST`, `PORT`, `IMAGE_FOLDER`).
15
+
16
+ ## Requirements
17
+
18
+ - Python 3.14 or newer.
19
+
20
+ ## Installation
21
+
22
+ Install with [`uv`](https://docs.astral.sh/uv/) as a standalone tool:
23
+
24
+ ```bash
25
+ uv tool install pixel-puzzle
26
+ ```
27
+
28
+ Or, alternatively, run it ephemerally:
29
+
30
+ ```bash
31
+ uvx pixel-puzzle
32
+ ```
33
+
34
+ Or, install it into a project virtual environment with:
35
+
36
+ ```bash
37
+ uv add pixel-puzzle
38
+ ```
39
+
40
+ ## Usage
41
+
42
+ Drop pixel art images (`.png`, `.jpg`, `.jpeg`) into a directory, then point
43
+ the server at it via the `IMAGE_FOLDER` environment variable (default: a
44
+ folder named `images` in the current working directory):
45
+
46
+ ```bash
47
+ IMAGE_FOLDER=/path/to/pixel-art pixel-puzzle
48
+ ```
49
+
50
+ Open <http://localhost:8000> and start guessing.
51
+
52
+ ### Configuration
53
+
54
+ | Variable | Default | Description |
55
+ |-----------------|----------------------|------------------------------------------|
56
+ | `HOST` | `0.0.0.0` | Interface for uvicorn to bind. |
57
+ | `PORT` | `8000` | TCP port for the HTTP server. |
58
+ | `IMAGE_FOLDER` | `./images` | Directory scanned for image files. |
59
+
60
+ ## Development
61
+
62
+ Clone the repository and sync the dev environment:
63
+
64
+ ```bash
65
+ git clone https://github.com/luca/Pixel-Puzzle.git
66
+ cd Pixel-Puzzle
67
+ uv sync --extra dev
68
+ ```
69
+
70
+ Run the test suite:
71
+
72
+ ```bash
73
+ uv run pytest
74
+ ```
75
+
76
+ Run the server from a working copy:
77
+
78
+ ```bash
79
+ uv run pixel-puzzle
80
+ ```
81
+
82
+ ## Project layout
83
+
84
+ ```
85
+ src/pixel_puzzle/
86
+ __init__.py
87
+ __main__.py # console-script entry point
88
+ app.py # FastAPI application
89
+ static/ # HTML, JS, CSS, fonts
90
+ tests/
91
+ pyproject.toml
92
+ ```
93
+
94
+ ## License
95
+
96
+ MIT. See the project metadata in `pyproject.toml` for the canonical notice.
@@ -0,0 +1,56 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "pixel-puzzle-game"
7
+ version = "0.4.0"
8
+ description = "A pixel art guessing quiz game"
9
+ readme = "README.md"
10
+ requires-python = ">=3.14"
11
+ license = { text = "MIT" }
12
+ authors = [{ name = "Luca Barden" }]
13
+ keywords = ["pixel-art", "game", "quiz", "fastapi"]
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "Framework :: FastAPI",
17
+ "Intended Audience :: End Users/Desktop",
18
+ "License :: OSI Approved :: MIT License",
19
+ "Operating System :: OS Independent",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3.14",
22
+ "Topic :: Games/Entertainment",
23
+ "Topic :: Internet :: WWW/HTTP :: HTTP Servers",
24
+ ]
25
+ dependencies = [
26
+ "fastapi>=0.100.0",
27
+ "uvicorn[standard]>=0.20.0",
28
+ "python-dotenv>=1.0.0",
29
+ ]
30
+
31
+ [project.optional-dependencies]
32
+ dev = [
33
+ "pytest>=8.0.0",
34
+ "httpx>=0.27.0",
35
+ ]
36
+
37
+ [project.scripts]
38
+ pixel-puzzle = "pixel_puzzle.__main__:main"
39
+
40
+ [project.urls]
41
+ Homepage = "https://github.com/luca/Pixel-Puzzle"
42
+ Issues = "https://github.com/luca/Pixel-Puzzle/issues"
43
+
44
+ [tool.hatch.build.targets.wheel]
45
+ packages = ["src/pixel_puzzle"]
46
+
47
+ [tool.hatch.build.targets.sdist]
48
+ include = [
49
+ "src/pixel_puzzle",
50
+ "README.md",
51
+ "LICENSE",
52
+ "pyproject.toml",
53
+ ]
54
+
55
+ [tool.pytest.ini_options]
56
+ testpaths = ["tests"]
@@ -0,0 +1,7 @@
1
+ """Pixel Puzzle — a pixel art guessing quiz game."""
2
+
3
+ from __future__ import annotations
4
+
5
+ __version__ = "0.2.0"
6
+
7
+ __all__ = ["__version__"]
@@ -0,0 +1,22 @@
1
+ """Console-script entry point: ``pixel-puzzle``."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import logging
6
+ import os
7
+
8
+ import uvicorn
9
+
10
+ logger = logging.getLogger("pixel_puzzle")
11
+
12
+
13
+ def main() -> None:
14
+ """Start the FastAPI app under uvicorn."""
15
+ host = os.getenv("HOST", "0.0.0.0")
16
+ port = int(os.getenv("PORT", "8000"))
17
+ logger.info(f"Starting server on {host}:{port}")
18
+ uvicorn.run("pixel_puzzle.app:app", host=host, port=port, reload=False)
19
+
20
+
21
+ if __name__ == "__main__":
22
+ main()
@@ -0,0 +1,125 @@
1
+ """FastAPI application for the Pixel Puzzle game.
2
+
3
+ Static assets (HTML, JS, CSS, fonts) are shipped inside the package and
4
+ resolved at runtime via :mod:`importlib.resources`, so the app works both
5
+ from a working copy and from an installed wheel.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import logging
11
+ import os
12
+ from importlib.resources import files
13
+
14
+ from dotenv import load_dotenv
15
+ from fastapi import FastAPI
16
+ from fastapi.middleware.gzip import GZipMiddleware
17
+ from fastapi.responses import FileResponse, HTMLResponse, JSONResponse
18
+ from fastapi.staticfiles import StaticFiles
19
+ from starlette.responses import Response
20
+ from starlette.staticfiles import StaticFiles as StarletteStaticFiles
21
+
22
+ load_dotenv()
23
+
24
+ logging.basicConfig(
25
+ level=logging.INFO,
26
+ format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
27
+ )
28
+ logger = logging.getLogger("pixel_puzzle")
29
+
30
+ # Location of the bundled `static/` directory inside the installed package.
31
+ STATIC_DIR = files("pixel_puzzle").joinpath("static")
32
+
33
+ # Allow operators to point at a directory of images outside the package.
34
+ IMAGE_FOLDER = os.getenv("IMAGE_FOLDER", os.path.join(os.getcwd(), "images"))
35
+
36
+ _images_cache: list[str] | None = None
37
+ _images_cache_mtime: float | None = None
38
+
39
+ CACHE_IMMUTABLE = "public, max-age=31536000, immutable"
40
+ CACHE_NO_CACHE = "no-cache"
41
+
42
+
43
+ class CachedStaticFiles(StarletteStaticFiles):
44
+ """StaticFiles with long-lived cache headers for versioned assets."""
45
+
46
+ async def get_response(self, path: str, scope) -> Response:
47
+ response = await super().get_response(path, scope)
48
+ if response.status_code == 200:
49
+ response.headers["Cache-Control"] = CACHE_IMMUTABLE
50
+ return response
51
+
52
+
53
+ app = FastAPI(title="Pixel Puzzle")
54
+ app.add_middleware(GZipMiddleware, minimum_size=512)
55
+
56
+ if not os.path.exists(IMAGE_FOLDER):
57
+ try:
58
+ os.makedirs(IMAGE_FOLDER, exist_ok=True)
59
+ logger.info(f"Created missing image directory at: {IMAGE_FOLDER}")
60
+ except Exception as e:
61
+ logger.error(f"Could not create image directory {IMAGE_FOLDER}: {e}")
62
+
63
+ app.mount("/static", CachedStaticFiles(directory=str(STATIC_DIR)), name="static")
64
+
65
+ if os.path.exists(IMAGE_FOLDER):
66
+ app.mount("/images", StaticFiles(directory=IMAGE_FOLDER), name="images")
67
+ else:
68
+ logger.warning(
69
+ f"Image folder {IMAGE_FOLDER} does not exist. /images path will not be mounted properly."
70
+ )
71
+
72
+
73
+ def get_images_list() -> list[str]:
74
+ global _images_cache, _images_cache_mtime
75
+
76
+ if not os.path.exists(IMAGE_FOLDER):
77
+ logger.warning(f"Image folder {IMAGE_FOLDER} does not exist.")
78
+ return []
79
+
80
+ try:
81
+ folder_mtime = os.path.getmtime(IMAGE_FOLDER)
82
+ if _images_cache is not None and _images_cache_mtime == folder_mtime:
83
+ return _images_cache
84
+
85
+ files_in_dir = sorted(os.listdir(IMAGE_FOLDER))
86
+ _images_cache = [
87
+ f"/images/{f}"
88
+ for f in files_in_dir
89
+ if f.lower().endswith((".png", ".jpg", ".jpeg"))
90
+ ]
91
+ _images_cache_mtime = folder_mtime
92
+ return _images_cache
93
+ except Exception as e:
94
+ logger.error(f"Error reading image folder {IMAGE_FOLDER}: {e}")
95
+ return []
96
+
97
+
98
+ @app.get("/", response_class=HTMLResponse)
99
+ def index():
100
+ index_path = STATIC_DIR.joinpath("index.html")
101
+ if index_path.is_file():
102
+ return FileResponse(str(index_path), headers={"Cache-Control": CACHE_NO_CACHE})
103
+ return HTMLResponse(
104
+ "<html><body><h1>Pixel Puzzle</h1>"
105
+ "<p>Frontend template not found.</p></body></html>",
106
+ status_code=404,
107
+ )
108
+
109
+
110
+ @app.get("/favicon.ico", include_in_schema=False)
111
+ def favicon():
112
+ favicon_path = STATIC_DIR.joinpath("favicon.svg")
113
+ if favicon_path.is_file():
114
+ return FileResponse(
115
+ str(favicon_path),
116
+ media_type="image/svg+xml",
117
+ headers={"Cache-Control": CACHE_IMMUTABLE},
118
+ )
119
+ return HTMLResponse(status_code=404)
120
+
121
+
122
+ @app.get("/api/images")
123
+ def api_images():
124
+ images = get_images_list()
125
+ return JSONResponse(content={"images": images})