randex 0.1.0__py3-none-any.whl → 0.2.1__py3-none-any.whl
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.
- randex/cli.py +56 -0
- randex/exam.py +8 -2
- {randex-0.1.0.dist-info → randex-0.2.1.dist-info}/METADATA +69 -70
- randex-0.2.1.dist-info/RECORD +12 -0
- {randex-0.1.0.dist-info → randex-0.2.1.dist-info}/entry_points.txt +1 -0
- scripts/exams.py +2 -0
- scripts/randex_download_examples.py +57 -0
- scripts/validate.py +2 -0
- randex-0.1.0.dist-info/RECORD +0 -10
- {randex-0.1.0.dist-info → randex-0.2.1.dist-info}/LICENSE +0 -0
- {randex-0.1.0.dist-info → randex-0.2.1.dist-info}/WHEEL +0 -0
randex/cli.py
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
"""Shared CLI utilities for randex scripts."""
|
2
|
+
|
3
|
+
import click
|
4
|
+
|
5
|
+
|
6
|
+
class CustomCommand(click.Command):
|
7
|
+
"""Custom Click command that provides better error messages."""
|
8
|
+
|
9
|
+
def parse_args(
|
10
|
+
self,
|
11
|
+
ctx: click.Context,
|
12
|
+
args: list[str],
|
13
|
+
) -> list[str]:
|
14
|
+
"""
|
15
|
+
Override parse_args to catch parameter parsing errors.
|
16
|
+
|
17
|
+
This is a workaround to catch the error when the user passes multiple
|
18
|
+
folder arguments to the command.
|
19
|
+
|
20
|
+
Parameters
|
21
|
+
----------
|
22
|
+
ctx : click.Context
|
23
|
+
The click context.
|
24
|
+
args : list[str]
|
25
|
+
The arguments passed to the command.
|
26
|
+
|
27
|
+
Returns
|
28
|
+
-------
|
29
|
+
list[str]:
|
30
|
+
The remaining unparsed arguments.
|
31
|
+
|
32
|
+
Examples
|
33
|
+
--------
|
34
|
+
```bash
|
35
|
+
exams examples/en/folder_* -t template.yaml -n 2
|
36
|
+
```
|
37
|
+
"""
|
38
|
+
try:
|
39
|
+
return super().parse_args(ctx, args)
|
40
|
+
except click.UsageError as e:
|
41
|
+
if "Got unexpected extra arguments" in str(e):
|
42
|
+
# Extract the extra arguments from the error message
|
43
|
+
error_msg = str(e)
|
44
|
+
if "(" in error_msg and ")" in error_msg:
|
45
|
+
extra_args = error_msg.split("(")[1].split(")")[0]
|
46
|
+
|
47
|
+
raise click.UsageError(
|
48
|
+
f"❌ Multiple folder arguments detected: {extra_args}\n\n"
|
49
|
+
f"💡 This usually happens when your shell expands a glob pattern like 'examples/en/folder_*'\n" # noqa: E501
|
50
|
+
f" into multiple folder names before passing them to the command.\n\n" # noqa: E501
|
51
|
+
f"🔧 Solutions:\n"
|
52
|
+
f' • Put quotes around your glob pattern: "examples/en/folder_*"\n' # noqa: E501
|
53
|
+
f" • Or specify a single folder path instead of a glob pattern\n\n" # noqa: E501
|
54
|
+
f'Example: exams "examples/en/folder_*" -t template.yaml -n 2'
|
55
|
+
) from e
|
56
|
+
raise
|
randex/exam.py
CHANGED
@@ -202,8 +202,14 @@ class Pool:
|
|
202
202
|
matched = [p.resolve() for p in Path().glob(folder_input) if p.is_dir()]
|
203
203
|
if not matched:
|
204
204
|
raise ValueError(
|
205
|
-
f"
|
206
|
-
"
|
205
|
+
f"❌ No folders found matching the pattern: '{folder_input}'\n\n"
|
206
|
+
f"💡 Suggestions:\n"
|
207
|
+
f" • Check if the path exists and contains folders\n"
|
208
|
+
f" • Verify the spelling (common mistake: 'example' vs 'examples')\n" # noqa: E501
|
209
|
+
f" • Use quotes around the pattern to prevent shell expansion\n"
|
210
|
+
f" • Try listing the directory to see available folders\n\n"
|
211
|
+
f"🔍 If '{folder_input}' is meant to be a literal folder name (not a pattern), " # noqa: E501
|
212
|
+
f"remove the special characters or use a Path object instead."
|
207
213
|
)
|
208
214
|
return matched
|
209
215
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: randex
|
3
|
-
Version: 0.1
|
3
|
+
Version: 0.2.1
|
4
4
|
Summary: Create randomized multiple choice exams using latex.
|
5
5
|
License: CC BY-NC 4.0
|
6
6
|
Author: G. Arampatzis
|
@@ -39,16 +39,20 @@ Multiple exams can be created at once.
|
|
39
39
|
|
40
40
|
## Installation
|
41
41
|
|
42
|
-
Randex requires Python version `3.10` or higher
|
42
|
+
Randex requires Python version `3.10` or higher and `latexmk`.
|
43
43
|
|
44
|
-
###
|
44
|
+
### Randex
|
45
|
+
|
46
|
+
To install Randex, run the following command from the root folder of the project:
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
-
|
48
|
+
```sh
|
49
|
+
pip install randex
|
50
|
+
```
|
49
51
|
|
50
52
|
### latexmk
|
51
53
|
|
54
|
+
In order to compile the LaTeX files, you need to install `latexmk`,
|
55
|
+
|
52
56
|
From [here](https://mg.readthedocs.io/latexmk.html):
|
53
57
|
```
|
54
58
|
Latexmk is a Perl script which you just have to run once and it does everything else for you... completely automagically.
|
@@ -57,41 +61,87 @@ Latexmk is a Perl script which you just have to run once and it does everything
|
|
57
61
|
and [here](https://www.cantab.net/users/johncollins/latexmk/)
|
58
62
|
|
59
63
|
```
|
60
|
-
Latexmk is also available at CTAN at https://ctan.org/pkg/latexmk/, and is/will be
|
64
|
+
Latexmk is also available at CTAN at https://ctan.org/pkg/latexmk/, and is/will be
|
65
|
+
in the TeXLive and MiKTeX distributions.
|
61
66
|
```
|
62
67
|
|
63
68
|
If you have already `Latex` installed in your system, you will most
|
64
69
|
probably have already `latexmk` installed as well.
|
65
70
|
|
66
|
-
|
71
|
+
## Randex Commands
|
67
72
|
|
68
|
-
|
73
|
+
### randex-download-examples
|
74
|
+
|
75
|
+
To download the latest examples from GitHub, run the following command from the root
|
76
|
+
folder of the project:
|
77
|
+
|
78
|
+
```sh
|
79
|
+
randex-download-examples
|
80
|
+
```
|
81
|
+
|
82
|
+
### validate
|
83
|
+
|
84
|
+
This command validates a single question or all questions under a folder. Execute:
|
85
|
+
|
86
|
+
```sh
|
87
|
+
validate -t examples/en/template-exam.yaml -o tmp --overwrite "examples/en/folder_*"
|
88
|
+
```
|
89
|
+
|
90
|
+
to validate all the questions under the folder `examples/en` that contains subfolders
|
91
|
+
with questions.
|
92
|
+
It will use the configuration from the file `examples/en/template-exam.yaml`.
|
93
|
+
The LaTeX compilation will run inside the `temp` folder.
|
94
|
+
The `--clean` option will remove all intermediate files created by LaTeX,
|
95
|
+
and the `-a` flag will show the correct answers in the produced PDF.
|
96
|
+
Open the PDF file inside `temp` to validate that all questions appear correctly.
|
97
|
+
|
98
|
+
Run:
|
69
99
|
|
70
100
|
```sh
|
71
|
-
|
101
|
+
validate --help
|
72
102
|
```
|
73
103
|
|
74
|
-
|
104
|
+
to see the help message for the command.
|
105
|
+
|
106
|
+
### exams
|
107
|
+
|
108
|
+
To create a batch of exams with random questions, execute:
|
75
109
|
|
76
110
|
```sh
|
77
|
-
|
111
|
+
exams -b 5 -n 2 -t examples/en/template-exam.yaml -o tmp --overwrite --clean "examples/en/folder_*"
|
78
112
|
```
|
79
113
|
|
80
|
-
|
114
|
+
This command will create 5 exams from using the questions inside the 3 folders with
|
115
|
+
names `folder_0`, `folder_1`, and `folder_2` using the configuration from the file
|
116
|
+
`examples/en/template-exam.yaml`.
|
117
|
+
The `--clean` option will remove all intermediate files created by LaTeX.
|
118
|
+
The `-n` option specifies the number of questions randomly chosen from each folder.
|
119
|
+
It can appear once, meaning all folders will contribute the same number of questions,
|
120
|
+
or multiple times, e.g., `-n 2 -n 1 -n 3 `, indicating the first folder will contribute
|
121
|
+
2 questions, the second folder will contribute 1 question, and the third folder will
|
122
|
+
contribute 3 questions.
|
123
|
+
The `-b` option specifies the number of exams to create.
|
124
|
+
|
125
|
+
### Grade
|
126
|
+
|
127
|
+
Not implemented yet.
|
81
128
|
|
82
129
|
## Randex Data Scheme
|
83
130
|
|
84
131
|
Randex requires two types of data files to create the exams.
|
85
132
|
|
86
|
-
###
|
133
|
+
### template-exam.yaml File
|
87
134
|
|
88
|
-
The `
|
135
|
+
The `template-exam.yaml` file is a `YAML` file that describes the LaTeX file that will
|
136
|
+
produce the exam. It contains the following keys:
|
89
137
|
|
90
|
-
- `documentclass` (optional): String with the documentclass command of the file.
|
138
|
+
- `documentclass` (optional): String with the documentclass command of the file.
|
139
|
+
Only the `exam` class is supported. Default:
|
91
140
|
```latex
|
92
141
|
\documentclass[11pt]{exam}
|
93
142
|
```
|
94
|
-
- `prebegin` (optional): String containing everything that goes before the
|
143
|
+
- `prebegin` (optional): String containing everything that goes before the
|
144
|
+
`\begin{document}` command. Default:
|
95
145
|
```latex
|
96
146
|
\usepackage{amsmath}
|
97
147
|
\usepackage{amssymb}
|
@@ -117,7 +167,7 @@ The `Tex` file is a `YAML` file that describes the LaTeX file that will produce
|
|
117
167
|
|
118
168
|
The right part of the head is reserved for the serial number of the exam.
|
119
169
|
|
120
|
-
###
|
170
|
+
### questions.yaml File
|
121
171
|
|
122
172
|
Each question is written in a `YAML` file with the following keys:
|
123
173
|
|
@@ -125,62 +175,11 @@ Each question is written in a `YAML` file with the following keys:
|
|
125
175
|
- `answers` (required): List of strings with the answers. Do not use double quotes around the strings.
|
126
176
|
- `right_answer` (required): Integer indicating the correct answer.
|
127
177
|
The answer is non-negative and less than the length of the `answers` list.
|
128
|
-
- `points` (optional): Points given to the question. Default: `1`
|
129
178
|
|
130
179
|
The questions `YAML` files should be organized inside folders.
|
131
180
|
|
132
|
-
The `randex` commands take the `
|
133
|
-
|
134
|
-
## Randex Commands
|
135
|
-
|
136
|
-
Inside an activated environment, you can run the following commands.
|
137
|
-
|
138
|
-
### Validate
|
181
|
+
The `randex` commands take the `template-exam.yaml` file and the folders containing the questions as inputs.
|
139
182
|
|
140
|
-
This command validates a single question or all questions inside a folder. Execute:
|
141
|
-
|
142
|
-
```sh
|
143
|
-
validate example/en -t example/en/tex.yaml -o temp --clean -a
|
144
|
-
```
|
145
|
-
|
146
|
-
to validate all the questions inside the folder `example/en` that contains subfolders
|
147
|
-
with questions.
|
148
|
-
It will use the configuration from the file `example/en/tex.yaml`.
|
149
|
-
The LaTeX compilation will run inside the `temp` folder.
|
150
|
-
The `--clean` option will remove all intermediate files created by LaTeX,
|
151
|
-
and the `-a` flag will show the correct answers in the produced PDF.
|
152
|
-
Open the PDF file inside `temp` to validate that all questions appear correctly.
|
153
|
-
|
154
|
-
Run:
|
155
|
-
|
156
|
-
```sh
|
157
|
-
validate --help
|
158
|
-
```
|
159
|
-
|
160
|
-
to see the help message for the command.
|
161
|
-
|
162
|
-
### Exams
|
163
|
-
|
164
|
-
To create a batch of exams with random questions, execute:
|
165
|
-
|
166
|
-
```sh
|
167
|
-
exams example/en/folder_0/ example/en/folder_1/ example/en/folder_2/ -b 10 -t example/en/tex.yaml --clean -n 2
|
168
|
-
```
|
169
|
-
|
170
|
-
This command will create 10 exams from 3 folders using the configuration from the file
|
171
|
-
`example/en/tex.yaml`.
|
172
|
-
The `--clean` option will remove all intermediate files created by LaTeX.
|
173
|
-
The `-n` option specifies the number of questions randomly chosen from each folder.
|
174
|
-
It can appear once, meaning all folders will contribute the same number of questions,
|
175
|
-
or multiple times, e.g., `-n 2 -n 1`, indicating the first folder will contribute
|
176
|
-
2 questions, and the remaining folders will contribute 1 question each.
|
177
|
-
For example, `-n 2 -n 1 -n 3` means the first, second,
|
178
|
-
and third folders will contribute 2, 1, and 3 questions, respectively.
|
179
|
-
The `-b` option specifies the number of exams to create.
|
180
|
-
|
181
|
-
### Grade
|
182
|
-
|
183
|
-
Not implemented yet.
|
184
183
|
|
185
184
|
|
186
185
|
# License
|
@@ -0,0 +1,12 @@
|
|
1
|
+
randex/__init__.py,sha256=6bBAISO6MqVCSCvqLcK3SGUnDODuwobLWouO3GY8SRU,187
|
2
|
+
randex/cli.py,sha256=hwLgZIfBkAeFXlbveywmQlKBGz9GsD_P6Q89YSDOe2M,2039
|
3
|
+
randex/exam.py,sha256=sYBQhYjmZDNyTicSD6nOOTo_7c_rst5rhyjCJhCbVtk,26975
|
4
|
+
scripts/__init__.py,sha256=F8pjiW8AlL0IhnvVh1TEfgiD--YdFE_PggtSevHp5y4,38
|
5
|
+
scripts/exams.py,sha256=D4ky-3J4yx7R3_-UgpGT7C9nQWFqNvdn-fhvzt9Jkbg,3401
|
6
|
+
scripts/randex_download_examples.py,sha256=fj88XkZV8bpHPCeXu1f3nVNws_hbcJ_3Zso7XOPB0RQ,1682
|
7
|
+
scripts/validate.py,sha256=MnJqfSs8n6qSuxMUT4W0P4ePGyDtRUIXKakWVy20eVo,2659
|
8
|
+
randex-0.2.1.dist-info/LICENSE,sha256=NxH5Y8BdC-gNU-WSMwim3uMbID2iNDXJz7fHtuTdXhk,19346
|
9
|
+
randex-0.2.1.dist-info/METADATA,sha256=18RJ4FY6RmVK4C9OxDWM8Qe8kY0SClXtbnXT8VrRYP8,6551
|
10
|
+
randex-0.2.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
11
|
+
randex-0.2.1.dist-info/entry_points.txt,sha256=RayNUArGNT0MLZi7uh1MHjnd1L1V4X6C4sBdMLbvAfc,138
|
12
|
+
randex-0.2.1.dist-info/RECORD,,
|
scripts/exams.py
CHANGED
@@ -6,10 +6,12 @@ from pathlib import Path
|
|
6
6
|
|
7
7
|
import click
|
8
8
|
|
9
|
+
from randex.cli import CustomCommand
|
9
10
|
from randex.exam import ExamBatch, ExamTemplate, Pool, QuestionSet
|
10
11
|
|
11
12
|
|
12
13
|
@click.command(
|
14
|
+
cls=CustomCommand,
|
13
15
|
context_settings={"help_option_names": ["--help"]},
|
14
16
|
)
|
15
17
|
@click.argument(
|
@@ -0,0 +1,57 @@
|
|
1
|
+
"""Download the latest examples from GitHub."""
|
2
|
+
|
3
|
+
import io
|
4
|
+
import shutil
|
5
|
+
import sys
|
6
|
+
import tempfile
|
7
|
+
import urllib.request
|
8
|
+
import zipfile
|
9
|
+
from pathlib import Path
|
10
|
+
from urllib.error import URLError
|
11
|
+
|
12
|
+
GITHUB_ZIP_URL = "https://github.com/arampatzis/randex/archive/refs/heads/main.zip"
|
13
|
+
DEST_DIR = Path("examples")
|
14
|
+
|
15
|
+
|
16
|
+
def main() -> None:
|
17
|
+
"""Download the latest examples from GitHub."""
|
18
|
+
print("📦 Downloading examples from GitHub...")
|
19
|
+
|
20
|
+
if DEST_DIR.exists():
|
21
|
+
print(
|
22
|
+
f"❌ Destination folder '{DEST_DIR}' already exists. "
|
23
|
+
"Please remove it first."
|
24
|
+
)
|
25
|
+
sys.exit(1)
|
26
|
+
|
27
|
+
try:
|
28
|
+
with (
|
29
|
+
urllib.request.urlopen(GITHUB_ZIP_URL) as response, # noqa: S310
|
30
|
+
zipfile.ZipFile(io.BytesIO(response.read())) as zip_ref,
|
31
|
+
):
|
32
|
+
temp_dir = Path(tempfile.mkdtemp())
|
33
|
+
zip_ref.extractall(temp_dir)
|
34
|
+
|
35
|
+
# Detect the root folder inside the zip (e.g., randex-main)
|
36
|
+
root_entry = next((p for p in temp_dir.iterdir() if p.is_dir()), None)
|
37
|
+
|
38
|
+
if not root_entry:
|
39
|
+
print("❌ Could not locate the root folder in the archive.")
|
40
|
+
sys.exit(1)
|
41
|
+
|
42
|
+
examples_path = root_entry / "examples"
|
43
|
+
|
44
|
+
if not examples_path.exists():
|
45
|
+
print("❌ examples/ folder not found in the downloaded repository.")
|
46
|
+
sys.exit(1)
|
47
|
+
|
48
|
+
shutil.copytree(examples_path, DEST_DIR)
|
49
|
+
print(f"✅ Examples downloaded to: {DEST_DIR.resolve()}")
|
50
|
+
|
51
|
+
except (URLError, zipfile.BadZipFile, OSError, shutil.Error) as e:
|
52
|
+
print(f"❌ Error: {e}")
|
53
|
+
sys.exit(1)
|
54
|
+
|
55
|
+
|
56
|
+
if __name__ == "__main__":
|
57
|
+
main()
|
scripts/validate.py
CHANGED
@@ -6,10 +6,12 @@ from pathlib import Path
|
|
6
6
|
|
7
7
|
import click
|
8
8
|
|
9
|
+
from randex.cli import CustomCommand
|
9
10
|
from randex.exam import Exam, ExamTemplate, Pool, QuestionSet
|
10
11
|
|
11
12
|
|
12
13
|
@click.command(
|
14
|
+
cls=CustomCommand,
|
13
15
|
context_settings={"help_option_names": ["--help"]},
|
14
16
|
)
|
15
17
|
@click.argument(
|
randex-0.1.0.dist-info/RECORD
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
randex/__init__.py,sha256=6bBAISO6MqVCSCvqLcK3SGUnDODuwobLWouO3GY8SRU,187
|
2
|
-
randex/exam.py,sha256=l-_6GnrstLgVMORXNEIKzgW9k6h_YbXndZd8YmEGKBI,26450
|
3
|
-
scripts/__init__.py,sha256=F8pjiW8AlL0IhnvVh1TEfgiD--YdFE_PggtSevHp5y4,38
|
4
|
-
scripts/exams.py,sha256=L4QSOZpU8Hw5QkW_2x5s8NESQAwlEmZTSaT6ZZ8-c04,3341
|
5
|
-
scripts/validate.py,sha256=xruN1P1rgJnc0MTklLgSrsx9TcFC2SY1a9eksNT_-KM,2599
|
6
|
-
randex-0.1.0.dist-info/LICENSE,sha256=NxH5Y8BdC-gNU-WSMwim3uMbID2iNDXJz7fHtuTdXhk,19346
|
7
|
-
randex-0.1.0.dist-info/METADATA,sha256=7UQ_rkrBEjHg9pKOjqMKrSRcv4S8FjjGLS7zgmEmG-g,6677
|
8
|
-
randex-0.1.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
9
|
-
randex-0.1.0.dist-info/entry_points.txt,sha256=gRD7WCYtG4hW2sv_mg2TT7ifbCGjqNqMBezaUa32F64,75
|
10
|
-
randex-0.1.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|