Skip to content

Commit b51c228

Browse files
committed
Use UV
1 parent c747ccb commit b51c228

21 files changed

+455
-264
lines changed

.github/workflows/testCode.yaml

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,38 @@ on:
88

99
jobs:
1010
testCode:
11-
1211
runs-on: windows-latest
1312
strategy:
1413
matrix:
1514
python-version: [3.13]
1615
steps:
16+
- name: Install the latest version of uv
17+
uses: astral-sh/setup-uv@v6
1718
- name: Checkout code
18-
uses: actions/checkout@v3
19+
uses: actions/checkout@v5
1920
- name: Set up Python ${{ matrix.python-version }}
20-
uses: actions/setup-python@v3
21+
uses: actions/setup-python@v5
2122
with:
2223
python-version: ${{ matrix.python-version }}
23-
architecture: x86
24-
- name: Install dependencies
25-
run: |
26-
python -m pip install --upgrade pip
27-
python -m pip install tox
28-
- name: Test with tox
24+
architecture: x64
25+
- name: Run unit tests
26+
shell: cmd
2927
# Run automated/unit tests
30-
run: tox
31-
- name: Lint with flake8
28+
run: .\rununittests.bat
29+
- name: Lint
30+
shell: cmd
3231
# Check code with the linter
33-
run: .\runlint.ps1
32+
run: .\runlint.bat
3433
- name: Validate metadata
34+
shell: cmd
3535
# E2E: test to check the script can be run, no need to actually test the file.
3636
# The internal checks are covered with unit tests.
37-
run: .\runvalidate.ps1 --dry-run _test/testData/addons/fake/13.0.json _tests\testData\nvdaAPIVersions.json
37+
run: .\runvalidate.bat --dry-run _test/testData/addons/fake/13.0.json _tests\testData\nvdaAPIVersions.json
3838
- name: Get sha256
39+
shell: cmd
3940
# E2E: test to check the script can be run
40-
run: .\runsha.ps1 _tests\testData\fake.nvda-addon
41+
run: .\runsha.bat _tests\testData\fake.nvda-addon
4142
- name: Generate json file
43+
shell: cmd
4244
# E2E: test to check the script can be run
43-
run: .\runcreatejson.ps1 -f _tests\testData\fake.nvda-addon --dir _tests\testOutput\test_runcreatejson --channel=stable --publisher=fakepublisher --sourceUrl=https://github.com/fake/ --url=https://github.com/fake.nvda-addon --licName="GPL v2" --licUrl="https://www.gnu.org/licenses/gpl-2.0.html"
45+
run: .\runcreatejson.bat -f _tests\testData\fake.nvda-addon --dir _tests\testOutput\test_runcreatejson --channel=stable --publisher=fakepublisher --sourceUrl=https://github.com/fake/ --url=https://github.com/fake.nvda-addon --licName="GPL v2" --licUrl="https://www.gnu.org/licenses/gpl-2.0.html"

.pre-commit-config.yml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# https://pre-commit.ci/
2+
# Configuration for Continuous Integration service
3+
ci:
4+
# Can't run Windows scons scripts on Linux.
5+
# Pyright does not seem to work in pre-commit CI
6+
skip: [unitTest, pyright]
7+
autoupdate_schedule: monthly
8+
autoupdate_commit_msg: "Pre-commit auto-update"
9+
autofix_commit_msg: "Pre-commit auto-fix"
10+
submodules: true
11+
12+
default_language_version:
13+
python: python3.11
14+
15+
repos:
16+
- repo: https://github.com/pre-commit-ci/pre-commit-ci-config
17+
rev: v1.6.1
18+
hooks:
19+
- id: check-pre-commit-ci-config
20+
21+
- repo: meta
22+
hooks:
23+
# ensures that exclude directives apply to any file in the repository.
24+
- id: check-useless-excludes
25+
# ensures that the configured hooks apply to at least one file in the repository.
26+
- id: check-hooks-apply
27+
28+
- repo: https://github.com/pre-commit/pre-commit-hooks
29+
rev: v5.0.0
30+
hooks:
31+
# Prevents commits to certain branches
32+
- id: no-commit-to-branch
33+
args: ["--branch", "main"]
34+
# Checks that large files have not been added. Default cut-off for "large" files is 500kb.
35+
- id: check-added-large-files
36+
# Checks python syntax
37+
- id: check-ast
38+
# Checks for filenames that will conflict on case insensitive filesystems (the majority of Windows filesystems, most of the time)
39+
- id: check-case-conflict
40+
# Checks for artifacts from resolving merge conflicts.
41+
- id: check-merge-conflict
42+
# Checks Python files for debug statements, such as python's breakpoint function, or those inserted by some IDEs.
43+
- id: debug-statements
44+
# Removes trailing whitespace.
45+
- id: trailing-whitespace
46+
types_or: [python, batch, markdown, toml, yaml, powershell]
47+
# Ensures all files end in 1 (and only 1) newline.
48+
- id: end-of-file-fixer
49+
types_or: [python, batch, markdown, toml, yaml, powershell]
50+
# Removes the UTF-8 BOM from files that have it.
51+
# See https://github.com/nvaccess/nvda/blob/master/projectDocs/dev/codingStandards.md#encoding
52+
- id: fix-byte-order-marker
53+
types_or: [python, batch, markdown, toml, yaml, powershell]
54+
# Validates TOML files.
55+
- id: check-toml
56+
# Validates YAML files.
57+
- id: check-yaml
58+
# Ensures that links to lines in files under version control point to a particular commit.
59+
- id: check-vcs-permalinks
60+
# Avoids using reserved Windows filenames.
61+
- id: check-illegal-windows-names
62+
# Checks that tests are named test_*.py.
63+
- id: name-tests-test
64+
args: ["--unittest"]
65+
66+
- repo: https://github.com/asottile/add-trailing-comma
67+
rev: v3.2.0
68+
hooks:
69+
# Ruff preserves indent/new-line formatting of function arguments, list items, and similar iterables,
70+
# if a trailing comma is added.
71+
# This adds a trailing comma to args/iterable items in case it was missed.
72+
- id: add-trailing-comma
73+
74+
- repo: https://github.com/astral-sh/ruff-pre-commit
75+
# Matches Ruff version in pyproject.
76+
rev: v0.12.7
77+
hooks:
78+
- id: ruff
79+
name: lint with ruff
80+
args: [ --fix ]
81+
- id: ruff-format
82+
name: format with ruff
83+
84+
- repo: https://github.com/RobertCraigie/pyright-python
85+
rev: v1.1.403
86+
hooks:
87+
- id: pyright
88+
name: Check types with pyright
89+
90+
- repo: https://github.com/astral-sh/uv-pre-commit
91+
rev: 0.8.4
92+
hooks:
93+
- id: uv-lock
94+
name: Verify uv lock file
95+
# Override python interpreter from .python-versions as that is too strict for pre-commit.ci
96+
args: ["-p3.13"]
97+
98+
- repo: local
99+
hooks:
100+
- id: unitTest
101+
name: unit tests
102+
entry: ./rununittests.bat
103+
language: script
104+
pass_filenames: false
105+
types_or: [python, batch]
106+

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cpython-3.13-windows-x86_64-none

ensureuv.ps1

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
[CmdletBinding()]
2+
param(
3+
[Parameter(ValueFromRemainingArguments = $true)]
4+
[string[]]$UvArgs
5+
)
6+
7+
$ErrorActionPreference = 'Stop'
8+
Set-StrictMode -Version Latest
9+
[Version]$UvVersion = '0.8.15'
10+
11+
function Invoke-Uv {
12+
& uv @UvArgs
13+
exit $LASTEXITCODE
14+
}
15+
16+
function Install-Uv {
17+
param(
18+
[Switch]$IsUpdate
19+
)
20+
21+
$installAction = if ($IsUpdate) { 'Update' } else { 'Install' }
22+
$hasWinGet = [bool](Get-Command winget -ErrorAction SilentlyContinue)
23+
if ($IsUpdate) {
24+
Write-Host 'Uv is out of date.'
25+
}
26+
else {
27+
Write-Host 'Uv is not installed.'
28+
}
29+
Write-Host ''
30+
Write-Host "Choose how to $($installAction.ToLower()) uv:"
31+
32+
while ($true) {
33+
if ($hasWinGet) {
34+
Write-Host "[1] $installAction using WinGet (recommended)"
35+
}
36+
else {
37+
Write-Host 'WinGet is NOT available.'
38+
}
39+
Write-Host "[2] $installAction using the official uv install script"
40+
Write-Host '[0] Exit'
41+
42+
$choice = Read-Host 'Enter your choice'
43+
44+
switch ($choice) {
45+
'0' { exit }
46+
'1' {
47+
if (-not $hasWinGet) {
48+
Write-Warning 'WinGet is not available. Please choose another option.'
49+
continue
50+
}
51+
$WinGetArgs = @('--accept-source-agreements', '--disable-interactivity' , '-e', 'astral-sh.uv')
52+
try {
53+
if ($IsUpdate) {
54+
Write-Host 'Updating uv using WinGet...'
55+
& winget update @WinGetArgs
56+
}
57+
else {
58+
Write-Host 'Installing uv using WinGet...'
59+
& winget install $WinGetArgs
60+
}
61+
if ($LASTEXITCODE -ne 0) {
62+
throw "winget command failed with exit code $LASTEXITCODE"
63+
}
64+
return
65+
}
66+
catch {
67+
Write-Error "Failed to $($installAction.ToLower()) uv using WinGet: $_"
68+
}
69+
}
70+
'2' {
71+
try {
72+
Write-Host 'Installing uv using the official script...'
73+
Invoke-RestMethod https://astral.sh/uv/install.ps1 | Invoke-Expression
74+
$env:PATH = "$(Join-Path $env:USERPROFILE '.local bin');$env:PATH"
75+
return
76+
}
77+
catch {
78+
Write-Error "Failed to install uv via the official script: $_"
79+
}
80+
}
81+
default {
82+
Write-Warning "Invalid choice: '$choice'. Please try again."
83+
}
84+
}
85+
}
86+
}
87+
88+
# Main Script Logic
89+
90+
$hasUv = [bool](Get-Command uv -ErrorAction SilentlyContinue)
91+
92+
if ($hasUv) {
93+
try {
94+
$json = uv self version --output-format json | ConvertFrom-Json
95+
[Version]$installedVersion = $json.Version
96+
}
97+
catch {
98+
Write-Warning 'Could not retrieve uv version.'
99+
[Version]$installedVersion = '0.0.0'
100+
}
101+
102+
if ($installedVersion -ge $UvVersion) {
103+
Invoke-Uv
104+
}
105+
else {
106+
Write-Host "uv version $installedVersion is installed, but version $UvVersion or higher is required. Trying to update..."
107+
uv self update
108+
if ($LASTEXITCODE -ne 0) {
109+
Write-Warning 'Prompting for manual install/update.'
110+
Install-Uv -IsUpdate
111+
}
112+
113+
}
114+
}
115+
else {
116+
Install-Uv
117+
}
118+
Invoke-Uv

0 commit comments

Comments
 (0)