-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmake.ps1
114 lines (111 loc) · 3.71 KB
/
make.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
param (
[string]$task = "active"
)
$ErrorActionPreference = 'Stop'
# Function to get the latest Python 3.10 version from pyenv
function Get-LatestPythonVersion {
$versions = pyenv versions --bare 3.10.*
$latestVersion = $versions | Where-Object { $_ -match '^3\.10\.[a-zA-Z0-9]+$' } | Sort-Object -Descending | Select-Object -First 1
return $latestVersion
}
if ($task -eq "active")
{
.\venv\Scripts\activate
if ($null -ne $env:PYTHONPATH)
{
if (-not ($env:PYTHONPATH -match [regex]::Escape($PWD)))
{
$env:PYTHONPATH = "$PWD" + ";$env:PYTHONPATH"
Write-Output "`nPYTHONPATH changed. It is '$( $env:PYTHONPATH )'"
}
else
{
Write-Output "`nPYTHONPATH not changed. It is '$( $env:PYTHONPATH )'"
}
}
else
{
$env:PYTHONPATH = $PWD
Write-Output "`nPYTHONPATH set to: $( $env:PYTHONPATH )"
}
Write-Output "`nThe Python used in the '$(Split-Path -Leaf $env:VIRTUAL_ENV)' environment is:"
Get-Command python
}
elseif ($task -eq "make")
{
Remove-Item -Path ".\venv" -Recurse -Force -ErrorAction SilentlyContinue
if (Test-Path $env:USERPROFILE\.pyenv) {
$latestVersion = Get-LatestPythonVersion
if ($latestVersion) {
pyenv global $latestVersion
pyenv local $latestVersion
Remove-Item -Path '.python-version' -Force -ErrorAction SilentlyContinue
Write-Output "Python $latestVersion set as both local and global version using pyenv."
} else {
Write-Warning "No Python 3.10 versions found with pyenv."
}
} else {
$pythonVersion = python --version 2>&1
if ($pythonVersion -like "*3.10*") {
Write-Output "Python 3.10 is identified as the system's Python version."
} else {
Write-Warning "Python 3.10 is not installed or configured. Please install Python 3.10 or pyenv."
}
}
python -m venv ./venv
if ($?) {
Write-Host "Virtual environment 'venv' created successfully." -ForegroundColor Green
} else {
Write-Host "Failed to create virtual environment 'venv'." -ForegroundColor Red
exit 1
}
.\venv\Scripts\activate
if ($null -ne $env:PYTHONPATH)
{
if (-not ($env:PYTHONPATH -match [regex]::Escape($PWD)))
{
$env:PYTHONPATH = "$PWD" + ";$env:PYTHONPATH"
Write-Output "`nPYTHONPATH changed. It is '$( $env:PYTHONPATH )'"
}
else
{
Write-Output "`nPYTHONPATH not changed. It is '$( $env:PYTHONPATH )'"
}
}
else
{
$env:PYTHONPATH = $PWD
Write-Output "`nPYTHONPATH set to: $( $env:PYTHONPATH )"
}
Write-Output "`nThe Python used in the '$(Split-Path -Leaf $env:VIRTUAL_ENV)' environment is:"
Get-Command python
python.exe -m pip install --upgrade pip
pip install poetry==1.8.4
Remove-Item -Path 'poetry.lock' -Force -ErrorAction SilentlyContinue
poetry install --with dev
poetry run pre-commit install
}
elseif ($task -eq "test")
{
poetry run coverage run -m pytest --verbose --capture=no
poetry run coverage xml --quiet
poetry run coverage report
poetry run genbadge coverage --silent --local --input-file coverage.xml --output-file coverage.svg
}
elseif ($task -eq "lint")
{
poetry run ruff check . --fix --exit-non-zero-on-fix
poetry run ruff format
poetry run mypy .
}
elseif ($task -eq "clean")
{
pre-commit uninstall
deactivate
Remove-Item -Path ".\venv" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item -Path 'poetry.lock' -Force -ErrorAction SilentlyContinue
}
else
{
Write-Output "Only active, make, test, clean or lint are allowed as tasks"
}