Skip to content

Commit

Permalink
Merge pull request #10 from grisov/dev
Browse files Browse the repository at this point in the history
Update for compatibility with NVDA 2024.1
  • Loading branch information
grisov authored Mar 9, 2024
2 parents 44ba07d + 543fc46 commit 353fe16
Show file tree
Hide file tree
Showing 12 changed files with 260 additions and 14 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/build_addon.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: build addon

on:
push:
tags: ["*"]
# To build on main/master branch, uncomment the following line:
# branches: [ main , master ]

pull_request:
branches: [ main, master ]

workflow_dispatch:

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- run: echo -e "pre-commit\nscons\nmarkdown">requirements.txt

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9
cache: 'pip'

- name: Install dependencies
run: |
python -m pip install --upgrade pip wheel
pip install -r requirements.txt
sudo apt-get update -y
sudo apt-get install -y gettext
- name: Code checks
run: export SKIP=no-commit-to-branch; pre-commit run --all

- name: building addon
run: scons

- uses: actions/upload-artifact@v3
with:
name: packaged_addon
path: ./*.nvda-addon

upload_release:
runs-on: ubuntu-latest
if: ${{ startsWith(github.ref, 'refs/tags/') }}
needs: ["build"]
steps:
- uses: actions/checkout@v3
- name: download releases files
uses: actions/download-artifact@v3
- name: Display structure of downloaded files
run: ls -R

- name: Release
uses: softprops/action-gh-release@v1
with:
files: packaged_addon/*.nvda-addon
fail_on_unmatched_files: true
prerelease: ${{ contains(github.ref, '-') }}
5 changes: 4 additions & 1 deletion .github/workflows/check-for-extended-ascii-and-utf-bom.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Check that we dont have extended ascii or utf boms in our files

on: [pull_request]
on:
pull_request:
branches:
- main

jobs:
extendedAsciiAndBom:
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Lint diff
on:
pull_request:
branches:
- master
- main

jobs:

Expand All @@ -17,15 +17,15 @@ jobs:
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Python 3.7
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.7
python-version: 3.9
- name: Install dependencies
run: pip install -r requirements.txt
run: pip install -U flake8
- name: Lint
run: |
git diff -U0 origin/master...HEAD -- addon/. > flake8.diff
git diff -U0 origin/main...HEAD -- addon/. > flake8.diff
type flake8.diff | flake8 --diff --output-file=flake8.txt --tee
- name: Comment on PR
uses: actions/github-script@v3
Expand Down
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11.6-win32
13 changes: 13 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
// 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",
"ms-python.flake8"
],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": []
}
20 changes: 20 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"editor.accessibilitySupport": "on",
"flake8.args": [
"--config=flake8.ini"
],
"flake8.importStrategy": "fromEnvironment",
"python.autoComplete.extraPaths": [
"../nvda/source",
"../nvda/miscDeps/python"
],
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"editor.insertSpaces": false,
"python.analysis.stubPath": "${workspaceFolder}/.vscode/typings",
"python.analysis.extraPaths": [
"../nvda/source",
"../nvda/miscDeps/python"
],
"python.defaultInterpreterPath": "${workspaceFolder}/../nvda/.venv/scripts/python.exe"
}
6 changes: 6 additions & 0 deletions .vscode/typings/__builtins__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def _(msg: str) -> str:
...


def pgettext(context: str, message: str) -> str:
...
29 changes: 29 additions & 0 deletions _template_addon_release.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"addonId": "checkGestures",
"addonVersionNumber": {
"major": 1,
"minor": 0,
"patch": 6
},
"addonVersionName": "1.0.6",
"displayName": "Check Input Gestures",
"publisher": "Oleksandr Gryshchenko <grisov.nvaccess@mailgw.com>",
"description": "Find and fix input gestures conflicts in NVDA and add-ons",
"homepage": "https://github.com/grisov/checkGestures",
"minNVDAVersion": {
"major": 2020,
"minor": 3,
"patch": 0
},
"lastTestedVersion": {
"major": 2024,
"minor": 1,
"patch": 0
},
"channel": "beta",
"URL": "https://github.com/nvaccess/addon-datastore/releases/download/v0.1.0/myAddon.nvda-addon",
"sha256": "69D84CA8899800A5575CE31798293CD4FEBAB1D734A07C2E51E56A28E0DF8C82",
"sourceURL": "https://github.com/grisov/checkGestures",
"license": "GPL v2",
"licenseURL": "https://github.com/grisov/checkGestures/blob/main/COPYING.txt"
}
14 changes: 10 additions & 4 deletions buildVars.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,27 @@ def _(arg):
# Translators: Long description to be shown for this add-on on add-on information from add-ons manager
"addon_description": _("""Find and fix input gestures conflicts in NVDA and add-ons."""),
# version
"addon_version": "1.0.5",
"addon_version": "1.0.6",
# Author(s)
"addon_author": "Oleksandr Gryshchenko <grisov.nvaccess@mailnull.com>",
"addon_author": "Oleksandr Gryshchenko <grisov.nvaccess@mailgw.com>",
# URL for the add-on documentation support
"addon_url": "https://github.com/grisov/checkGestures",
# URL for the add-on repository where the source code can be found
"addon_sourceURL": "https://github.com/grisov/checkGestures",
# Documentation file name
"addon_docFileName": "readme.html",
# Minimum NVDA version supported (e.g. "2018.3.0", minor version is optional)
"addon_minimumNVDAVersion": "2020.3.0",
# Last NVDA version supported/tested (e.g. "2018.4.0", ideally more recent than minimum version)
"addon_lastTestedNVDAVersion": "2023.1.0",
"addon_lastTestedNVDAVersion": "2024.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": "GNU General Public License v2",
# URL for the license document the ad-on is licensed under
"addon_licenseURL": "https://github.com/grisov/checkGestures/blob/main/COPYING.txt",
}

# Define the python files that are the sources of your add-on.
Expand Down Expand Up @@ -71,5 +77,5 @@ def _(arg):
# Most add-ons do not require additional Markdown extensions.
# If you need to add support for markup such as tables, fill out the below list.
# Extensions string must be of the form "markdown.extensions.extensionName"
# e.g. markdown.extensions.tables to add tables.
# e.g. "markdown.extensions.tables" to add tables.
markdownExtensions: List[str] = []
103 changes: 100 additions & 3 deletions sconstruct
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# NVDA add-on template SCONSTRUCT file
# Copyright (C) 2012-2022 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.

Expand Down Expand Up @@ -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"])

Expand All @@ -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}.0.0"
env["versionNumber"] = f"{versionTimestamp}.0.0"
env["channel"] = "dev"
elif env["version"] is not None:
env["addon_version"] = env["version"]
Expand Down Expand Up @@ -155,9 +170,86 @@ def createAddonBundleFromPath(path, dest):
absPath = os.path.join(dir, filename)
if pathInBundle not in buildVars.excludedFiles:
z.write(absPath, pathInBundle)
# Add-on store does not require submitting json files.
# 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'{major}.{minor}.{patch}.json'
else:
jsonFilename = f'{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:
Expand Down Expand Up @@ -208,7 +300,12 @@ for file in pythonFiles:
createAddonHelp("addon")
for mdFile in env.Glob(os.path.join('addon', 'doc', '*', '*.md')):
htmlFile = env.markdown(mdFile)
env.Depends(htmlFile, mdFile)
try: # It is possible that no moFile was set, because an add-on has no translations.
moFile
except NameError: # Runs if there is no moFile
env.Depends(htmlFile, mdFile)
else: # Runs if there is a moFile
env.Depends(htmlFile, [mdFile, moFile])
env.Depends(addon, htmlFile)

# Pot target
Expand Down
2 changes: 1 addition & 1 deletion style.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@charset "utf-8";
@charset "utf-8";
body {
font-family : Verdana, Arial, Helvetica, Sans-serif;
line-height: 1.2em;
Expand Down

0 comments on commit 353fe16

Please sign in to comment.