Skip to content

Commit

Permalink
run ruff format
Browse files Browse the repository at this point in the history
  • Loading branch information
seanbudd committed Jul 4, 2024
1 parent 55fb00a commit b31c94c
Show file tree
Hide file tree
Showing 523 changed files with 38,105 additions and 28,956 deletions.
8 changes: 4 additions & 4 deletions appveyor/crowdinSync.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@


def request(
path: str,
method=requests.get,
headers: dict[str, str] | None = None,
**kwargs,
path: str,
method=requests.get,
headers: dict[str, str] | None = None,
**kwargs,
) -> requests.Response:
if headers is None:
headers = {}
Expand Down
55 changes: 29 additions & 26 deletions appveyor/mozillaSyms.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
NVDA_LIB = os.path.join(NVDA_SOURCE, "lib")
NVDA_LIB64 = os.path.join(NVDA_SOURCE, "lib64")
ZIP_FILE = os.path.join(SCRIPT_DIR, "mozillaSyms.zip")
URL = 'https://symbols.mozilla.org/upload/'
URL = "https://symbols.mozilla.org/upload/"

# The dlls for which symbols are to be uploaded to Mozilla.
# This only needs to include dlls injected into Mozilla products.
Expand All @@ -28,59 +28,63 @@
"nvdaHelperRemote.dll",
]
DLL_FILES = [
f
for dll in DLL_NAMES
# We need both the 32 bit and 64 bit symbols.
for f in (os.path.join(NVDA_LIB, dll), os.path.join(NVDA_LIB64, dll))
f
for dll in DLL_NAMES
# We need both the 32 bit and 64 bit symbols.
for f in (os.path.join(NVDA_LIB, dll), os.path.join(NVDA_LIB64, dll))
]


class ProcError(Exception):
def __init__(self, returncode, stderr):
self.returncode = returncode
self.stderr = stderr


def check_output(command):
proc = subprocess.Popen(
command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
)
command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
)
stdout, stderr = proc.communicate()
if proc.returncode != 0:
raise ProcError(proc.returncode, stderr)
return stdout


def processFile(path):
print("dump_syms %s"%path)
print("dump_syms %s" % path)
try:
stdout = check_output([DUMP_SYMS, path])
except ProcError as e:
print('Error: running "%s %s": %s' % (DUMP_SYMS, path, e.stderr))
return None, None, None
bits = stdout.splitlines()[0].split(' ', 4)
bits = stdout.splitlines()[0].split(" ", 4)
if len(bits) != 5:
return None, None, None
_, platform, cpu_arch, debug_id, debug_file = bits
# debug_file will have a .pdb extension; e.g. nvdaHelperRemote.dll.pdb.
# The output file format should have a .sym extension instead.
# Strip .pdb and add .sym.
sym_file = debug_file[:-4] + '.sym'
sym_file = debug_file[:-4] + ".sym"
filename = os.path.join(debug_file, debug_id, sym_file)
debug_filename = os.path.join(debug_file, debug_id, debug_file)
return filename, stdout, debug_filename


def generate():
count = 0
with zipfile.ZipFile(ZIP_FILE, 'w', zipfile.ZIP_DEFLATED) as zf:
with zipfile.ZipFile(ZIP_FILE, "w", zipfile.ZIP_DEFLATED) as zf:
for f in DLL_FILES:
filename, contents, debug_filename = processFile(f)
if not (filename and contents):
print('Error dumping symbols')
print("Error dumping symbols")
raise RuntimeError
zf.writestr(filename, contents)
count += 1
print('Added %d files to %s' % (count, ZIP_FILE))
print("Added %d files to %s" % (count, ZIP_FILE))


def upload():
Expand All @@ -89,37 +93,36 @@ def upload():
if i > 0:
print("Sleeping for 15 seconds before next attempt.")
import time

time.sleep(15)
try:
r = requests.post(
URL,
files={'symbols.zip': open(ZIP_FILE, 'rb')},
headers={'Auth-Token': os.getenv('mozillaSymsAuthToken')},
files={"symbols.zip": open(ZIP_FILE, "rb")},
headers={"Auth-Token": os.getenv("mozillaSymsAuthToken")},
allow_redirects=False,
)
break # success
except Exception as e:
print(f"Attempt {i + 1} failed: {e!r}")
errors.append(repr(e))
else: # no break in for loop
allErrors = "\n".join(
f"Attempt {index + 1} error: \n{e}"
for index, e in enumerate(errors)
)
allErrors = "\n".join(f"Attempt {index + 1} error: \n{e}" for index, e in enumerate(errors))
raise RuntimeError(allErrors)

if 200 <= r.status_code < 300:
print('Uploaded successfully!')
print("Uploaded successfully!")
elif r.status_code < 400:
print('Error: bad auth token? (%d)' % r.status_code)
print("Error: bad auth token? (%d)" % r.status_code)
raise RuntimeError
else:
print('Error: %d' % r.status_code)
print("Error: %d" % r.status_code)
print(r.text)
raise RuntimeError
return 0

if __name__ == '__main__':

if __name__ == "__main__":
try:
generate()
upload()
Expand Down
140 changes: 75 additions & 65 deletions appx/sconscript
Original file line number Diff line number Diff line change
@@ -1,108 +1,118 @@
###
#This file is a part of the NVDA project.
#URL: https://www.nvaccess.org/
#Copyright 2018-2019 NV Access Limited
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License version 2.0, as published by
#the Free Software Foundation.
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#This license can be found at:
#http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# This file is a part of the NVDA project.
# URL: https://www.nvaccess.org/
# Copyright 2018-2019 NV Access Limited
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2.0, as published by
# the Free Software Foundation.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# This license can be found at:
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
###

import subprocess
import versionInfo
import os

Import([
'env',
'outFilePrefix',
'isStoreSubmission',
])
Import(
[
"env",
"outFilePrefix",
"isStoreSubmission",
]
)


def getCertPublisher(env):
"""
If no signing certificate is provided, then the given publisher is used as is.
If a signing certificate is given, then the publisher is extracted from the certificate.
"""
certFilePath = env.get('certFile')
certFilePath = env.get("certFile")
if not certFilePath:
return env['publisher']
certPassword=env.get('certPassword','')
return env["publisher"]
certPassword = env.get("certPassword", "")
if not os.path.isabs(certFilePath):
# If path is not absolute it is assumed that it is being given relative to the top dir of the repo
repoTopDir = Dir('#').abspath
repoTopDir = Dir("#").abspath
certFilePath = os.path.abspath(os.path.normpath(os.path.join(repoTopDir, certFilePath)))
cmd=['certutil', '-dump', '-p', certPassword, certFilePath]
lines=subprocess.run(cmd,check=True,capture_output=True,text=True).stdout.splitlines()
linePrefix='Subject: '
cmd = ["certutil", "-dump", "-p", certPassword, certFilePath]
lines = subprocess.run(cmd, check=True, capture_output=True, text=True).stdout.splitlines()
linePrefix = "Subject: "
for line in lines:
if line.startswith(linePrefix):
subject=line[len(linePrefix):].rstrip()
subject = line[len(linePrefix) :].rstrip()
return subject

packageName="NVAccessLimited.NVDANonVisualDesktopAccess"
packageVersion="%s.%s.%s.%s"%(versionInfo.version_year,versionInfo.version_major,env['version_build'],0)

packageName = "NVAccessLimited.NVDANonVisualDesktopAccess"
packageVersion = "%s.%s.%s.%s" % (
versionInfo.version_year,
versionInfo.version_major,
env["version_build"],
0,
)
if isStoreSubmission:
packageFileName=outFilePrefix+"_storeSubmission.appx"
packageFileName = outFilePrefix + "_storeSubmission.appx"
# NV Access Limited's Windows Store publisher ID
# It is okay to be here as the only way to submit, validate and sign the package is via the NV Access store account.
packagePublisher="CN=83B1DA31-9B66-442C-88AB-77B4B815E1DE"
packagePublisherDisplayName="NV Access Limited"
productName="NVDA Screen Reader (Windows Store Edition)"
else: # not for submission, just side-loadable
packageFileName=outFilePrefix+"_sideLoadable.appx"
packagePublisher=getCertPublisher(env)
packagePublisherDisplayName=env['publisher']
productName="NVDA Screen Reader (Windows Desktop Bridge Edition)"
packagePublisher = "CN=83B1DA31-9B66-442C-88AB-77B4B815E1DE"
packagePublisherDisplayName = "NV Access Limited"
productName = "NVDA Screen Reader (Windows Store Edition)"
else: # not for submission, just side-loadable
packageFileName = outFilePrefix + "_sideLoadable.appx"
packagePublisher = getCertPublisher(env)
packagePublisherDisplayName = env["publisher"]
productName = "NVDA Screen Reader (Windows Desktop Bridge Edition)"

signExec = env['signExec'] if (bool(env['certFile']) ^ bool(env['apiSigningToken'])) else None
signExec = env["signExec"] if (bool(env["certFile"]) ^ bool(env["apiSigningToken"])) else None


# Files from NVDA's distribution that cannot be included in the appx due to policy or security restrictions
excludedDistFiles = [
'nvda_slave.exe',
'nvda_noUIAccess.exe',
'lib/IAccessible2Proxy.dll',
'lib/ISimpleDOM.dll',
'lib/NVDAHelperRemote.dll',
'lib64/',
'libArm64/',
'uninstall.exe',
"nvda_slave.exe",
"nvda_noUIAccess.exe",
"lib/IAccessible2Proxy.dll",
"lib/ISimpleDOM.dll",
"lib/NVDAHelperRemote.dll",
"lib64/",
"libArm64/",
"uninstall.exe",
]

# Create an appx manifest with version and publisher etc all filled in
manifest=env.Substfile(
# Create an appx manifest with version and publisher etc all filled in
manifest = env.Substfile(
"AppxManifest.xml",
'manifest.xml.subst',
"manifest.xml.subst",
SUBST_DICT={
'%packageName%':packageName,
'%packageVersion%':packageVersion,
'%packagePublisher%':packagePublisher,
'%publisher%':packagePublisherDisplayName,
'%productName%':productName,
'%description%':versionInfo.description,
"%packageName%": packageName,
"%packageVersion%": packageVersion,
"%packagePublisher%": packagePublisher,
"%publisher%": packagePublisherDisplayName,
"%productName%": productName,
"%description%": versionInfo.description,
},
)
# Make a copy of the dist dir produced by py2exe
# Make a copy of the dist dir produced by py2exe
# And also place some extra appx specific images in there
appxContent=env.Command(
target='content',
source=[Dir("#dist"),Dir('#appx/appx_images'),manifest],
appxContent = env.Command(
target="content",
source=[Dir("#dist"), Dir("#appx/appx_images"), manifest],
action=[
Delete("$TARGET"),
Copy("$TARGET","${SOURCES[0]}"),
Copy("${TARGET}\\appx_images","${SOURCES[1]}"),
Copy("${TARGET}\\AppxManifest.xml","${SOURCES[2]}"),
]+[Delete("${TARGET}/%s"%excludeFile) for excludeFile in excludedDistFiles],
Copy("$TARGET", "${SOURCES[0]}"),
Copy("${TARGET}\\appx_images", "${SOURCES[1]}"),
Copy("${TARGET}\\AppxManifest.xml", "${SOURCES[2]}"),
]
+ [Delete("${TARGET}/%s" % excludeFile) for excludeFile in excludedDistFiles],
)
# Ensure that it is always copied as we can't tell if dist changed
# Ensure that it is always copied as we can't tell if dist changed
env.AlwaysBuild(appxContent)
# Package the appx
appx=env.Command(packageFileName,appxContent,"makeappx pack /p $TARGET /d $SOURCE")
appx = env.Command(packageFileName, appxContent, "makeappx pack /p $TARGET /d $SOURCE")
if signExec and not isStoreSubmission:
env.AddPostAction(appx,signExec)
env.AddPostAction(appx, signExec)

Return(['appx'])
Return(["appx"])
14 changes: 6 additions & 8 deletions cldrDict_sconscript
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,22 @@


import typing

if typing.TYPE_CHECKING:
import SCons
from SCons import(
from SCons import (
Dir,
Import,
)

sourceDir: "SCons.Node.FS.Dir"
env: "SCons.Environment.Base"
Import(
'env',
'sourceDir',
"env",
"sourceDir",
)

targetCldrDir = sourceDir.Dir('locale')
targetCldrDir = sourceDir.Dir("locale")
cldrDataSource = Dir("include/nvda-cldr/locale")

env.RecursiveInstall(
targetCldrDir,
cldrDataSource.abspath
)
env.RecursiveInstall(targetCldrDir, cldrDataSource.abspath)
12 changes: 6 additions & 6 deletions extras/controllerClient/examples/example_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ def onMarkReached(name: str) -> int:


ssml = (
'<speak>'
'This is one sentence. '
"<speak>"
"This is one sentence. "
'<mark name="test" />'
'<prosody pitch="200%">This sentence is pronounced with higher pitch.</prosody>'
'<mark name="test2" />'
'This is a third sentence. '
"This is a third sentence. "
'<mark name="test3" />'
'This is a fourth sentence. We will stay silent for a second after this one.'
"This is a fourth sentence. We will stay silent for a second after this one."
'<break time="1000ms" />'
'<mark name="test4" />'
'This is a fifth sentence. '
"This is a fifth sentence. "
'<mark name="test5" />'
'</speak>'
"</speak>"
)
clientLib.nvdaController_setOnSsmlMarkReachedCallback(onMarkReached)
clientLib.nvdaController_speakSsml(ssml, -1, 0, False)
Expand Down
Loading

0 comments on commit b31c94c

Please sign in to comment.