Skip to content

Commit

Permalink
chore: Add support for specifying a maximum anki version in addon.json (
Browse files Browse the repository at this point in the history
#802)

* fix: Use `anki.utils.point_version`

* Fix sorting args of browser column

* Update anki version in requirements

* Don't call db.begin() on Anki >= 23.10

* Don't monkey patch `db.begin` on 23.10

* Add PyQt5 requirements

* Add "type:  ignore" comments

* Fix test

* Refactor

* Adjust conversion between version string and int in scripts

* Update tested anki version in addon.json

* Update `generate_manifest` to support `max_anki_version`

* Update `upload_to_ankiweb` to support negative `max_point_version`

* Refactor

* Merge main
  • Loading branch information
RisingOrange authored Nov 13, 2023
1 parent 0810803 commit 1ec1b2b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
17 changes: 16 additions & 1 deletion scripts/generate_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ def generate_manifest():
"homepage": addon_properties["contact"],
"conflicts": addon_properties["conflicts"],
"min_point_version": to_point_version(addon_properties["min_anki_version"]),
"max_point_version": to_point_version(addon_properties["tested_anki_version"]),
"max_point_version": _max_point_version(
addon_properties.get("max_anki_version"),
addon_properties.get("tested_anki_version"),
),
}
json.dump(manifest, MANIFEST_FILE.open("w"), indent=4)

Expand All @@ -34,5 +37,17 @@ def generate_manifest():
f.write("\n")


def _max_point_version(
max_anki_version: str = None, tested_anki_version: str = None
) -> int:
if max_anki_version is not None:
# A negative max_point_version prevents the add-on from being downloaded on any newer versions.
return -1 * to_point_version(max_anki_version)
elif tested_anki_version is not None:
return to_point_version(tested_anki_version)

assert False, "Either max_anki_version or tested_anki_version must be specified"


if __name__ == "__main__":
generate_manifest()
5 changes: 4 additions & 1 deletion scripts/upload_to_ankiweb.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ def upload(
xpath = '//div[@class="form-inline"]//input[2]'
web.type("", xpath=xpath)
time.sleep(0.3)
web.type(to_version_str(max_point_version), xpath=xpath)
# Preserve sign when converting to version string.
# A negative version prevents the add-on from being downloaded on any newer versions.
version_str = f"{'-' if max_point_version < 0 else ''}{to_version_str(abs(max_point_version))}"
web.type(version_str, xpath=xpath)

web.click("Save")

Expand Down

0 comments on commit 1ec1b2b

Please sign in to comment.