randex 0.1.0__tar.gz → 0.2.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: randex
3
- Version: 0.1.0
3
+ Version: 0.2.0
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, `Poetry`, and `latexmk`.
42
+ Randex requires Python version `3.10` or higher and `latexmk`.
43
43
 
44
- ### Poetry
44
+ ### Randex
45
+
46
+ To install Randex, run the following command from the root folder of the project:
45
47
 
46
- [Poetry](https://python-poetry.org) is the packaging and dependency manager used for
47
- this project.
48
- To install Poetry, follow the instructions [here](https://python-poetry.org/docs/#installing-with-pipx).
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 in the TeXLive and MiKTeX distributions.
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
- ### Randex
71
+ ## Randex Commands
67
72
 
68
- To install Randex, run the following command from the root folder of the project:
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
- poetry install
101
+ validate --help
72
102
  ```
73
103
 
74
- Then execute:
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
- poetry shell
111
+ exams -b 5 -n 2 -t examples/en/template-exam.yaml -o tmp --overwrite --clean "examples/en/folder_*"
78
112
  ```
79
113
 
80
- to spawn a shell with the Python environment activated.
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
- ### Tex File
133
+ ### template-exam.yaml File
87
134
 
88
- The `Tex` file is a `YAML` file that describes the LaTeX file that will produce the exam. It contains the following keys:
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. Only the `exam` class is supported. Default:
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 `\begin{document}` command. Default:
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
- ### Questions File
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 `Tex` file and the folders containing the exams as inputs.
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
@@ -13,16 +13,20 @@ Multiple exams can be created at once.
13
13
 
14
14
  ## Installation
15
15
 
16
- Randex requires Python version `3.10` or higher, `Poetry`, and `latexmk`.
16
+ Randex requires Python version `3.10` or higher and `latexmk`.
17
17
 
18
- ### Poetry
18
+ ### Randex
19
+
20
+ To install Randex, run the following command from the root folder of the project:
19
21
 
20
- [Poetry](https://python-poetry.org) is the packaging and dependency manager used for
21
- this project.
22
- To install Poetry, follow the instructions [here](https://python-poetry.org/docs/#installing-with-pipx).
22
+ ```sh
23
+ pip install randex
24
+ ```
23
25
 
24
26
  ### latexmk
25
27
 
28
+ In order to compile the LaTeX files, you need to install `latexmk`,
29
+
26
30
  From [here](https://mg.readthedocs.io/latexmk.html):
27
31
  ```
28
32
  Latexmk is a Perl script which you just have to run once and it does everything else for you... completely automagically.
@@ -31,41 +35,87 @@ Latexmk is a Perl script which you just have to run once and it does everything
31
35
  and [here](https://www.cantab.net/users/johncollins/latexmk/)
32
36
 
33
37
  ```
34
- Latexmk is also available at CTAN at https://ctan.org/pkg/latexmk/, and is/will be in the TeXLive and MiKTeX distributions.
38
+ Latexmk is also available at CTAN at https://ctan.org/pkg/latexmk/, and is/will be
39
+ in the TeXLive and MiKTeX distributions.
35
40
  ```
36
41
 
37
42
  If you have already `Latex` installed in your system, you will most
38
43
  probably have already `latexmk` installed as well.
39
44
 
40
- ### Randex
45
+ ## Randex Commands
41
46
 
42
- To install Randex, run the following command from the root folder of the project:
47
+ ### randex-download-examples
48
+
49
+ To download the latest examples from GitHub, run the following command from the root
50
+ folder of the project:
51
+
52
+ ```sh
53
+ randex-download-examples
54
+ ```
55
+
56
+ ### validate
57
+
58
+ This command validates a single question or all questions under a folder. Execute:
59
+
60
+ ```sh
61
+ validate -t examples/en/template-exam.yaml -o tmp --overwrite "examples/en/folder_*"
62
+ ```
63
+
64
+ to validate all the questions under the folder `examples/en` that contains subfolders
65
+ with questions.
66
+ It will use the configuration from the file `examples/en/template-exam.yaml`.
67
+ The LaTeX compilation will run inside the `temp` folder.
68
+ The `--clean` option will remove all intermediate files created by LaTeX,
69
+ and the `-a` flag will show the correct answers in the produced PDF.
70
+ Open the PDF file inside `temp` to validate that all questions appear correctly.
71
+
72
+ Run:
43
73
 
44
74
  ```sh
45
- poetry install
75
+ validate --help
46
76
  ```
47
77
 
48
- Then execute:
78
+ to see the help message for the command.
79
+
80
+ ### exams
81
+
82
+ To create a batch of exams with random questions, execute:
49
83
 
50
84
  ```sh
51
- poetry shell
85
+ exams -b 5 -n 2 -t examples/en/template-exam.yaml -o tmp --overwrite --clean "examples/en/folder_*"
52
86
  ```
53
87
 
54
- to spawn a shell with the Python environment activated.
88
+ This command will create 5 exams from using the questions inside the 3 folders with
89
+ names `folder_0`, `folder_1`, and `folder_2` using the configuration from the file
90
+ `examples/en/template-exam.yaml`.
91
+ The `--clean` option will remove all intermediate files created by LaTeX.
92
+ The `-n` option specifies the number of questions randomly chosen from each folder.
93
+ It can appear once, meaning all folders will contribute the same number of questions,
94
+ or multiple times, e.g., `-n 2 -n 1 -n 3 `, indicating the first folder will contribute
95
+ 2 questions, the second folder will contribute 1 question, and the third folder will
96
+ contribute 3 questions.
97
+ The `-b` option specifies the number of exams to create.
98
+
99
+ ### Grade
100
+
101
+ Not implemented yet.
55
102
 
56
103
  ## Randex Data Scheme
57
104
 
58
105
  Randex requires two types of data files to create the exams.
59
106
 
60
- ### Tex File
107
+ ### template-exam.yaml File
61
108
 
62
- The `Tex` file is a `YAML` file that describes the LaTeX file that will produce the exam. It contains the following keys:
109
+ The `template-exam.yaml` file is a `YAML` file that describes the LaTeX file that will
110
+ produce the exam. It contains the following keys:
63
111
 
64
- - `documentclass` (optional): String with the documentclass command of the file. Only the `exam` class is supported. Default:
112
+ - `documentclass` (optional): String with the documentclass command of the file.
113
+ Only the `exam` class is supported. Default:
65
114
  ```latex
66
115
  \documentclass[11pt]{exam}
67
116
  ```
68
- - `prebegin` (optional): String containing everything that goes before the `\begin{document}` command. Default:
117
+ - `prebegin` (optional): String containing everything that goes before the
118
+ `\begin{document}` command. Default:
69
119
  ```latex
70
120
  \usepackage{amsmath}
71
121
  \usepackage{amssymb}
@@ -91,7 +141,7 @@ The `Tex` file is a `YAML` file that describes the LaTeX file that will produce
91
141
 
92
142
  The right part of the head is reserved for the serial number of the exam.
93
143
 
94
- ### Questions File
144
+ ### questions.yaml File
95
145
 
96
146
  Each question is written in a `YAML` file with the following keys:
97
147
 
@@ -99,62 +149,11 @@ Each question is written in a `YAML` file with the following keys:
99
149
  - `answers` (required): List of strings with the answers. Do not use double quotes around the strings.
100
150
  - `right_answer` (required): Integer indicating the correct answer.
101
151
  The answer is non-negative and less than the length of the `answers` list.
102
- - `points` (optional): Points given to the question. Default: `1`
103
152
 
104
153
  The questions `YAML` files should be organized inside folders.
105
154
 
106
- The `randex` commands take the `Tex` file and the folders containing the exams as inputs.
107
-
108
- ## Randex Commands
109
-
110
- Inside an activated environment, you can run the following commands.
111
-
112
- ### Validate
155
+ The `randex` commands take the `template-exam.yaml` file and the folders containing the questions as inputs.
113
156
 
114
- This command validates a single question or all questions inside a folder. Execute:
115
-
116
- ```sh
117
- validate example/en -t example/en/tex.yaml -o temp --clean -a
118
- ```
119
-
120
- to validate all the questions inside the folder `example/en` that contains subfolders
121
- with questions.
122
- It will use the configuration from the file `example/en/tex.yaml`.
123
- The LaTeX compilation will run inside the `temp` folder.
124
- The `--clean` option will remove all intermediate files created by LaTeX,
125
- and the `-a` flag will show the correct answers in the produced PDF.
126
- Open the PDF file inside `temp` to validate that all questions appear correctly.
127
-
128
- Run:
129
-
130
- ```sh
131
- validate --help
132
- ```
133
-
134
- to see the help message for the command.
135
-
136
- ### Exams
137
-
138
- To create a batch of exams with random questions, execute:
139
-
140
- ```sh
141
- exams example/en/folder_0/ example/en/folder_1/ example/en/folder_2/ -b 10 -t example/en/tex.yaml --clean -n 2
142
- ```
143
-
144
- This command will create 10 exams from 3 folders using the configuration from the file
145
- `example/en/tex.yaml`.
146
- The `--clean` option will remove all intermediate files created by LaTeX.
147
- The `-n` option specifies the number of questions randomly chosen from each folder.
148
- It can appear once, meaning all folders will contribute the same number of questions,
149
- or multiple times, e.g., `-n 2 -n 1`, indicating the first folder will contribute
150
- 2 questions, and the remaining folders will contribute 1 question each.
151
- For example, `-n 2 -n 1 -n 3` means the first, second,
152
- and third folders will contribute 2, 1, and 3 questions, respectively.
153
- The `-b` option specifies the number of exams to create.
154
-
155
- ### Grade
156
-
157
- Not implemented yet.
158
157
 
159
158
 
160
159
  # License
@@ -53,7 +53,7 @@ packages = [
53
53
  {include = "scripts"}
54
54
  ]
55
55
  readme = "README.md"
56
- version = "0.1.0"
56
+ version = "0.2.0"
57
57
 
58
58
  [tool.poetry.dependencies]
59
59
  cerberus = "^1.3.5"
@@ -77,6 +77,7 @@ types-pyyaml = "^6.0.12.20250516"
77
77
 
78
78
  [tool.poetry.scripts]
79
79
  exams = "scripts.exams:main"
80
+ randex-download-examples = "scripts.randex_download_examples:main"
80
81
  validate = "scripts.validate:main"
81
82
 
82
83
  [tool.poetry.urls]
@@ -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()
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes