|
| 1 | +# Define the path to the .pypirc file |
| 2 | +$pypircPath = Join-Path $HOME ".pypirc" |
| 3 | + |
| 4 | +# Initialize credential variables |
| 5 | +$pypiUsername = $null |
| 6 | +$pypiPassword = $null |
| 7 | + |
| 8 | +# Check if the .pypirc file exists |
| 9 | +if (-not (Test-Path -Path $pypircPath -PathType Leaf)) { |
| 10 | + Write-Error "Error: ~/.pypirc file not found at '$pypircPath'." |
| 11 | + exit 1 |
| 12 | +} |
| 13 | + |
| 14 | +Write-Host "Reading credentials from $pypircPath..." |
| 15 | + |
| 16 | +# Read the file content and parse for [pypi] credentials |
| 17 | +try { |
| 18 | + $pypircContent = Get-Content -Path $pypircPath -Raw |
| 19 | + # Simple parsing assuming [pypi] section and username/password lines |
| 20 | + if ($pypircContent -match '\[pypi\]') { |
| 21 | + if ($pypircContent -match '(?m)^\s*username\s*=\s*(.+)$') { |
| 22 | + $pypiUsername = $Matches[1].Trim() |
| 23 | + } |
| 24 | + if ($pypircContent -match '(?m)^\s*password\s*=\s*(.+)$') { |
| 25 | + $pypiPassword = $Matches[1].Trim() |
| 26 | + } |
| 27 | + } |
| 28 | +} catch { |
| 29 | + Write-Error "Error reading or parsing '$pypircPath': $($_.Exception.Message)" |
| 30 | + exit 1 |
| 31 | +} |
| 32 | + |
| 33 | +# Validate that credentials were found |
| 34 | +if (-not $pypiUsername -or -not $pypiPassword) { |
| 35 | + Write-Error "Error: Could not find username and/or password under the [pypi] section in '$pypircPath'." |
| 36 | + exit 1 |
| 37 | +} |
| 38 | + |
| 39 | +Write-Host "Credentials found. Username: $pypiUsername" # Username is usually __token__ |
| 40 | + |
| 41 | +# Construct and execute the uv publish command |
| 42 | +Write-Host "Attempting to publish packages using credentials from ~/.pypirc..." |
| 43 | +try { |
| 44 | + # Use Invoke-Expression if needed, but direct call is often better |
| 45 | + # Ensure the password is treated as a single argument, even if it contains special characters |
| 46 | + uv publish --username $pypiUsername --password $pypiPassword |
| 47 | + Write-Host "Publish command executed." |
| 48 | +} catch { |
| 49 | + Write-Error "Error executing uv publish: $($_.Exception.Message)" |
| 50 | + exit 1 |
| 51 | +} |
0 commit comments