lamchau
2/14/2016 - 8:45 PM

pip-freeze.ps1

$pip_file = "requirements.txt"

try {
  pip freeze > $pip_file

  # PowerShell creates UTF16 LE with Windows line endings so we must convert
  # for pip to consume
  # http://stackoverflow.com/questions/8852682/convert-file-from-windows-to-unix-through-powershell-or-batch
  Get-ChildItem $pip_file | ForEach-Object {
    $contents = [IO.File]::ReadAllText($_) -replace "`r`n?", "`n"
    $utf8 = New-Object System.Text.UTF8Encoding $false
    [IO.File]::WriteAllText($_, $contents, $utf8)
  }

  Write-Output "Created '$pip_file'"
} catch {
  Remove-Item $pip_file
}