itqan-cli 0.6.0__tar.gz → 0.8.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.
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/CHANGELOG.md +30 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/PKG-INFO +3 -2
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/README.md +2 -1
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/pyproject.toml +2 -1
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/src/itqan_cli/browse.py +11 -2
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/src/itqan_cli/client.py +53 -5
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/src/itqan_cli/main.py +17 -6
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/tests/test_browse.py +50 -1
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/tests/test_cli_integration.py +34 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/tests/test_client.py +96 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/.gitignore +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/LICENSE +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/RELEASING.md +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/dart/.gitignore +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/dart/README.md +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/dart/analysis_options.yaml +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/dart/bin/itqan.dart +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/dart/lib/itqan_cli.dart +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/dart/lib/src/launcher.dart +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/dart/lib/src/version.dart +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/dart/pubspec.yaml +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/dart/test/launcher_test.dart +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/npm/README.md +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/npm/bin/itqan.js +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/scripts/dart_package.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/scripts/homebrew_formula.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/scripts/npm_packages.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/src/itqan_cli/__init__.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/src/itqan_cli/__main__.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/src/itqan_cli/add.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/src/itqan_cli/autoupdate.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/src/itqan_cli/columns_comment.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/src/itqan_cli/credentials.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/src/itqan_cli/downloader.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/src/itqan_cli/exceptions.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/src/itqan_cli/flutter.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/src/itqan_cli/init_template.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/src/itqan_cli/lockfile.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/src/itqan_cli/manifest.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/src/itqan_cli/progress.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/src/itqan_cli/semver.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/src/itqan_cli/updates.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/src/itqan_cli/usage.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/tests/__init__.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/tests/conftest.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/tests/test_access.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/tests/test_add.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/tests/test_assets_dir.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/tests/test_autoupdate.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/tests/test_columns_comment.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/tests/test_dart_package.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/tests/test_downloader.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/tests/test_entry_points.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/tests/test_flutter.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/tests/test_homebrew_formula.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/tests/test_init.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/tests/test_install_progress.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/tests/test_languages.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/tests/test_lockfile.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/tests/test_login.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/tests/test_manifest.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/tests/test_npm_packages.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/tests/test_progress.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/tests/test_updates.py +0 -0
- {itqan_cli-0.6.0 → itqan_cli-0.8.0}/tests/test_usage.py +0 -0
|
@@ -1,3 +1,33 @@
|
|
|
1
|
+
## v0.8.0 (2026-11-29)
|
|
2
|
+
|
|
3
|
+
### Feat
|
|
4
|
+
|
|
5
|
+
- `itqan browse` shows a recitation's timing level when the registry sends it: the CATEGORY column
|
|
6
|
+
reads `recitation (ayah timing)`, and `--json` includes `"timing_level"`. Nothing changes when
|
|
7
|
+
the registry doesn't send the field.
|
|
8
|
+
|
|
9
|
+
### Fix
|
|
10
|
+
|
|
11
|
+
- when the registry rejects your API key (not valid, revoked or expired), every command now says
|
|
12
|
+
so in one message and tells you to run `itqan login` with a new key, or `itqan logout` (and drop
|
|
13
|
+
`--api-key` / `ITQAN_API_KEY`) to continue without one. A failed `itqan install` no longer makes
|
|
14
|
+
a second catalog call that would fail on the same key.
|
|
15
|
+
- "Cannot satisfy version constraints" is now picked from the registry's error name, so it still
|
|
16
|
+
shows when the registry reports these errors with status 400 instead of 422.
|
|
17
|
+
|
|
18
|
+
## v0.7.0 (2026-11-14)
|
|
19
|
+
|
|
20
|
+
### BREAKING CHANGE
|
|
21
|
+
|
|
22
|
+
- the registry now reports tafsirs and translations as category `text` with tags such as `tafsir`
|
|
23
|
+
or `translation`. `itqan browse --category tafsir` and `--category translation` now fail with
|
|
24
|
+
the registry's `category_renamed` error; use `--tag` instead.
|
|
25
|
+
|
|
26
|
+
### Feat
|
|
27
|
+
|
|
28
|
+
- `itqan browse` shows each package's tags, in the table and in `--json` output.
|
|
29
|
+
- `itqan browse --tag/-t <tag>` filters the catalog by tag, for example `itqan browse --tag tafsir`.
|
|
30
|
+
|
|
1
31
|
## v0.6.0 (2026-11-03)
|
|
2
32
|
|
|
3
33
|
### Feat
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: itqan-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.8.0
|
|
4
4
|
Summary: Itqan Quranic Asset Manager: install and pin Itqan Quranic assets in your project.
|
|
5
5
|
Project-URL: Homepage, https://github.com/Itqan-community/itqan-cli
|
|
6
6
|
Project-URL: Repository, https://github.com/Itqan-community/itqan-cli
|
|
@@ -195,7 +195,8 @@ The asset's name is the one `itqan browse` and each asset's page in the
|
|
|
195
195
|
|
|
196
196
|
In `itqan browse`, type to filter the list, press Enter to add the highlighted asset, or press
|
|
197
197
|
Space on several and then Enter. `itqan browse tafsir` starts with a search, and
|
|
198
|
-
`itqan browse --
|
|
198
|
+
`itqan browse --tag translation` shows one kind of text asset (`--category font` does the same
|
|
199
|
+
for the other categories).
|
|
199
200
|
|
|
200
201
|
## Use the assets in your app
|
|
201
202
|
|
|
@@ -164,7 +164,8 @@ The asset's name is the one `itqan browse` and each asset's page in the
|
|
|
164
164
|
|
|
165
165
|
In `itqan browse`, type to filter the list, press Enter to add the highlighted asset, or press
|
|
166
166
|
Space on several and then Enter. `itqan browse tafsir` starts with a search, and
|
|
167
|
-
`itqan browse --
|
|
167
|
+
`itqan browse --tag translation` shows one kind of text asset (`--category font` does the same
|
|
168
|
+
for the other categories).
|
|
168
169
|
|
|
169
170
|
## Use the assets in your app
|
|
170
171
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "itqan-cli"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.8.0"
|
|
4
4
|
description = "Itqan Quranic Asset Manager: install and pin Itqan Quranic assets in your project."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "MIT"
|
|
@@ -85,5 +85,6 @@ name = "cz_conventional_commits"
|
|
|
85
85
|
version_provider = "pep621"
|
|
86
86
|
version_scheme = "pep440"
|
|
87
87
|
tag_format = "v$version"
|
|
88
|
+
major_version_zero = true
|
|
88
89
|
update_changelog_on_bump = true
|
|
89
90
|
changelog_file = "CHANGELOG.md"
|
|
@@ -207,13 +207,20 @@ def access_footer(packages: list[CatalogPackage], has_api_key: bool) -> list[str
|
|
|
207
207
|
return lines
|
|
208
208
|
|
|
209
209
|
|
|
210
|
+
def kind_text(package: CatalogPackage) -> str:
|
|
211
|
+
"""The category, narrowed by the tags of a text asset (`text: tafsir`) and the
|
|
212
|
+
timing level of a timed recitation (`recitation (ayah timing)`)."""
|
|
213
|
+
kind = f"{package.category}: {', '.join(package.tags)}" if package.tags else package.category
|
|
214
|
+
return f"{kind} ({package.timing_level} timing)" if package.timing_level else kind
|
|
215
|
+
|
|
216
|
+
|
|
210
217
|
def render_table(packages: list[CatalogPackage], targets: set[Target]) -> str:
|
|
211
218
|
"""Plain-text listing for pipes, CI and `--no-interactive`."""
|
|
212
219
|
header = ("SLUG", "CATEGORY", "LANGUAGES", "LATEST", "ACCESS", "NAME")
|
|
213
220
|
rows = [header] + [
|
|
214
221
|
(
|
|
215
222
|
("* " if package.languages and not missing_languages(targets, package) else "") + package.slug,
|
|
216
|
-
package
|
|
223
|
+
kind_text(package),
|
|
217
224
|
_languages_text(package),
|
|
218
225
|
_latest_text(package),
|
|
219
226
|
_access_column(package),
|
|
@@ -231,6 +238,8 @@ def to_json(packages: list[CatalogPackage], targets: set[Target]) -> list[dict]:
|
|
|
231
238
|
"slug": package.slug,
|
|
232
239
|
"name": package.name,
|
|
233
240
|
"category": package.category,
|
|
241
|
+
"tags": list(package.tags),
|
|
242
|
+
"timing_level": package.timing_level,
|
|
234
243
|
"is_open_access": package.is_open_access,
|
|
235
244
|
"access": package.access,
|
|
236
245
|
"access_request_url": package.access_request_url,
|
|
@@ -261,7 +270,7 @@ def choice_titles(packages: list[CatalogPackage], reasons: list[str | None], max
|
|
|
261
270
|
"""One aligned row per package that fits in ``max_width`` columns, leaving
|
|
262
271
|
room for the picker's ` (<reason>)` note on rows that can't be picked."""
|
|
263
272
|
columns = [
|
|
264
|
-
(package.slug, package
|
|
273
|
+
(package.slug, kind_text(package), _languages_text(package), _latest_text(package)) for package in packages
|
|
265
274
|
]
|
|
266
275
|
widths = [max(len(row[col]) for row in columns) for col in range(4)]
|
|
267
276
|
titles = []
|
|
@@ -63,6 +63,11 @@ class CatalogPackage:
|
|
|
63
63
|
# a registry that predates it, which only says whether the asset is open.
|
|
64
64
|
access: str | None = None
|
|
65
65
|
access_request_url: str | None = None
|
|
66
|
+
# Text assets: what kind of text it holds (tafsir, translation, ...). Slugs only.
|
|
67
|
+
tags: tuple[str, ...] = ()
|
|
68
|
+
# Recitations: the finest timing they have (ayah | word | sentence); None without
|
|
69
|
+
# timings, for other categories, or from a registry that predates it.
|
|
70
|
+
timing_level: str | None = None
|
|
66
71
|
|
|
67
72
|
|
|
68
73
|
@dataclass(frozen=True, slots=True)
|
|
@@ -122,6 +127,39 @@ def _error_detail(response: requests.Response) -> str:
|
|
|
122
127
|
return f": {reason}" if reason else ""
|
|
123
128
|
|
|
124
129
|
|
|
130
|
+
INVALID_API_KEY = "invalid_api_key"
|
|
131
|
+
INVALID_API_KEY_MESSAGE = (
|
|
132
|
+
"The registry rejected your API key: it is not valid, was revoked or has expired. "
|
|
133
|
+
"Run `itqan login` with a new key, or `itqan logout` (and drop --api-key / ITQAN_API_KEY) "
|
|
134
|
+
"to continue without one."
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
# The registry's version-resolution errors. Older registries sent them with 422,
|
|
139
|
+
# newer ones with 400 (like every other validation error), so key on the name.
|
|
140
|
+
VERSION_CONSTRAINT_ERRORS = frozenset(
|
|
141
|
+
{
|
|
142
|
+
"invalid_version_constraint",
|
|
143
|
+
"unsatisfiable_version_constraint",
|
|
144
|
+
"no_eligible_package_versions",
|
|
145
|
+
"canonical_version_collision",
|
|
146
|
+
"category_not_installable",
|
|
147
|
+
}
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def _raise_if_invalid_key(response: requests.Response) -> None:
|
|
152
|
+
"""Turn the registry's `401 invalid_api_key` into one clear, actionable error."""
|
|
153
|
+
if response.status_code != 401:
|
|
154
|
+
return
|
|
155
|
+
try:
|
|
156
|
+
body = response.json()
|
|
157
|
+
except ValueError:
|
|
158
|
+
return
|
|
159
|
+
if isinstance(body, dict) and body.get("error_name") == INVALID_API_KEY:
|
|
160
|
+
raise RegistryApiError(INVALID_API_KEY_MESSAGE, status_code=401, error_name=INVALID_API_KEY)
|
|
161
|
+
|
|
162
|
+
|
|
125
163
|
class RegistryClient:
|
|
126
164
|
"""HTTP Client for Itqan Package Registry API."""
|
|
127
165
|
|
|
@@ -164,6 +202,7 @@ class RegistryClient:
|
|
|
164
202
|
open_access: bool | None = None,
|
|
165
203
|
search: str | None = None,
|
|
166
204
|
category: str | None = None,
|
|
205
|
+
tag: str | None = None,
|
|
167
206
|
page_size: int = 50,
|
|
168
207
|
) -> list[CatalogPackage]:
|
|
169
208
|
"""Call GET /packages/ for the first page of installable assets.
|
|
@@ -172,7 +211,7 @@ class RegistryClient:
|
|
|
172
211
|
RegistryApiError when the registry can't be reached or answers badly.
|
|
173
212
|
"""
|
|
174
213
|
packages, _ = self._catalog_page(
|
|
175
|
-
open_access=open_access, search=search, category=category, page=1, page_size=page_size
|
|
214
|
+
open_access=open_access, search=search, category=category, tag=tag, page=1, page_size=page_size
|
|
176
215
|
)
|
|
177
216
|
return packages
|
|
178
217
|
|
|
@@ -182,6 +221,7 @@ class RegistryClient:
|
|
|
182
221
|
open_access: bool | None = None,
|
|
183
222
|
search: str | None = None,
|
|
184
223
|
category: str | None = None,
|
|
224
|
+
tag: str | None = None,
|
|
185
225
|
page_size: int = 50,
|
|
186
226
|
) -> list[CatalogPackage]:
|
|
187
227
|
"""Every installable asset matching the filters, following GET /packages/ pagination.
|
|
@@ -193,7 +233,7 @@ class RegistryClient:
|
|
|
193
233
|
page = 1
|
|
194
234
|
while True:
|
|
195
235
|
batch, count = self._catalog_page(
|
|
196
|
-
open_access=open_access, search=search, category=category, page=page, page_size=page_size
|
|
236
|
+
open_access=open_access, search=search, category=category, tag=tag, page=page, page_size=page_size
|
|
197
237
|
)
|
|
198
238
|
packages.extend(batch)
|
|
199
239
|
if not batch or len(packages) >= count:
|
|
@@ -206,6 +246,7 @@ class RegistryClient:
|
|
|
206
246
|
open_access: bool | None,
|
|
207
247
|
search: str | None,
|
|
208
248
|
category: str | None,
|
|
249
|
+
tag: str | None,
|
|
209
250
|
page: int,
|
|
210
251
|
page_size: int,
|
|
211
252
|
) -> tuple[list[CatalogPackage], int]:
|
|
@@ -219,12 +260,15 @@ class RegistryClient:
|
|
|
219
260
|
params["search"] = search
|
|
220
261
|
if category:
|
|
221
262
|
params["category"] = category
|
|
263
|
+
if tag:
|
|
264
|
+
params["tag"] = tag
|
|
222
265
|
try:
|
|
223
266
|
response = self.session.get(
|
|
224
267
|
f"{self.base_url}/packages/", params=params, headers=self._headers(), timeout=self.timeout
|
|
225
268
|
)
|
|
226
269
|
except requests.RequestException as exc:
|
|
227
270
|
raise RegistryApiError(f"Failed to connect to package registry at {self.base_url}: {exc}") from exc
|
|
271
|
+
_raise_if_invalid_key(response)
|
|
228
272
|
if response.status_code != 200:
|
|
229
273
|
raise RegistryApiError(
|
|
230
274
|
f"Registry catalog request failed with status {response.status_code}{_error_detail(response)}",
|
|
@@ -241,6 +285,8 @@ class RegistryClient:
|
|
|
241
285
|
publisher_name=item.get("publisher_name"),
|
|
242
286
|
access=item.get("access"),
|
|
243
287
|
access_request_url=item.get("access_request_url"),
|
|
288
|
+
tags=tuple(tag_item["slug"] for tag_item in item.get("tags") or ()),
|
|
289
|
+
timing_level=item.get("timing_level"),
|
|
244
290
|
languages=tuple(
|
|
245
291
|
CatalogLanguage(
|
|
246
292
|
language=lang["language"],
|
|
@@ -268,6 +314,7 @@ class RegistryClient:
|
|
|
268
314
|
response = self.session.get(f"{self.base_url}/packages/me/", headers=self._headers(), timeout=self.timeout)
|
|
269
315
|
except requests.RequestException as exc:
|
|
270
316
|
raise RegistryApiError(f"Failed to connect to package registry at {self.base_url}: {exc}") from exc
|
|
317
|
+
_raise_if_invalid_key(response)
|
|
271
318
|
if response.status_code != 200:
|
|
272
319
|
raise RegistryApiError(
|
|
273
320
|
f"API key check failed with status {response.status_code}{_error_detail(response)}",
|
|
@@ -351,6 +398,7 @@ class RegistryClient:
|
|
|
351
398
|
raise RegistryApiError(f"Failed to parse registry API response: {exc}") from exc
|
|
352
399
|
|
|
353
400
|
# Handle API Error responses
|
|
401
|
+
_raise_if_invalid_key(response)
|
|
354
402
|
status_code = response.status_code
|
|
355
403
|
error_name: str | None = None
|
|
356
404
|
message = f"Registry request failed with status {status_code}"
|
|
@@ -363,7 +411,9 @@ class RegistryClient:
|
|
|
363
411
|
except Exception:
|
|
364
412
|
message = response.text or message
|
|
365
413
|
|
|
366
|
-
if status_code ==
|
|
414
|
+
if error_name in VERSION_CONSTRAINT_ERRORS or status_code == 422:
|
|
415
|
+
friendly_msg = f"Cannot satisfy version constraints: {message}"
|
|
416
|
+
elif status_code == 401:
|
|
367
417
|
friendly_msg = f"Authentication required (API key missing or invalid): {message}"
|
|
368
418
|
elif status_code == 403:
|
|
369
419
|
friendly_msg = f"Access denied for requested assets (approved access required): {message}"
|
|
@@ -374,8 +424,6 @@ class RegistryClient:
|
|
|
374
424
|
f"Version removed from the registry: {message} "
|
|
375
425
|
"Run `itqan install --force` to resolve another version, or change it in your manifest."
|
|
376
426
|
)
|
|
377
|
-
elif status_code == 422:
|
|
378
|
-
friendly_msg = f"Cannot satisfy version constraints: {message}"
|
|
379
427
|
else:
|
|
380
428
|
friendly_msg = f"Registry API error [{status_code}]: {message}"
|
|
381
429
|
|
|
@@ -13,7 +13,14 @@ import tempfile
|
|
|
13
13
|
import click
|
|
14
14
|
|
|
15
15
|
from itqan_cli import add, autoupdate, browse, credentials, flutter as flutter_pubspec, progress, updates
|
|
16
|
-
from itqan_cli.client import
|
|
16
|
+
from itqan_cli.client import (
|
|
17
|
+
DEFAULT_REGISTRY_URL,
|
|
18
|
+
INVALID_API_KEY,
|
|
19
|
+
CatalogLanguage,
|
|
20
|
+
CatalogPackage,
|
|
21
|
+
RegistryClient,
|
|
22
|
+
ResolvedAssetPayload,
|
|
23
|
+
)
|
|
17
24
|
from itqan_cli.columns_comment import refresh_blocks
|
|
18
25
|
from itqan_cli.downloader import AssetDownloader
|
|
19
26
|
from itqan_cli.exceptions import ItqanCliError, ManifestError, RegistryApiError
|
|
@@ -309,7 +316,8 @@ def install_command(
|
|
|
309
316
|
sys.exit(exit_code)
|
|
310
317
|
except ItqanCliError as exc:
|
|
311
318
|
click.echo(f"Error: {exc.message}", err=True)
|
|
312
|
-
|
|
319
|
+
# A rejected key fails every catalog call too, so there is nothing more to explain.
|
|
320
|
+
if isinstance(exc, RegistryApiError) and exc.status_code in (401, 403) and exc.error_name != INVALID_API_KEY:
|
|
313
321
|
_explain_access(Path(manifest_path), registry_url, api_key)
|
|
314
322
|
sys.exit(exc.exit_code)
|
|
315
323
|
except Exception as exc:
|
|
@@ -529,6 +537,7 @@ def init_command(manifest_path: str, assets_dir: str, registry_url: str, api_key
|
|
|
529
537
|
browse_command.callback(
|
|
530
538
|
query=None,
|
|
531
539
|
category=None,
|
|
540
|
+
tag=None,
|
|
532
541
|
manifest_path=str(m_path),
|
|
533
542
|
lockfile_path="itqan-assets.lock",
|
|
534
543
|
interactive=True,
|
|
@@ -546,7 +555,8 @@ def init_command(manifest_path: str, assets_dir: str, registry_url: str, api_key
|
|
|
546
555
|
|
|
547
556
|
@cli.command("browse", short_help="Search the catalog and add assets to the manifest.")
|
|
548
557
|
@click.argument("query", required=False)
|
|
549
|
-
@click.option("--category", "-c", default=None, help="Only assets of this category (mushaf,
|
|
558
|
+
@click.option("--category", "-c", default=None, help="Only assets of this category (mushaf, font, text, ...).")
|
|
559
|
+
@click.option("--tag", "-t", default=None, help="Only text assets with this tag (tafsir, translation, ...).")
|
|
550
560
|
@click.option(
|
|
551
561
|
"--manifest",
|
|
552
562
|
"-m",
|
|
@@ -587,6 +597,7 @@ def init_command(manifest_path: str, assets_dir: str, registry_url: str, api_key
|
|
|
587
597
|
def browse_command(
|
|
588
598
|
query: str | None,
|
|
589
599
|
category: str | None,
|
|
600
|
+
tag: str | None,
|
|
590
601
|
manifest_path: str,
|
|
591
602
|
lockfile_path: str,
|
|
592
603
|
interactive: bool | None,
|
|
@@ -596,7 +607,7 @@ def browse_command(
|
|
|
596
607
|
) -> None:
|
|
597
608
|
"""Browse installable assets and add them to itqan-assets.yaml.
|
|
598
609
|
|
|
599
|
-
QUERY searches names, slugs, descriptions and
|
|
610
|
+
QUERY searches names, slugs, descriptions, publishers and tags on the registry;
|
|
600
611
|
without it, every asset is listed and you can filter by typing in the picker.
|
|
601
612
|
"""
|
|
602
613
|
if interactive is None:
|
|
@@ -610,7 +621,7 @@ def browse_command(
|
|
|
610
621
|
manifest = load_manifest(m_path) if m_path.exists() else None
|
|
611
622
|
targets = browse.manifest_targets(manifest)
|
|
612
623
|
client = RegistryClient(base_url=registry_url, api_key=api_key)
|
|
613
|
-
packages = client.list_all_packages(search=query, category=category)
|
|
624
|
+
packages = client.list_all_packages(search=query, category=category, tag=tag)
|
|
614
625
|
except ItqanCliError as exc:
|
|
615
626
|
click.echo(f"Error: {exc.message}", err=True)
|
|
616
627
|
sys.exit(exc.exit_code)
|
|
@@ -619,7 +630,7 @@ def browse_command(
|
|
|
619
630
|
click.echo(json.dumps(browse.to_json(packages, targets), ensure_ascii=False, indent=2))
|
|
620
631
|
return
|
|
621
632
|
if not packages:
|
|
622
|
-
click.echo("No assets match." if query or category else "The registry has no installable assets yet.")
|
|
633
|
+
click.echo("No assets match." if query or category or tag else "The registry has no installable assets yet.")
|
|
623
634
|
return
|
|
624
635
|
if not interactive:
|
|
625
636
|
click.echo(browse.render_table(packages, targets))
|
|
@@ -20,7 +20,8 @@ REGISTRY = "https://cms.itqan.dev"
|
|
|
20
20
|
MULTILINGUAL = {
|
|
21
21
|
"slug": "tafsir-jalalayn",
|
|
22
22
|
"name": "Tafsir al-Jalalayn",
|
|
23
|
-
"category": "
|
|
23
|
+
"category": "text",
|
|
24
|
+
"tags": [{"slug": "tafsir", "name": "Tafsir"}],
|
|
24
25
|
"is_open_access": True,
|
|
25
26
|
"publisher_name": "Publisher",
|
|
26
27
|
"languages": [
|
|
@@ -89,6 +90,18 @@ def test_list_all_packages_where_catalog_has_two_pages_should_return_both():
|
|
|
89
90
|
assert [package.slug for package in packages] == ["mushaf-madinah", "tafsir-jalalayn"]
|
|
90
91
|
|
|
91
92
|
|
|
93
|
+
@responses.activate
|
|
94
|
+
def test_list_all_packages_where_tag_given_should_send_it():
|
|
95
|
+
# Arrange
|
|
96
|
+
_mock_catalog([MULTILINGUAL], query={"page_size": "50", "tag": "tafsir"})
|
|
97
|
+
|
|
98
|
+
# Act
|
|
99
|
+
packages = RegistryClient(base_url=REGISTRY).list_all_packages(tag="tafsir")
|
|
100
|
+
|
|
101
|
+
# Assert
|
|
102
|
+
assert [package.tags for package in packages] == [("tafsir",)]
|
|
103
|
+
|
|
104
|
+
|
|
92
105
|
@responses.activate
|
|
93
106
|
def test_list_all_packages_where_search_and_category_given_should_send_them():
|
|
94
107
|
# Arrange
|
|
@@ -185,6 +198,42 @@ def test_render_table_where_no_published_version_should_not_mark_it_in_manifest(
|
|
|
185
198
|
assert "* " not in row
|
|
186
199
|
|
|
187
200
|
|
|
201
|
+
def test_kind_text_where_recitation_has_timing_level_should_show_it():
|
|
202
|
+
# Arrange
|
|
203
|
+
package = CatalogPackage(
|
|
204
|
+
slug="husary", name="Husary", category="recitation", is_open_access=True, languages=(), timing_level="ayah"
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
# Act
|
|
208
|
+
kind = browse.kind_text(package)
|
|
209
|
+
|
|
210
|
+
# Assert
|
|
211
|
+
assert kind == "recitation (ayah timing)"
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def test_kind_text_where_no_timing_level_should_show_only_the_category():
|
|
215
|
+
# Arrange
|
|
216
|
+
package = _package(SINGLE)
|
|
217
|
+
|
|
218
|
+
# Act
|
|
219
|
+
kind = browse.kind_text(package)
|
|
220
|
+
|
|
221
|
+
# Assert
|
|
222
|
+
assert kind == "mushaf"
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
@responses.activate
|
|
226
|
+
def test_list_packages_where_catalog_reports_timing_level_should_parse_it():
|
|
227
|
+
# Arrange
|
|
228
|
+
_mock_catalog([{**SINGLE, "timing_level": "ayah"}, MULTILINGUAL])
|
|
229
|
+
|
|
230
|
+
# Act
|
|
231
|
+
packages = RegistryClient(REGISTRY).list_packages(page_size=50)
|
|
232
|
+
|
|
233
|
+
# Assert
|
|
234
|
+
assert [p.timing_level for p in packages] == ["ayah", None]
|
|
235
|
+
|
|
236
|
+
|
|
188
237
|
# --- editing the manifest -------------------------------------------------------
|
|
189
238
|
|
|
190
239
|
|
|
@@ -154,6 +154,40 @@ assets:
|
|
|
154
154
|
assert "Authentication required" in result.output
|
|
155
155
|
|
|
156
156
|
|
|
157
|
+
@responses.activate
|
|
158
|
+
def test_install_command_where_api_key_rejected_should_tell_how_to_fix_it_without_more_calls(
|
|
159
|
+
runner: CliRunner, tmp_path: Path
|
|
160
|
+
):
|
|
161
|
+
manifest_path = tmp_path / "itqan-assets.yaml"
|
|
162
|
+
manifest_path.write_bytes(b"""schema_version: 1
|
|
163
|
+
assets:
|
|
164
|
+
quran-uthmani-hafs:
|
|
165
|
+
version: "^2.1.0"
|
|
166
|
+
""")
|
|
167
|
+
registry_url = "https://api.itqan.dev/api"
|
|
168
|
+
responses.add(
|
|
169
|
+
responses.POST,
|
|
170
|
+
f"{registry_url}/packages/resolve/manifest/",
|
|
171
|
+
json={
|
|
172
|
+
"error_name": "invalid_api_key",
|
|
173
|
+
"message": "The API key is not valid or has been revoked.",
|
|
174
|
+
"extra": None,
|
|
175
|
+
},
|
|
176
|
+
status=401,
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
result = runner.invoke(
|
|
180
|
+
cli,
|
|
181
|
+
["install", "--manifest", str(manifest_path), "--registry-url", registry_url, "--api-key", "stale.key"],
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
assert result.exit_code == 1
|
|
185
|
+
assert "rejected your API key" in result.output
|
|
186
|
+
assert "itqan login" in result.output
|
|
187
|
+
# No catalog lookup to explain access: it would fail on the same key.
|
|
188
|
+
assert [call.request.method for call in responses.calls] == ["POST"]
|
|
189
|
+
|
|
190
|
+
|
|
157
191
|
@responses.activate
|
|
158
192
|
def test_install_command_where_locked_version_withdrawn_should_install_it_and_warn(runner: CliRunner, tmp_path: Path):
|
|
159
193
|
manifest_path = tmp_path / "itqan-assets.yaml"
|
|
@@ -60,6 +60,46 @@ def test_resolve_manifest_where_api_key_missing_should_raise_registry_api_error_
|
|
|
60
60
|
assert "Authentication required" in exc_info.value.message
|
|
61
61
|
|
|
62
62
|
|
|
63
|
+
@responses.activate
|
|
64
|
+
def test_resolve_manifest_where_api_key_rejected_should_raise_invalid_api_key_error():
|
|
65
|
+
base_url = "https://api.itqan.dev/api"
|
|
66
|
+
responses.add(
|
|
67
|
+
responses.POST,
|
|
68
|
+
f"{base_url}/packages/resolve/manifest/",
|
|
69
|
+
json={"error_name": "invalid_api_key", "message": "The API key has expired.", "extra": None},
|
|
70
|
+
status=401,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
client = RegistryClient(base_url=base_url, api_key="stale.key")
|
|
74
|
+
with pytest.raises(RegistryApiError) as exc_info:
|
|
75
|
+
client.resolve_manifest({"quran": "1.0.0"})
|
|
76
|
+
|
|
77
|
+
assert (exc_info.value.status_code, exc_info.value.error_name) == (401, "invalid_api_key")
|
|
78
|
+
assert "itqan login" in exc_info.value.message
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@responses.activate
|
|
82
|
+
def test_list_all_packages_where_api_key_rejected_should_raise_invalid_api_key_error():
|
|
83
|
+
base_url = "https://api.itqan.dev/api"
|
|
84
|
+
responses.add(
|
|
85
|
+
responses.GET,
|
|
86
|
+
f"{base_url}/packages/",
|
|
87
|
+
json={
|
|
88
|
+
"error_name": "invalid_api_key",
|
|
89
|
+
"message": "The API key is not valid or has been revoked.",
|
|
90
|
+
"extra": None,
|
|
91
|
+
},
|
|
92
|
+
status=401,
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
client = RegistryClient(base_url=base_url, api_key="stale.key")
|
|
96
|
+
with pytest.raises(RegistryApiError) as exc_info:
|
|
97
|
+
client.list_all_packages()
|
|
98
|
+
|
|
99
|
+
assert (exc_info.value.status_code, exc_info.value.error_name) == (401, "invalid_api_key")
|
|
100
|
+
assert "rejected your API key" in exc_info.value.message
|
|
101
|
+
|
|
102
|
+
|
|
63
103
|
@responses.activate
|
|
64
104
|
def test_resolve_manifest_where_asset_access_denied_should_raise_registry_api_error_403():
|
|
65
105
|
base_url = "https://api.itqan.dev/api"
|
|
@@ -96,6 +136,62 @@ def test_resolve_manifest_where_no_version_satisfies_constraint_should_raise_reg
|
|
|
96
136
|
assert "Cannot satisfy version constraints" in exc_info.value.message
|
|
97
137
|
|
|
98
138
|
|
|
139
|
+
@pytest.mark.parametrize("status", [400, 422])
|
|
140
|
+
@pytest.mark.parametrize(
|
|
141
|
+
"error_name",
|
|
142
|
+
[
|
|
143
|
+
"invalid_version_constraint",
|
|
144
|
+
"unsatisfiable_version_constraint",
|
|
145
|
+
"no_eligible_package_versions",
|
|
146
|
+
"canonical_version_collision",
|
|
147
|
+
"category_not_installable",
|
|
148
|
+
],
|
|
149
|
+
)
|
|
150
|
+
@responses.activate
|
|
151
|
+
def test_resolve_manifest_where_version_constraint_error_should_explain_it_on_old_and_new_registries(
|
|
152
|
+
error_name, status
|
|
153
|
+
):
|
|
154
|
+
# Arrange: the registry moved these errors from 422 to 400; the name stays the same
|
|
155
|
+
base_url = "https://api.itqan.dev/api"
|
|
156
|
+
responses.add(
|
|
157
|
+
responses.POST,
|
|
158
|
+
f"{base_url}/packages/resolve/manifest/",
|
|
159
|
+
json={"error_name": error_name, "message": "No matching version", "extra": None},
|
|
160
|
+
status=status,
|
|
161
|
+
)
|
|
162
|
+
client = RegistryClient(base_url=base_url)
|
|
163
|
+
|
|
164
|
+
# Act
|
|
165
|
+
with pytest.raises(RegistryApiError) as exc_info:
|
|
166
|
+
client.resolve_manifest({"quran": "^99.0.0"})
|
|
167
|
+
|
|
168
|
+
# Assert
|
|
169
|
+
assert exc_info.value.message == "Cannot satisfy version constraints: No matching version"
|
|
170
|
+
assert exc_info.value.status_code == status
|
|
171
|
+
assert exc_info.value.error_name == error_name
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
@responses.activate
|
|
175
|
+
def test_resolve_manifest_where_other_400_error_should_not_blame_version_constraints():
|
|
176
|
+
# Arrange
|
|
177
|
+
base_url = "https://api.itqan.dev/api"
|
|
178
|
+
responses.add(
|
|
179
|
+
responses.POST,
|
|
180
|
+
f"{base_url}/packages/resolve/manifest/",
|
|
181
|
+
json={"error_name": "validation_error", "message": "Invalid Input", "extra": None},
|
|
182
|
+
status=400,
|
|
183
|
+
)
|
|
184
|
+
client = RegistryClient(base_url=base_url)
|
|
185
|
+
|
|
186
|
+
# Act
|
|
187
|
+
with pytest.raises(RegistryApiError) as exc_info:
|
|
188
|
+
client.resolve_manifest({"quran": "^1.0.0"})
|
|
189
|
+
|
|
190
|
+
# Assert
|
|
191
|
+
assert exc_info.value.message == "Registry API error [400]: Invalid Input"
|
|
192
|
+
assert exc_info.value.error_name == "validation_error"
|
|
193
|
+
|
|
194
|
+
|
|
99
195
|
def test_registry_client_where_no_base_url_given_should_default_to_production():
|
|
100
196
|
# Arrange / Act
|
|
101
197
|
client = RegistryClient()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|