NenJa commited on
Commit
7c47f56
1 Parent(s): 29d1b36

Upload 4 files

Browse files
Files changed (4) hide show
  1. .python-version +1 -0
  2. install-pyenv-win.ps1 +156 -0
  3. pyproject.toml +57 -0
  4. requirements.dev.txt +3 -0
.python-version ADDED
@@ -0,0 +1 @@
 
 
1
+ 3.11.7
install-pyenv-win.ps1 ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <#
2
+ .SYNOPSIS
3
+ Installs pyenv-win
4
+
5
+ .DESCRIPTION
6
+ Installs pyenv-win to $HOME\.pyenv
7
+ If pyenv-win is already installed, try to update to the latest version.
8
+
9
+ .PARAMETER Uninstall
10
+ Uninstall pyenv-win. Note that this uninstalls any Python versions that were installed with pyenv-win.
11
+
12
+ .INPUTS
13
+ None.
14
+
15
+ .OUTPUTS
16
+ None.
17
+
18
+ .EXAMPLE
19
+ PS> install-pyenv-win.ps1
20
+
21
+ .LINK
22
+ Online version: https://pyenv-win.github.io/pyenv-win/
23
+ #>
24
+
25
+ param (
26
+ [Switch] $Uninstall = $False
27
+ )
28
+
29
+ $PyEnvDir = "${env:USERPROFILE}\.pyenv"
30
+ $PyEnvWinDir = "${PyEnvDir}\pyenv-win"
31
+ $BinPath = "${PyEnvWinDir}\bin"
32
+ $ShimsPath = "${PyEnvWinDir}\shims"
33
+
34
+ Function Remove-PyEnvVars() {
35
+ $PathParts = [System.Environment]::GetEnvironmentVariable('PATH', "User") -Split ";"
36
+ $NewPathParts = $PathParts.Where{ $_ -ne $BinPath }.Where{ $_ -ne $ShimsPath }
37
+ $NewPath = $NewPathParts -Join ";"
38
+ [System.Environment]::SetEnvironmentVariable('PATH', $NewPath, "User")
39
+
40
+ [System.Environment]::SetEnvironmentVariable('PYENV', $null, "User")
41
+ [System.Environment]::SetEnvironmentVariable('PYENV_ROOT', $null, "User")
42
+ [System.Environment]::SetEnvironmentVariable('PYENV_HOME', $null, "User")
43
+ }
44
+
45
+ Function Remove-PyEnv() {
46
+ Write-Host "Removing $PyEnvDir..."
47
+ If (Test-Path $PyEnvDir) {
48
+ Remove-Item -Path $PyEnvDir -Recurse
49
+ }
50
+ Write-Host "Removing environment variables..."
51
+ Remove-PyEnvVars
52
+ }
53
+
54
+ Function Get-CurrentVersion() {
55
+ $VersionFilePath = "$PyEnvDir\.version"
56
+ If (Test-Path $VersionFilePath) {
57
+ $CurrentVersion = Get-Content $VersionFilePath
58
+ }
59
+ Else {
60
+ $CurrentVersion = ""
61
+ }
62
+
63
+ Return $CurrentVersion
64
+ }
65
+
66
+ Function Get-LatestVersion() {
67
+ $LatestVersionFilePath = "$PyEnvDir\latest.version"
68
+ (New-Object System.Net.WebClient).DownloadFile("https://raw.githubusercontent.com/pyenv-win/pyenv-win/master/.version", $LatestVersionFilePath)
69
+ $LatestVersion = Get-Content $LatestVersionFilePath
70
+
71
+ Remove-Item -Path $LatestVersionFilePath
72
+
73
+ Return $LatestVersion
74
+ }
75
+
76
+ Function Main() {
77
+ If ($Uninstall) {
78
+ Remove-PyEnv
79
+ If ($? -eq $True) {
80
+ Write-Host "pyenv-win successfully uninstalled."
81
+ }
82
+ Else {
83
+ Write-Host "Uninstallation failed."
84
+ }
85
+ exit
86
+ }
87
+
88
+ $BackupDir = "${env:Temp}/pyenv-win-backup"
89
+
90
+ $CurrentVersion = Get-CurrentVersion
91
+ If ($CurrentVersion) {
92
+ Write-Host "pyenv-win $CurrentVersion installed."
93
+ $LatestVersion = Get-LatestVersion
94
+ If ($CurrentVersion -eq $LatestVersion) {
95
+ Write-Host "No updates available."
96
+ exit
97
+ }
98
+ Else {
99
+ Write-Host "New version available: $LatestVersion. Updating..."
100
+
101
+ Write-Host "Backing up existing Python installations..."
102
+ $FoldersToBackup = "install_cache", "versions", "shims"
103
+ ForEach ($Dir in $FoldersToBackup) {
104
+ If (-not (Test-Path $BackupDir)) {
105
+ New-Item -ItemType Directory -Path $BackupDir
106
+ }
107
+ Move-Item -Path "${PyEnvWinDir}/${Dir}" -Destination $BackupDir
108
+ }
109
+
110
+ Write-Host "Removing $PyEnvDir..."
111
+ Remove-Item -Path $PyEnvDir -Recurse
112
+ }
113
+ }
114
+
115
+ New-Item -Path $PyEnvDir -ItemType Directory
116
+
117
+ $DownloadPath = "$PyEnvDir\pyenv-win.zip"
118
+
119
+ (New-Object System.Net.WebClient).DownloadFile("https://github.com/pyenv-win/pyenv-win/archive/master.zip", $DownloadPath)
120
+
121
+ Start-Process -FilePath "powershell.exe" -ArgumentList @(
122
+ "-NoProfile",
123
+ "-Command `"Microsoft.PowerShell.Archive\Expand-Archive -Path $DownloadPath -DestinationPath $PyEnvDir`""
124
+ ) -NoNewWindow -Wait
125
+
126
+ Move-Item -Path "$PyEnvDir\pyenv-win-master\*" -Destination "$PyEnvDir"
127
+ Remove-Item -Path "$PyEnvDir\pyenv-win-master" -Recurse
128
+ Remove-Item -Path $DownloadPath
129
+
130
+ # Update env vars
131
+ [System.Environment]::SetEnvironmentVariable('PYENV', "${PyEnvWinDir}\", "User")
132
+ [System.Environment]::SetEnvironmentVariable('PYENV_ROOT', "${PyEnvWinDir}\", "User")
133
+ [System.Environment]::SetEnvironmentVariable('PYENV_HOME', "${PyEnvWinDir}\", "User")
134
+
135
+ $PathParts = [System.Environment]::GetEnvironmentVariable('PATH', "User") -Split ";"
136
+
137
+ # Remove existing paths, so we don't add duplicates
138
+ $NewPathParts = $PathParts.Where{ $_ -ne $BinPath }.Where{ $_ -ne $ShimsPath }
139
+ $NewPathParts = ($BinPath, $ShimsPath) + $NewPathParts
140
+ $NewPath = $NewPathParts -Join ";"
141
+ [System.Environment]::SetEnvironmentVariable('PATH', $NewPath, "User")
142
+
143
+ If (Test-Path $BackupDir) {
144
+ Write-Host "Restoring Python installations..."
145
+ Move-Item -Path "$BackupDir/*" -Destination $PyEnvWinDir
146
+ }
147
+
148
+ If ($? -eq $True) {
149
+ Write-Host "pyenv-win is successfully installed. You may need to close and reopen your terminal before using it."
150
+ }
151
+ Else {
152
+ Write-Host "pyenv-win was not installed successfully. If this issue persists, please open a ticket: https://github.com/pyenv-win/pyenv-win/issues."
153
+ }
154
+ }
155
+
156
+ Main
pyproject.toml ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [tool.ruff]
2
+ exclude = [
3
+ ".bzr",
4
+ ".direnv",
5
+ ".eggs",
6
+ ".git",
7
+ ".git-rewrite",
8
+ ".hg",
9
+ ".ipynb_checkpoints",
10
+ ".mypy_cache",
11
+ ".nox",
12
+ ".pants.d",
13
+ ".pyenv",
14
+ ".pytest_cache",
15
+ ".pytype",
16
+ ".ruff_cache",
17
+ ".svn",
18
+ ".tox",
19
+ ".venv",
20
+ ".vscode",
21
+ "__pypackages__",
22
+ "_build",
23
+ "buck-out",
24
+ "build",
25
+ "dist",
26
+ "node_modules",
27
+ "site-packages",
28
+ "venv",
29
+ ]
30
+
31
+ # Same as Black.
32
+ line-length = 88
33
+ indent-width = 4
34
+
35
+ # Assume Python 3.8
36
+ target-version = "py38"
37
+
38
+ [tool.ruff.lint]
39
+ select = ["E4", "E7", "E9", "F"]
40
+ ignore = []
41
+
42
+ # Allow fix for all enabled rules (when `--fix`) is provided.
43
+ fixable = ["ALL"]
44
+ unfixable = []
45
+
46
+ # Allow unused variables when underscore-prefixed.
47
+ dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
48
+
49
+ [tool.ruff.format]
50
+ quote-style = "double"
51
+ indent-style = "space"
52
+ skip-magic-trailing-comma = false
53
+ line-ending = "auto"
54
+
55
+ docstring-code-format = false
56
+
57
+ docstring-code-line-length = "dynamic"
requirements.dev.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ -r requirements.txt
2
+
3
+ ruff==0.4.2