Reputation: 156
Everytime I start a new project, I create a virtual environment, I upgrade pip, initialise a git repo, create .gitignore, requirements.txt, etc.
I'd like to automate this, so that I just start the process, and at the end, the terminal has the virtual environment activated.
While I'm mainly using Python, the question applies to any language.
I could chain tasks with the "dependsOn", but that's not the cleanest option.
Does anybody have suggestions? I couldn't find anything useful only.
Upvotes: 0
Views: 127
Reputation: 156
As suggest by Alejandro, I wrote a script (Powershell) and put it in the folder containing all my projects
Write-Host "=====> Python project setup <====="
Write-Host "Creating virtual environment"
if ( Test-Path -Path ./venv )
{
Write-Host "Virtual environment already exists"
}
else
{
python -m venv venv
}
./venv/Scripts/Activate.ps1 > $null
Write-Host "Installing packages"
python -m pip install --upgrade pip > $null
pip install wheel black > $null
Write-Host "Initialise git repo"
if ( Test-Path -Path ./.git )
{
Write-Host "Repository already exists"
}
else
{
git init
}
Write-Host "Creating files"
New-Item -Path . -Name "requirements.txt" -ItemType "file" -ErrorAction SilentlyContinue >$null
New-Item -Path . -Name ".gitignore" -ItemType "file" -Value "venv/`n" -ErrorAction SilentlyContinue >$null
And then, in the User tasks, I added this
{
"label": "Setup Python project",
"type": "shell",
"command": "../setup.ps1",
"args": ["${input:folder}"],
"presentation": {
"echo": false,
"reveal": "always",
"focus": true,
"panel": "shared",
},
"problemMatcher": []
}
Upvotes: 1