django-wordsearch 0.1.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.
Files changed (28) hide show
  1. django_wordsearch-0.1.0/.github/dependabot.yml +13 -0
  2. django_wordsearch-0.1.0/.github/workflows/ci.yml +36 -0
  3. django_wordsearch-0.1.0/.github/workflows/release.yml +23 -0
  4. django_wordsearch-0.1.0/.gitignore +8 -0
  5. django_wordsearch-0.1.0/CHANGELOG.md +12 -0
  6. django_wordsearch-0.1.0/LICENSE +28 -0
  7. django_wordsearch-0.1.0/PKG-INFO +131 -0
  8. django_wordsearch-0.1.0/README.md +104 -0
  9. django_wordsearch-0.1.0/pyproject.toml +56 -0
  10. django_wordsearch-0.1.0/src/wordsearch/__init__.py +1 -0
  11. django_wordsearch-0.1.0/src/wordsearch/apps.py +6 -0
  12. django_wordsearch-0.1.0/src/wordsearch/conf.py +41 -0
  13. django_wordsearch-0.1.0/src/wordsearch/puzzle.py +308 -0
  14. django_wordsearch-0.1.0/src/wordsearch/static/wordsearch/wordsearch.css +96 -0
  15. django_wordsearch-0.1.0/src/wordsearch/templates/wordsearch/_about.html +1 -0
  16. django_wordsearch-0.1.0/src/wordsearch/templates/wordsearch/_assets.html +1 -0
  17. django_wordsearch-0.1.0/src/wordsearch/templates/wordsearch/_crumbs_root.html +1 -0
  18. django_wordsearch-0.1.0/src/wordsearch/templates/wordsearch/maker.html +66 -0
  19. django_wordsearch-0.1.0/src/wordsearch/templates/wordsearch/page.html +23 -0
  20. django_wordsearch-0.1.0/src/wordsearch/templates/wordsearch/solver.html +47 -0
  21. django_wordsearch-0.1.0/src/wordsearch/urls.py +10 -0
  22. django_wordsearch-0.1.0/src/wordsearch/views.py +204 -0
  23. django_wordsearch-0.1.0/tests/__init__.py +0 -0
  24. django_wordsearch-0.1.0/tests/settings.py +25 -0
  25. django_wordsearch-0.1.0/tests/test_puzzle.py +89 -0
  26. django_wordsearch-0.1.0/tests/test_views.py +115 -0
  27. django_wordsearch-0.1.0/tests/urls.py +3 -0
  28. django_wordsearch-0.1.0/uv.lock +167 -0
@@ -0,0 +1,13 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: uv
4
+ directory: /
5
+ schedule:
6
+ interval: weekly
7
+ - package-ecosystem: github-actions
8
+ directory: /
9
+ schedule:
10
+ interval: weekly
11
+ groups:
12
+ actions:
13
+ patterns: ["*"]
@@ -0,0 +1,36 @@
1
+ name: CI
2
+
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches: [main]
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ test:
13
+ runs-on: ubuntu-latest
14
+ strategy:
15
+ fail-fast: false
16
+ matrix:
17
+ python: ["3.12", "3.13", "3.14"]
18
+ django: ["5.2", "6.0", "6.1"]
19
+ steps:
20
+ - uses: actions/checkout@v7
21
+ - uses: astral-sh/setup-uv@v7
22
+ with:
23
+ python-version: ${{ matrix.python }}
24
+ - run: uv sync --group dev
25
+ - run: uv pip install "django~=${{ matrix.django }}.0"
26
+ - run: uv run --no-sync ruff check .
27
+ - run: uv run --no-sync ruff format --check .
28
+ - run: uv run --no-sync pytest
29
+
30
+ build:
31
+ runs-on: ubuntu-latest
32
+ steps:
33
+ - uses: actions/checkout@v7
34
+ - uses: astral-sh/setup-uv@v7
35
+ - run: uv build
36
+ - run: uvx twine check --strict dist/*
@@ -0,0 +1,23 @@
1
+ # Publishes a release to PyPI when a tag such as v0.2.0 is pushed, by trusted
2
+ # publishing (no token is stored): on PyPI, the project's publisher is this
3
+ # repository, this workflow (release.yml) and the environment "pypi".
4
+ name: Release
5
+
6
+ on:
7
+ push:
8
+ tags: ["v*"]
9
+
10
+ jobs:
11
+ publish:
12
+ runs-on: ubuntu-latest
13
+ environment: pypi
14
+ permissions:
15
+ contents: read
16
+ id-token: write
17
+ steps:
18
+ - uses: actions/checkout@v7
19
+ - uses: astral-sh/setup-uv@v7
20
+ - name: The tag matches the version in pyproject.toml
21
+ run: test "v$(uv version --short)" = "$GITHUB_REF_NAME"
22
+ - run: uv build
23
+ - run: uv publish --trusted-publishing always
@@ -0,0 +1,8 @@
1
+ __pycache__/
2
+ *.py[co]
3
+ .venv/
4
+ build/
5
+ dist/
6
+ *.egg-info/
7
+ .pytest_cache/
8
+ .ruff_cache/
@@ -0,0 +1,12 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 (24 November 2026)
4
+
5
+ The first release, from the app that runs at https://scipython.com/apps/wordsearch/.
6
+
7
+ - A maker: words hidden in a rectangular or shaped (circle or squares) grid at three difficulties, by a depth-first search with restarts and a time limit, with the other cells filled with letters drawn from the words.
8
+ - A link to each puzzle, which holds its seed and makes it again; the puzzle and its solution, with each word ringed, as SVG images; a printed page of just the puzzle and its words.
9
+ - A solver: every occurrence of each word, in all eight directions, ringed on the grid and listed by row, column and direction.
10
+ - An optional rate limit on the maker, by the visitor's address, with a hook for sites behind a proxy.
11
+ - Templates and a stylesheet with no dependence on a CSS framework, in the page's colours and font unless a site sets its own.
12
+ - `wordsearch.puzzle`, which makes, solves and draws puzzles with only Python's standard library.
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2026, Christian Hill
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,131 @@
1
+ Metadata-Version: 2.5
2
+ Name: django-wordsearch
3
+ Version: 0.1.0
4
+ Summary: Word search puzzles for Django sites: a maker, with shaped grids, difficulties and solutions, and a solver.
5
+ Project-URL: Homepage, https://github.com/xnx/django-wordsearch
6
+ Project-URL: Changelog, https://github.com/xnx/django-wordsearch/blob/main/CHANGELOG.md
7
+ Author: Christian Hill
8
+ License-Expression: BSD-3-Clause
9
+ License-File: LICENSE
10
+ Keywords: django,puzzle,word search,wordsearch
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Environment :: Web Environment
13
+ Classifier: Framework :: Django
14
+ Classifier: Framework :: Django :: 5.2
15
+ Classifier: Framework :: Django :: 6.0
16
+ Classifier: Framework :: Django :: 6.1
17
+ Classifier: Intended Audience :: Education
18
+ Classifier: Operating System :: OS Independent
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
+ Classifier: Topic :: Games/Entertainment :: Puzzle Games
24
+ Requires-Python: >=3.12
25
+ Requires-Dist: django>=5.2
26
+ Description-Content-Type: text/markdown
27
+
28
+ # django-wordsearch
29
+
30
+ The django-wordsearch package adds a word search maker and solver to a Django site. A *word search puzzle* hides a list of words in a grid of letters, each along a straight line of cells, among letters that fill the rest of the grid. The maker hides the words that a visitor enters, in a rectangular or shaped grid, at one of three difficulties, and shows the puzzle with its solution, in which each word is ringed. The solver finds the words in a puzzle that a visitor already has, reading in any of the eight directions.
31
+
32
+ The package needs Python 3.12 or later and Django 5.2 or later, and has no other dependencies. It stores nothing, so it has no models or migrations. It runs at https://scipython.com/apps/wordsearch/, and its method is described in the blog post [Word search puzzles](https://scipython.com/blog/making-a-word-search-puzzle-in-python/).
33
+
34
+ ## Installation
35
+
36
+ ```bash
37
+ pip install django-wordsearch
38
+ ```
39
+
40
+ Add the app to `INSTALLED_APPS` and include its URLs:
41
+
42
+ ```python
43
+ INSTALLED_APPS = [
44
+ ...,
45
+ "wordsearch",
46
+ ]
47
+ ```
48
+
49
+ ```python
50
+ urlpatterns = [
51
+ ...,
52
+ path("wordsearch/", include("wordsearch.urls")),
53
+ ]
54
+ ```
55
+
56
+ The maker is then at `wordsearch/` and the solver at `wordsearch/solve/` (the URL names `wordsearch:maker` and `wordsearch:solver`).
57
+
58
+ ## Maker
59
+
60
+ The maker takes a list of words, one on each line or separated by commas, the numbers of rows and columns, a shape and a difficulty. Spaces and other characters that are not letters are left out of the grid, so that NEW YORK is written NEWYORK. The shapes are a rectangle, a circle (the largest that fits in the grid) and *squares* (the grid with its margin cut away except at its corners). At the easy difficulty, words read right or down; at medium, also diagonally down or up to the right; at hard, in all eight directions, so that words may also read backwards.
61
+
62
+ The words are placed longest first by a depth-first search: each word is put in the first place where it fits and, if a word fits nowhere, the word before it is moved to its next place. A search that has made twice as many placements as there are words is begun afresh in a new random order, until `WORDSEARCH_TIME_LIMIT`. The other cells are filled with letters drawn at random from the words themselves, in proportion to their frequency in them, so that the filler cannot be told from the words by its letters.
63
+
64
+ The maker is a GET form, and each puzzle is made with a random seed, so that the link to a puzzle, which holds the seed, makes the same puzzle again. The puzzle and its solution can be downloaded as SVG images, black on white, and a printed page shows only the puzzle and its words.
65
+
66
+ ## Solver
67
+
68
+ The solver takes a grid, one row on each line, and a list of words. A row's letters may be written together (`SNMEHJU`) or separated by spaces (`S N M E H J U`, as the maker's text output and many printed puzzles have them); a blank cell in a shaped grid is any character that is not a letter, or a space between spaced letters. It finds every occurrence of each word, in all eight directions, rings them on the grid, and lists the row, column and direction of each. A word that reads the same both ways, such as a palindrome, is counted once. The solver is a POST form, since a grid can be too long for an address.
69
+
70
+ ## Settings
71
+
72
+ | Setting | Default | Meaning |
73
+ |---|---|---|
74
+ | `WORDSEARCH_MAX_SIZE` | `32` | The greatest number of rows or columns of a puzzle |
75
+ | `WORDSEARCH_MAX_WORDS` | `150` | The greatest number of words in a puzzle |
76
+ | `WORDSEARCH_MAX_CHARS` | `1500` | The greatest number of characters in a puzzle's list of words |
77
+ | `WORDSEARCH_TIME_LIMIT` | `2.0` | The time, in seconds, spent searching for a puzzle before giving up |
78
+ | `WORDSEARCH_SOLVER_MAX_SIZE` | `50` | The greatest number of rows or columns of a grid to solve |
79
+ | `WORDSEARCH_SOLVER_MAX_WORDS` | `200` | The greatest number of words to find |
80
+ | `WORDSEARCH_SOLVER_MAX_CHARS` | `10000` | The greatest number of characters in the grid, and in the words, to solve |
81
+ | `WORDSEARCH_RATE_LIMIT_PER_HOUR` | `None` | The puzzles that one visitor may make in an hour, counted in Django's default cache; no limit if `None` |
82
+ | `WORDSEARCH_CLIENT_IP` | `None` | The dotted path of a function of the request that returns the visitor's address, for the rate limit; `REMOTE_ADDR` if `None` |
83
+
84
+ `WORDSEARCH_MAX_CHARS` keeps the address of a puzzle short enough for servers such as gunicorn, which refuses a request line longer than 4094 bytes. Behind a proxy, every visitor has the proxy's `REMOTE_ADDR`, so a site that limits the rate sets `WORDSEARCH_CLIENT_IP` to a function that reads the proxy's header, such as `X-Forwarded-For`.
85
+
86
+ ## Templates and styles
87
+
88
+ Every page extends `wordsearch/page.html`, which by default is a page of its own. A site overrides it to put the app inside its own pages:
89
+
90
+ ```django
91
+ {% extends "base.html" %}
92
+ {% block title %}{% block wordsearch_title %}{% endblock %}{% endblock %}
93
+ {% block content %}{% block wordsearch_content %}{% endblock %}{% endblock %}
94
+ ```
95
+
96
+ The breadcrumb trail starts with `wordsearch/_crumbs_root.html`, and the maker's introduction ends with `wordsearch/_about.html`; both are empty by default, and a site can override them to add its own links.
97
+
98
+ The app has its own stylesheet, with no dependence on a CSS framework. Its colours follow the page's text colour and `color-scheme` (light or dark), unless the site sets these custom properties on `.wordsearch`: `--wordsearch-ink`, `--wordsearch-muted`, `--wordsearch-line`, `--wordsearch-surface` (the grid's cells), `--wordsearch-input`, `--wordsearch-accent` (links, buttons and the rings of a solution), `--wordsearch-accent-on` and `--wordsearch-page` (behind the grid). The grid's letters are in the page's font.
99
+
100
+ ## Use without Django
101
+
102
+ The module `wordsearch.puzzle` needs only Python's standard library:
103
+
104
+ ```python
105
+ from wordsearch.puzzle import find_words, grid_svg, make_wordsearch
106
+
107
+ grid, placed = make_wordsearch(["Mercury", "Venus", "Earth", "Mars"], 6, 6, seed=1)
108
+ print("\n".join(" ".join(row) for row in grid))
109
+ for word, i, j, di, dj in placed:
110
+ print(word, "reads from row", i, "column", j, "in direction", (di, dj))
111
+ ```
112
+
113
+ `make_wordsearch` also takes `mask` (`"circle"` or `"squares"`), `difficulty` (`"easy"`, `"medium"` or `"hard"`) and `time_limit`, and raises `ValueError` if the words cannot be fitted. `find_words(grid, words)` returns every occurrence of each word, and `grid_svg(grid, rings, words)` draws a grid as an SVG image.
114
+
115
+ ## Development
116
+
117
+ The package has its own tests and settings (in `tests/`), independent of any site:
118
+
119
+ ```bash
120
+ uv sync --group dev
121
+ uv run pytest
122
+ uv run ruff check . && uv run ruff format --check .
123
+ ```
124
+
125
+ CI runs them with Python 3.12 to 3.14 and Django 5.2 to 6.1, and treats any warning raised in the package's own code, such as of a deprecation, as an error.
126
+
127
+ To release a new version, change `version` in `pyproject.toml`, add it to `CHANGELOG.md`, commit, and push a tag such as `v0.2.0`. The Release workflow then publishes it to PyPI, by trusted publishing.
128
+
129
+ ## Licence
130
+
131
+ The django-wordsearch package is licensed under the BSD 3-Clause License (see `LICENSE`).
@@ -0,0 +1,104 @@
1
+ # django-wordsearch
2
+
3
+ The django-wordsearch package adds a word search maker and solver to a Django site. A *word search puzzle* hides a list of words in a grid of letters, each along a straight line of cells, among letters that fill the rest of the grid. The maker hides the words that a visitor enters, in a rectangular or shaped grid, at one of three difficulties, and shows the puzzle with its solution, in which each word is ringed. The solver finds the words in a puzzle that a visitor already has, reading in any of the eight directions.
4
+
5
+ The package needs Python 3.12 or later and Django 5.2 or later, and has no other dependencies. It stores nothing, so it has no models or migrations. It runs at https://scipython.com/apps/wordsearch/, and its method is described in the blog post [Word search puzzles](https://scipython.com/blog/making-a-word-search-puzzle-in-python/).
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ pip install django-wordsearch
11
+ ```
12
+
13
+ Add the app to `INSTALLED_APPS` and include its URLs:
14
+
15
+ ```python
16
+ INSTALLED_APPS = [
17
+ ...,
18
+ "wordsearch",
19
+ ]
20
+ ```
21
+
22
+ ```python
23
+ urlpatterns = [
24
+ ...,
25
+ path("wordsearch/", include("wordsearch.urls")),
26
+ ]
27
+ ```
28
+
29
+ The maker is then at `wordsearch/` and the solver at `wordsearch/solve/` (the URL names `wordsearch:maker` and `wordsearch:solver`).
30
+
31
+ ## Maker
32
+
33
+ The maker takes a list of words, one on each line or separated by commas, the numbers of rows and columns, a shape and a difficulty. Spaces and other characters that are not letters are left out of the grid, so that NEW YORK is written NEWYORK. The shapes are a rectangle, a circle (the largest that fits in the grid) and *squares* (the grid with its margin cut away except at its corners). At the easy difficulty, words read right or down; at medium, also diagonally down or up to the right; at hard, in all eight directions, so that words may also read backwards.
34
+
35
+ The words are placed longest first by a depth-first search: each word is put in the first place where it fits and, if a word fits nowhere, the word before it is moved to its next place. A search that has made twice as many placements as there are words is begun afresh in a new random order, until `WORDSEARCH_TIME_LIMIT`. The other cells are filled with letters drawn at random from the words themselves, in proportion to their frequency in them, so that the filler cannot be told from the words by its letters.
36
+
37
+ The maker is a GET form, and each puzzle is made with a random seed, so that the link to a puzzle, which holds the seed, makes the same puzzle again. The puzzle and its solution can be downloaded as SVG images, black on white, and a printed page shows only the puzzle and its words.
38
+
39
+ ## Solver
40
+
41
+ The solver takes a grid, one row on each line, and a list of words. A row's letters may be written together (`SNMEHJU`) or separated by spaces (`S N M E H J U`, as the maker's text output and many printed puzzles have them); a blank cell in a shaped grid is any character that is not a letter, or a space between spaced letters. It finds every occurrence of each word, in all eight directions, rings them on the grid, and lists the row, column and direction of each. A word that reads the same both ways, such as a palindrome, is counted once. The solver is a POST form, since a grid can be too long for an address.
42
+
43
+ ## Settings
44
+
45
+ | Setting | Default | Meaning |
46
+ |---|---|---|
47
+ | `WORDSEARCH_MAX_SIZE` | `32` | The greatest number of rows or columns of a puzzle |
48
+ | `WORDSEARCH_MAX_WORDS` | `150` | The greatest number of words in a puzzle |
49
+ | `WORDSEARCH_MAX_CHARS` | `1500` | The greatest number of characters in a puzzle's list of words |
50
+ | `WORDSEARCH_TIME_LIMIT` | `2.0` | The time, in seconds, spent searching for a puzzle before giving up |
51
+ | `WORDSEARCH_SOLVER_MAX_SIZE` | `50` | The greatest number of rows or columns of a grid to solve |
52
+ | `WORDSEARCH_SOLVER_MAX_WORDS` | `200` | The greatest number of words to find |
53
+ | `WORDSEARCH_SOLVER_MAX_CHARS` | `10000` | The greatest number of characters in the grid, and in the words, to solve |
54
+ | `WORDSEARCH_RATE_LIMIT_PER_HOUR` | `None` | The puzzles that one visitor may make in an hour, counted in Django's default cache; no limit if `None` |
55
+ | `WORDSEARCH_CLIENT_IP` | `None` | The dotted path of a function of the request that returns the visitor's address, for the rate limit; `REMOTE_ADDR` if `None` |
56
+
57
+ `WORDSEARCH_MAX_CHARS` keeps the address of a puzzle short enough for servers such as gunicorn, which refuses a request line longer than 4094 bytes. Behind a proxy, every visitor has the proxy's `REMOTE_ADDR`, so a site that limits the rate sets `WORDSEARCH_CLIENT_IP` to a function that reads the proxy's header, such as `X-Forwarded-For`.
58
+
59
+ ## Templates and styles
60
+
61
+ Every page extends `wordsearch/page.html`, which by default is a page of its own. A site overrides it to put the app inside its own pages:
62
+
63
+ ```django
64
+ {% extends "base.html" %}
65
+ {% block title %}{% block wordsearch_title %}{% endblock %}{% endblock %}
66
+ {% block content %}{% block wordsearch_content %}{% endblock %}{% endblock %}
67
+ ```
68
+
69
+ The breadcrumb trail starts with `wordsearch/_crumbs_root.html`, and the maker's introduction ends with `wordsearch/_about.html`; both are empty by default, and a site can override them to add its own links.
70
+
71
+ The app has its own stylesheet, with no dependence on a CSS framework. Its colours follow the page's text colour and `color-scheme` (light or dark), unless the site sets these custom properties on `.wordsearch`: `--wordsearch-ink`, `--wordsearch-muted`, `--wordsearch-line`, `--wordsearch-surface` (the grid's cells), `--wordsearch-input`, `--wordsearch-accent` (links, buttons and the rings of a solution), `--wordsearch-accent-on` and `--wordsearch-page` (behind the grid). The grid's letters are in the page's font.
72
+
73
+ ## Use without Django
74
+
75
+ The module `wordsearch.puzzle` needs only Python's standard library:
76
+
77
+ ```python
78
+ from wordsearch.puzzle import find_words, grid_svg, make_wordsearch
79
+
80
+ grid, placed = make_wordsearch(["Mercury", "Venus", "Earth", "Mars"], 6, 6, seed=1)
81
+ print("\n".join(" ".join(row) for row in grid))
82
+ for word, i, j, di, dj in placed:
83
+ print(word, "reads from row", i, "column", j, "in direction", (di, dj))
84
+ ```
85
+
86
+ `make_wordsearch` also takes `mask` (`"circle"` or `"squares"`), `difficulty` (`"easy"`, `"medium"` or `"hard"`) and `time_limit`, and raises `ValueError` if the words cannot be fitted. `find_words(grid, words)` returns every occurrence of each word, and `grid_svg(grid, rings, words)` draws a grid as an SVG image.
87
+
88
+ ## Development
89
+
90
+ The package has its own tests and settings (in `tests/`), independent of any site:
91
+
92
+ ```bash
93
+ uv sync --group dev
94
+ uv run pytest
95
+ uv run ruff check . && uv run ruff format --check .
96
+ ```
97
+
98
+ CI runs them with Python 3.12 to 3.14 and Django 5.2 to 6.1, and treats any warning raised in the package's own code, such as of a deprecation, as an error.
99
+
100
+ To release a new version, change `version` in `pyproject.toml`, add it to `CHANGELOG.md`, commit, and push a tag such as `v0.2.0`. The Release workflow then publishes it to PyPI, by trusted publishing.
101
+
102
+ ## Licence
103
+
104
+ The django-wordsearch package is licensed under the BSD 3-Clause License (see `LICENSE`).
@@ -0,0 +1,56 @@
1
+ [project]
2
+ name = "django-wordsearch"
3
+ version = "0.1.0"
4
+ description = "Word search puzzles for Django sites: a maker, with shaped grids, difficulties and solutions, and a solver."
5
+ readme = "README.md"
6
+ license = "BSD-3-Clause"
7
+ license-files = ["LICENSE"]
8
+ authors = [{ name = "Christian Hill" }]
9
+ requires-python = ">=3.12"
10
+ keywords = ["django", "word search", "puzzle", "wordsearch"]
11
+ classifiers = [
12
+ "Development Status :: 4 - Beta",
13
+ "Environment :: Web Environment",
14
+ "Framework :: Django",
15
+ "Framework :: Django :: 5.2",
16
+ "Framework :: Django :: 6.0",
17
+ "Framework :: Django :: 6.1",
18
+ "Intended Audience :: Education",
19
+ "Operating System :: OS Independent",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3.12",
22
+ "Programming Language :: Python :: 3.13",
23
+ "Programming Language :: Python :: 3.14",
24
+ "Topic :: Games/Entertainment :: Puzzle Games",
25
+ ]
26
+ dependencies = ["django>=5.2"]
27
+
28
+ [project.urls]
29
+ Homepage = "https://github.com/xnx/django-wordsearch"
30
+ Changelog = "https://github.com/xnx/django-wordsearch/blob/main/CHANGELOG.md"
31
+
32
+ [dependency-groups]
33
+ dev = ["pytest", "pytest-django", "ruff"]
34
+
35
+ [build-system]
36
+ requires = ["hatchling>=1.27"]
37
+ build-backend = "hatchling.build"
38
+
39
+ [tool.hatch.build.targets.wheel]
40
+ packages = ["src/wordsearch"]
41
+
42
+ [tool.pytest.ini_options]
43
+ DJANGO_SETTINGS_MODULE = "tests.settings"
44
+ pythonpath = ["."]
45
+ testpaths = ["tests"]
46
+ # A warning raised in the package's own code, such as of a deprecation, fails.
47
+ filterwarnings = ["error:::wordsearch"]
48
+
49
+ [tool.ruff]
50
+ line-length = 88
51
+ target-version = "py312"
52
+ src = ["src", "."]
53
+
54
+ [tool.ruff.lint]
55
+ select = ["E", "F", "I", "B", "UP", "DJ"]
56
+ ignore = ["E501"] # line length is left to `ruff format`
@@ -0,0 +1 @@
1
+ """Word search puzzles for Django sites: a maker and a solver."""
@@ -0,0 +1,6 @@
1
+ from django.apps import AppConfig
2
+
3
+
4
+ class WordsearchConfig(AppConfig):
5
+ name = "wordsearch"
6
+ verbose_name = "Word search"
@@ -0,0 +1,41 @@
1
+ """The app's settings. A site overrides one by setting WORDSEARCH_<NAME>."""
2
+
3
+ from django.conf import settings
4
+ from django.utils.module_loading import import_string
5
+
6
+ DEFAULTS = {
7
+ # The maker: the greatest number of rows or columns, of words, and of
8
+ # characters in the list of words. The maker is a GET form, so that the link
9
+ # to a puzzle makes it again; MAX_CHARS keeps that address short enough for
10
+ # servers such as gunicorn, which refuses a request line over 4094 bytes.
11
+ "MAX_SIZE": 32,
12
+ "MAX_WORDS": 150,
13
+ "MAX_CHARS": 1500,
14
+ # Seconds to search for a puzzle before giving up.
15
+ "TIME_LIMIT": 2.0,
16
+ # The solver (a POST form): the greatest number of rows or columns, of
17
+ # words, and of characters in the grid or in the list of words.
18
+ "SOLVER_MAX_SIZE": 50,
19
+ "SOLVER_MAX_WORDS": 200,
20
+ "SOLVER_MAX_CHARS": 10_000,
21
+ # Puzzles that one visitor may make in an hour (None for no limit), counted
22
+ # in Django's default cache.
23
+ "RATE_LIMIT_PER_HOUR": None,
24
+ # The dotted path of a function of the request that returns the visitor's
25
+ # address, for the rate limit; REMOTE_ADDR if None. Behind a proxy, every
26
+ # visitor has the proxy's REMOTE_ADDR, so a site sets this to a function
27
+ # that reads the proxy's header.
28
+ "CLIENT_IP": None,
29
+ }
30
+
31
+
32
+ def setting(name):
33
+ return getattr(settings, f"WORDSEARCH_{name}", DEFAULTS[name])
34
+
35
+
36
+ def client_ip(request):
37
+ """The visitor's address, by the function that CLIENT_IP names, if any."""
38
+ path = setting("CLIENT_IP")
39
+ if path:
40
+ return import_string(path)(request)
41
+ return request.META.get("REMOTE_ADDR", "")