Skip to content

Commit

Permalink
Merge pull request #16803 from nvaccess/ruffFormat
Browse files Browse the repository at this point in the history
run ruff format to fix whitespace changes

Follow up to #16767
Closes #12261

Summary of the issue:
When migrating to ruff in #16751, we failed to lint scons files, and also run ruff format on the repository.
Ruff format fixes whitespaces issues in python files.

Description of user facing changes
None

Description of development approach
Perform lint fixes on scons files and run ruff format.
  • Loading branch information
seanbudd authored Jul 4, 2024
2 parents e7ecce0 + b48dbdc commit 7734274
Show file tree
Hide file tree
Showing 528 changed files with 40,888 additions and 30,803 deletions.
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ e6a639bfe237ff7f98c4cbec2094a34ac4b879db
# Lint the repository with Ruff
d3ce6b8879b14464058d5eaf3f914f803e8f22ac
8bdfbc2e8da78945e20c3b203b39b9a81227d596
d7b29daceb98e717aeb4828eb9e71e34e9e33b5e
55fb00ad342b0cd4b0a8913cfc75e0ea61b28100
b31c94cf5856832f2fff2c6270e1d5e44c9cd6af
18 changes: 9 additions & 9 deletions appveyor/crowdinSync.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@


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 = {}
headers["Authorization"] = f"Bearer {AUTH_TOKEN}"
r = method(
f"https://api.crowdin.com/api/v2/{path}",
headers=headers,
**kwargs
**kwargs,
)
# Convert errors to exceptions, but print the response before raising.
try:
Expand All @@ -54,27 +54,27 @@ def uploadSourceFile(crowdinFileID: int, localFilePath: str) -> None:
"storages",
method=requests.post,
headers={"Crowdin-API-FileName": fn},
data=f
data=f,
)
storageID = r.json()["data"]["id"]
print(f"Updating file {crowdinFileID} on Crowdin with storage ID {storageID}")
r = projectRequest(
f"files/{crowdinFileID}",
method=requests.put,
json={"storageId": storageID}
json={"storageId": storageID},
)
revisionId = r.json()["data"]["revisionId"]
print(f"Updated to revision {revisionId}")


def main():
parser = argparse.ArgumentParser(
description="Syncs translations with Crowdin."
description="Syncs translations with Crowdin.",
)
commands = parser.add_subparsers(dest="command", required=True)
uploadCommand = commands.add_parser(
"uploadSourceFile",
help="Upload a source file to Crowdin."
help="Upload a source file to Crowdin.",
)
uploadCommand.add_argument("crowdinFileID", type=int, help="The Crowdin file ID.")
uploadCommand.add_argument("localFilePath", help="The path to the local file.")
Expand Down
51 changes: 29 additions & 22 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 @@ -27,56 +27,64 @@
"ISimpleDOM.dll",
"nvdaHelperRemote.dll",
]
DLL_FILES = [f
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))]
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,
proc = subprocess.Popen(
command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True)
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 @@ -85,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')},
allow_redirects=False
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"])
Loading

0 comments on commit 7734274

Please sign in to comment.