Skip to content

Commit bc18cd0

Browse files
committed
Small changes following last review
1 parent f6c0968 commit bc18cd0

File tree

4 files changed

+17
-34
lines changed

4 files changed

+17
-34
lines changed

scraper/src/mindtouch2zim/context.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
VERSION,
1515
)
1616

17+
MINDTOUCH_TMP = os.getenv("MINDTOUCH_TMP")
18+
1719

1820
@dataclasses.dataclass(kw_only=True)
1921
class Context:

scraper/src/mindtouch2zim/entrypoint.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import argparse
2-
import os
32
import re
43
import threading
54
from pathlib import Path
@@ -16,7 +15,7 @@
1615
STANDARD_KNOWN_BAD_ASSETS_REGEX,
1716
VERSION,
1817
)
19-
from mindtouch2zim.context import Context
18+
from mindtouch2zim.context import MINDTOUCH_TMP, Context
2019

2120

2221
def prepare_context(raw_args: list[str], tmpdir: str) -> None:
@@ -26,8 +25,6 @@ def prepare_context(raw_args: list[str], tmpdir: str) -> None:
2625
prog=NAME,
2726
)
2827

29-
parser.register("type", "Path", lambda x: Path(x))
30-
3128
parser.add_argument(
3229
"--creator",
3330
help="Name of content creator.",
@@ -36,13 +33,13 @@ def prepare_context(raw_args: list[str], tmpdir: str) -> None:
3633

3734
parser.add_argument(
3835
"--publisher",
39-
help=f"Publisher name. Default: {Context.publisher!r}",
36+
help=f"Publisher name. Default: {Context.publisher!s}",
4037
)
4138

4239
parser.add_argument(
4340
"--file-name",
4441
help="Custom file name format for individual ZIMs. "
45-
f"Default: {Context.file_name!r}",
42+
f"Default: {Context.file_name!s}",
4643
)
4744

4845
parser.add_argument(
@@ -82,7 +79,7 @@ def prepare_context(raw_args: list[str], tmpdir: str) -> None:
8279
parser.add_argument(
8380
"--secondary-color",
8481
help="Secondary (background) color of ZIM UI. Default: "
85-
f"{Context.secondary_color!r}",
82+
f"{Context.secondary_color!s}",
8683
)
8784

8885
parser.add_argument(
@@ -141,22 +138,22 @@ def prepare_context(raw_args: list[str], tmpdir: str) -> None:
141138
parser.add_argument(
142139
"--output",
143140
help="Output folder for ZIMs. Default: /output",
144-
type="Path",
141+
type=Path,
145142
dest="output_folder",
146143
)
147144

148145
parser.add_argument(
149146
"--tmp",
150147
help="Temporary folder for cache, intermediate files, ...",
151-
type="Path",
148+
type=Path,
152149
dest="tmp_folder",
153150
)
154151

155152
parser.add_argument("--debug", help="Enable verbose output", action="store_true")
156153

157154
parser.add_argument(
158155
"--zimui-dist",
159-
type="Path",
156+
type=Path,
160157
help=(
161158
"Dev option to customize directory containing Vite build output from the "
162159
"ZIM UI Vue.JS application"
@@ -165,7 +162,7 @@ def prepare_context(raw_args: list[str], tmpdir: str) -> None:
165162

166163
parser.add_argument(
167164
"--stats-filename",
168-
type="Path",
165+
type=Path,
169166
help="Path to store the progress JSON file to.",
170167
)
171168

@@ -216,8 +213,8 @@ def prepare_context(raw_args: list[str], tmpdir: str) -> None:
216213
# initialize some context properties that are "dynamic" (i.e. not constant
217214
# values like an int, a string, ...)
218215
if not args_dict.get("tmp_folder", None):
219-
if tmp_from_env := os.getenv("MINDTOUCH_TMP"):
220-
args_dict["tmp_folder"] = Path(tmp_from_env)
216+
if MINDTOUCH_TMP:
217+
args_dict["tmp_folder"] = Path(MINDTOUCH_TMP)
221218
else:
222219
args_dict["tmp_folder"] = Path(tmpdir)
223220

scraper/src/mindtouch2zim/zimconfig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def fmt(string: str) -> str:
3939
except KeyError as e:
4040
valid_placeholders = ", ".join(sorted(placeholders.keys()))
4141
raise InvalidFormatError(
42-
f"Invalid placeholder {e!s} in {string!r}, "
42+
f"Invalid placeholder {e!s} in {string!s}, "
4343
f"valid placeholders are: {valid_placeholders}"
4444
) from e
4545

scraper/tests/test_entrypoint.py

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import os
21
import re
32
import tempfile
43
from pathlib import Path
54
from typing import Any
65

76
import pytest
87

8+
import mindtouch2zim.entrypoint
99
from mindtouch2zim.context import Context
1010
from mindtouch2zim.entrypoint import prepare_context
1111

@@ -101,33 +101,17 @@ def test_entrypoint_defaults(
101101
assert context.__getattribute__(context_name) == expected_context_value
102102

103103

104-
@pytest.mark.parametrize(
105-
"env_var_name, env_var_value, context_name, expected_context_value",
106-
[
107-
pytest.param(
108-
"MINDTOUCH_TMP",
109-
"../foo/bar",
110-
"tmp_folder",
111-
Path("../foo/bar"),
112-
id="tmp_folder",
113-
),
114-
],
115-
)
116104
def test_entrypoint_defaults_env_var(
117105
good_cli_args: list[str],
118106
tmpdir: str,
119-
env_var_name: str,
120-
env_var_value: str,
121-
context_name: str,
122-
expected_context_value: Any,
123107
):
124108
"""Not passing optional args sources Context default in environement variable."""
125109
try:
126-
os.environ[env_var_name] = env_var_value
110+
mindtouch2zim.entrypoint.MINDTOUCH_TMP = "../foo/bar"
127111
prepare_context(good_cli_args, tmpdir)
128-
assert context.__getattribute__(context_name) == expected_context_value
112+
assert context.tmp_folder == Path("../foo/bar")
129113
finally:
130-
os.environ.pop(env_var_name)
114+
mindtouch2zim.entrypoint.MINDTOUCH_TMP = None
131115

132116

133117
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)