-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclean_environment.bat
76 lines (68 loc) · 2.31 KB
/
clean_environment.bat
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
@echo off
setlocal enabledelayedexpansion
:: Initialize flags
set fastFlag=0
set softFlag=0
set uninstallFlag=0
:: Process command line arguments
:parse_args
if "%~1"=="" goto args_passed
:: Check against known flags
set "flag_found="
for %%i in (fast soft uninstall) do (
if /I "%~1"=="--%%i" (
set %%iFlag=1
set flag_found=1
)
)
:: Handle unknown flags
if not defined flag_found (
echo Unknown option: %1
exit /b 1
)
shift
goto parse_args
:args_passed
if !fastFlag! equ 1 if !uninstallFlag! equ 0 goto install_req
echo #############################################################
echo # #
echo # Remove installed packages #
echo # #
echo #############################################################
.env\Scripts\pip.exe freeze > installed_packages_to_be_uninstalled.txt
set size=0
:: Check for unempty file
for /f %%i in ("installed_packages_to_be_uninstalled.txt") do set size=%%~zi
if %size% gtr 0 .env\Scripts\pip.exe uninstall -r installed_packages_to_be_uninstalled.txt -y
del installed_packages_to_be_uninstalled.txt
if !uninstallFlag! equ 1 goto activate_environment
:install_req
echo #############################################################
echo # #
echo # Install packages #
echo # #
echo #############################################################
.env\Scripts\python.exe -m pip install --upgrade pip
if !softFlag! equ 1 goto soft_requirements
:: Install hard requirements
.env\Scripts\pip.exe install -r requirements-dev.txt
.env\Scripts\pip.exe install -r requirements.txt
pre-commit install
goto activate_environment
:soft_requirements
:: Install soft (enversioned requirements)
:: Create an empty output file
set "outputFile=packages.txt"
type nul > %outputFile%
for %%f in (.txt -dev.txt) do (
set "inputFile=requirements%%f"
for /f "tokens=1,* delims==" %%a in (%inputFile%) do (
set "packageName=%%a"
echo !packageName!>>%outputFile%
)
)
pip install -r %outputFile%
del %outputFile%
pre-commit install
:activate_environment
.env\Scripts\activate.bat