Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 32 additions & 12 deletions clodex.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,45 @@
$ErrorActionPreference = 'Stop'
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path

function Test-ClodexPython {
param([string]$Exe, [string[]]$Prefix = @())
# Probe tolerantly: the Microsoft Store python3.exe stub writes to stderr and
# exits non-zero, which 'Stop' would otherwise turn into a terminating error.
$previous = $ErrorActionPreference
$ErrorActionPreference = 'Continue'
try {
& $Exe @Prefix -c "import sys; raise SystemExit(0 if sys.version_info >= (3, 12) else 1)" 2>&1 | Out-Null
return ($LASTEXITCODE -eq 0)
}
catch {
return $false
}
finally {
$ErrorActionPreference = $previous
}
}

function Find-ClodexPython {
foreach ($candidate in @('python3', 'python')) {
$cmd = Get-Command $candidate -ErrorAction SilentlyContinue
if ($cmd) {
& $cmd.Source -c "import sys; raise SystemExit(0 if sys.version_info >= (3, 12) else 1)" 2>$null
if ($LASTEXITCODE -eq 0) {
return $cmd.Source
if ($cmd -and (Test-ClodexPython $cmd.Source)) {
return @{ Exe = $cmd.Source; Prefix = @() }
}
}
$py = Get-Command 'py' -ErrorAction SilentlyContinue
if ($py) {
foreach ($version in @('-3', '-3.14', '-3.13', '-3.12')) {
if (Test-ClodexPython $py.Source @($version)) {
return @{ Exe = $py.Source; Prefix = @($version) }
}
}
}
throw 'Clodex requires Python >= 3.12'
}

$python = Find-ClodexPython
Push-Location $scriptDir
try {
& $python -m clodex @args
exit $LASTEXITCODE
}
finally {
Pop-Location
}
# Stay in the caller's directory so Clodex operates on their repo, not this checkout.
$existing = $env:PYTHONPATH
$env:PYTHONPATH = if ($existing) { "$scriptDir;$existing" } else { $scriptDir }
& $python.Exe @($python.Prefix) -m clodex @args
exit $LASTEXITCODE
14 changes: 14 additions & 0 deletions clodex/_vendor/VENDORED.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Vendored dependencies

Clodex runs from whatever system Python the npm launcher finds, so pure-Python
dependencies are vendored here and used only when they are not importable.

## PyYAML 6.0.3 (`yaml/`)

- Source: https://files.pythonhosted.org/packages/05/8e/961c0007c59b8dd7729d542c61a4d537767a59645b82a0b521206e1e25c2/pyyaml-6.0.3.tar.gz
- sdist sha256: `d76623373421df22fb4cf8817020cbb7ef15c725b9d5e45f17e189bfc384190f`
- License: MIT (`yaml/LICENSE`)
- Copied unmodified from `lib/yaml/*.py`, except `cyaml.py` is omitted (the optional
libyaml bindings); `yaml/__init__.py` already falls back to the pure-Python
loaders when `.cyaml` cannot be imported.
- To update: download the new sdist, verify its sha256, replace the files, update this note.
1 change: 1 addition & 0 deletions clodex/_vendor/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Vendored pure-Python dependencies (see VENDORED.md)."""
20 changes: 20 additions & 0 deletions clodex/_vendor/yaml/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2017-2021 Ingy döt Net
Copyright (c) 2006-2016 Kirill Simonov

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading
Loading