From ce9d45e1d2a60449aaea74275444cd3844b7fa25 Mon Sep 17 00:00:00 2001 From: cary-rowen Date: Thu, 9 Mar 2023 01:05:20 +0800 Subject: [PATCH] Updated add-on templates, updated for compatibility with NVDA2023.1. --- .pre-commit-config.yaml | 7 +++ .vscode/extensions.json | 12 +++++ .vscode/settings.json | 25 +++++++++++ addon/doc/zh_CN/readme.md | 8 +++- buildVars.py | 16 ++++--- readme.md | 8 +++- sconstruct | 95 ++++++++++++++++++++++++++++++++++++++- 7 files changed, 159 insertions(+), 12 deletions(-) create mode 100644 .pre-commit-config.yaml create mode 100644 .vscode/extensions.json create mode 100644 .vscode/settings.json diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..dd7a9d6 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,7 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.3.0 + hooks: + - id: check-ast + - id: check-case-conflict + - id: check-yaml diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..75fa7aa --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,12 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. + // Extension identifier format: ${publisher}.${name}. Example: vscode.csharp + // List of extensions which should be recommended for users of this workspace. + "recommendations": [ + "ms-python.python", + "ms-python.vscode-pylance", + "redhat.vscode-yaml" + ], + // List of extensions recommended by VS Code that should not be recommended for users of this workspace. + "unwantedRecommendations": [] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7c58677 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,25 @@ +{ + "editor.accessibilitySupport": "on", + "python.linting.enabled": true, + "python.linting.maxNumberOfProblems": 10000, + "python.linting.flake8Args": [ + "--config=flake8.ini" + ], + "python.linting.flake8Enabled": true, + "python.linting.pylintEnabled": false, + "python.autoComplete.extraPaths": [ + "../nvda/source", + "../nvda/miscDeps/python" + ], + "files.insertFinalNewline": true, + "files.trimFinalNewlines": true, + "editor.insertSpaces": false, + "python.analysis.diagnosticSeverityOverrides": { + "reportUndefinedVariable": "none" + }, + "python.analysis.extraPaths": [ + "../nvda/source", + "../nvda/miscDeps/python" + ], + "python.defaultInterpreterPath": "../nvda/.venv/scripts/python.exe" +} diff --git a/addon/doc/zh_CN/readme.md b/addon/doc/zh_CN/readme.md index ff72d05..6c14bd8 100644 --- a/addon/doc/zh_CN/readme.md +++ b/addon/doc/zh_CN/readme.md @@ -3,7 +3,7 @@ 作者: Ibrahim Hamadeh, Cary-Rowen, Belala Toufik NVDA 兼容性:2018.3 及更高版本 -下载 [2.7版][1] +下载 [2.8版][1] 该插件可以从选中的文本、剪贴板中的文本或最后一次朗读的文本中提取所包含的链接,并显示在一个弹出对话框的列表内,您可以选择使用已安装的浏览器打开列表中的链接。 @@ -23,6 +23,10 @@ NVDA 兼容性:2018.3 及更高版本 * 如果只有一个链接可以直接使用默认浏览器打开,当然这是一个可选项,在设置面板中可以开启 / 关闭。 * 您还可以在设置面板中设置是否在打开链接后关闭链接对话框。 +## 2.7 的变化 ## +* 更新了插件模板。 +* 将最后测试的 NVDA 版本更新为 2023.1 以兼容最新的 API 更改。 + ## 2.7 的变化 ## @@ -55,4 +59,4 @@ NVDA 兼容性:2018.3 及更高版本 ## 1.0 的变化 ## * 初始版本 -[1]: https://github.com/ibrahim-s/openLinkWith/releases/download/v2.7/openLinkWith-2.7.nvda-addon +[1]: https://github.com/ibrahim-s/openLinkWith/releases/download/v2.8/openLinkWith-2.8.nvda-addon diff --git a/buildVars.py b/buildVars.py index 48d7325..7d081db 100644 --- a/buildVars.py +++ b/buildVars.py @@ -28,25 +28,29 @@ def _(arg): Press the command you assotiated with the addon via input gestures, to display OpenLinkWith dialog. """), # version - "addon_version": "2.7", + "addon_version": "2.8", # Author(s) - "addon_author": u"Ibrahim Hamadeh , Cary Rowen , Belala Toufik", + "addon_author": "Ibrahim Hamadeh , Cary Rowen , Belala Toufik", # URL for the add-on documentation support "addon_url": "https://github.com/ibrahim-s/openLinkWith.git", + # URL for the add-on repository where the source code can be found + "addon_sourceURL": "https://github.com/ibrahim-s/openLinkWith.git", # Documentation file name "addon_docFileName": "readme.html", # Minimum NVDA version supported (e.g. "2018.3.0", minor version is optional) "addon_minimumNVDAVersion": "2018.3.0", # Last NVDA version supported/tested (e.g. "2018.4.0", ideally more recent than minimum version) - "addon_lastTestedNVDAVersion": "2022.1.0", + "addon_lastTestedNVDAVersion": "2023.1.0", # Add-on update channel (default is None, denoting stable releases, # and for development releases, use "dev".) # Do not change unless you know what you are doing! "addon_updateChannel": None, + # Add-on license such as GPL 2 + "addon_license": None, + # URL for the license document the ad-on is licensed under + "addon_licenseURL": None, } -import os.path - # Define the python files that are the sources of your add-on. # You can either list every file (using ""/") as a path separator, # or use glob expressions. @@ -55,7 +59,7 @@ def _(arg): # pythonSources = ["addon/globalPlugins/*.py"] # For more information on SCons Glob expressions please take a look at: # https://scons.org/doc/production/HTML/scons-user/apd.html -pythonSources = [os.path.join("addon", "globalPlugins", "OpenLinkWith", "*.py"), ] +pythonSources = ["addon/globalPlugins/OpenLinkWith/*.py"] # Files that contain strings for translation. Usually your python sources i18nSources = pythonSources + ["buildVars.py"] diff --git a/readme.md b/readme.md index eb29bfa..d994986 100644 --- a/readme.md +++ b/readme.md @@ -2,7 +2,7 @@ Authors: Ibrahim Hamadeh, Cary Rowen, Belala Toufik NVDA compatibility: 2018.3 and beyond -Download [Version 2.7][1] +Download [Version 2.8][1] This addon is used to extract links either from selected, clipboard, or last spoken text display them in a list in a dialog @@ -24,6 +24,10 @@ and give you the opportunity to open them with several browsers if found on your * If there is only one link, you can choose to be opened directly with the default browser. this obtion can be adjusted in the settings panel. * In the settings panel also, remember that you got the obtion to close the dialog, after activating a link. +## Changes for 2.8 ## +* Updated add-on template. +* Update last tested version to 2023.1, to comply with latest addon api. + ## Changes for 2.7 ## * Now, You can extract the links from the text in last spoken. @@ -61,4 +65,4 @@ So that we have the obtion to close the dialog after activating a link. * Initial version. -[1]: https://github.com/ibrahim-s/openLinkWith/releases/download/v2.7/openLinkWith-2.7.nvda-addon +[1]: https://github.com/ibrahim-s/openLinkWith/releases/download/v2.8/openLinkWith-2.8.nvda-addon diff --git a/sconstruct b/sconstruct index ab61654..d22756e 100644 --- a/sconstruct +++ b/sconstruct @@ -1,5 +1,5 @@ # NVDA add-on template SCONSTRUCT file -# Copyright (C) 2012-2021 Rui Batista, Noelia Martinez, Joseph Lee +# Copyright (C) 2012-2023 Rui Batista, Noelia Martinez, Joseph Lee # This file is covered by the GNU General Public License. # See the file COPYING.txt for more details. @@ -75,8 +75,21 @@ def mdTool(env): env['BUILDERS']['markdown'] = mdBuilder +def validateVersionNumber(key, val, env): + # Used to make sure version major.minor.patch are integers to comply with NV Access add-on store. + # Ignore all this if version number is not specified, in which case json generator will validate this info. + if val == "0.0.0": + return + versionNumber = val.split(".") + if len(versionNumber) < 3: + raise ValueError("versionNumber must have three parts (major.minor.patch)") + if not all([part.isnumeric() for part in versionNumber]): + raise ValueError("versionNumber (major.minor.patch) must be integers") + + vars = Variables() vars.Add("version", "The version of this build", buildVars.addon_info["addon_version"]) +vars.Add("versionNumber", "Version number of the form major.minor.patch", "0.0.0", validateVersionNumber) vars.Add(BoolVariable("dev", "Whether this is a daily development version", False)) vars.Add("channel", "Update channel for this build", buildVars.addon_info["addon_updateChannel"]) @@ -87,7 +100,9 @@ if env["dev"]: import datetime buildDate = datetime.datetime.now() year, month, day = str(buildDate.year), str(buildDate.month), str(buildDate.day) - env["addon_version"] = "".join([year, month.zfill(2), day.zfill(2), "-dev"]) + versionTimestamp = "".join([year, month.zfill(2), day.zfill(2)]) + env["addon_version"] = f"{versionTimestamp}-dev" + env["versionNumber"] = f"{versionTimestamp}.0.0" env["channel"] = "dev" elif env["version"] is not None: env["addon_version"] = env["version"] @@ -155,9 +170,85 @@ def createAddonBundleFromPath(path, dest): absPath = os.path.join(dir, filename) if pathInBundle not in buildVars.excludedFiles: z.write(absPath, pathInBundle) + createAddonStoreJson(dest) return dest +def createAddonStoreJson(bundle): + """Creates add-on store JSON file from an add-on package and manifest data.""" + import json + import hashlib + # Set different json file names and version number properties based on version number parsing results. + if env["versionNumber"] == "0.0.0": + env["versionNumber"] = buildVars.addon_info["addon_version"] + versionNumberParsed = env["versionNumber"].split(".") + if all([part.isnumeric() for part in versionNumberParsed]): + if len(versionNumberParsed) == 1: + versionNumberParsed += ["0", "0"] + elif len(versionNumberParsed) == 2: + versionNumberParsed.append("0") + else: + versionNumberParsed = [] + if len(versionNumberParsed): + major, minor, patch = [int(part) for part in versionNumberParsed] + jsonFilename = f'{buildVars.addon_info["addon_name"]}-{major}.{minor}.{patch}.json' + else: + jsonFilename = f'{buildVars.addon_info["addon_name"]}-{buildVars.addon_info["addon_version"]}.json' + major, minor, patch = 0, 0, 0 + print('Generating % s' % jsonFilename) + sha256 = hashlib.sha256() + with open(bundle, "rb") as f: + for byte_block in iter(lambda: f.read(65536), b""): + sha256.update(byte_block) + hashValue = sha256.hexdigest() + try: + minimumNVDAVersion = buildVars.addon_info["addon_minimumNVDAVersion"].split(".") + except AttributeError: + minimumNVDAVersion = [0, 0, 0] + minMajor, minMinor = minimumNVDAVersion[:2] + minPatch = minimumNVDAVersion[-1] if len(minimumNVDAVersion) == 3 else "0" + try: + lastTestedNVDAVersion = buildVars.addon_info["addon_lastTestedNVDAVersion"].split(".") + except AttributeError: + lastTestedNVDAVersion = [0, 0, 0] + lastTestedMajor, lastTestedMinor = lastTestedNVDAVersion[:2] + lastTestedPatch = lastTestedNVDAVersion[-1] if len(lastTestedNVDAVersion) == 3 else "0" + channel = buildVars.addon_info["addon_updateChannel"] + if channel is None: + channel = "stable" + addonStoreEntry = { + "addonId": buildVars.addon_info["addon_name"], + "displayName": buildVars.addon_info["addon_summary"], + "URL": "", + "description": buildVars.addon_info["addon_description"], + "sha256": hashValue, + "homepage": buildVars.addon_info["addon_url"], + "addonVersionName": buildVars.addon_info["addon_version"], + "addonVersionNumber": { + "major": major, + "minor": minor, + "patch": patch + }, + "minNVDAVersion": { + "major": int(minMajor), + "minor": int(minMinor), + "patch": int(minPatch) + }, + "lastTestedVersion": { + "major": int(lastTestedMajor), + "minor": int(lastTestedMinor), + "patch": int(lastTestedPatch) + }, + "channel": channel, + "publisher": "", + "sourceURL": buildVars.addon_info["addon_sourceURL"], + "license": buildVars.addon_info["addon_license"], + "licenseURL": buildVars.addon_info["addon_licenseURL"], + } + with open(jsonFilename, "w") as addonStoreJson: + json.dump(addonStoreEntry, addonStoreJson, indent="\t") + + def generateManifest(source, dest): addon_info = buildVars.addon_info with codecs.open(source, "r", "utf-8") as f: