mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
Add make.ps1 cmdlet + activateenv command for Windows make scripts (#4087)
* Add missing command to `make.bat`'s help * Add `activateenv` and `deactivateenv` commands to `make.bat` * Add help to `Makefile` * Add `make.ps1` cmdlet
This commit is contained in:
parent
53c069a636
commit
1ff976b3d0
25
Makefile
25
Makefile
@ -1,7 +1,28 @@
|
||||
.DEFAULT_GOAL := help
|
||||
|
||||
PYTHON ?= python3.8
|
||||
|
||||
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
|
||||
|
||||
define HELP_BODY
|
||||
Usage:
|
||||
make <command>
|
||||
|
||||
Commands:
|
||||
reformat Reformat all .py files being tracked by git.
|
||||
stylecheck Check which tracked .py files need reformatting.
|
||||
stylediff Show the post-reformat diff of the tracked .py files
|
||||
without modifying them.
|
||||
gettext Generate pot files.
|
||||
upload_translations Upload pot files to Crowdin.
|
||||
download_translations Download translations from Crowdin.
|
||||
bumpdeps Run script bumping dependencies.
|
||||
newenv Create or replace this project's virtual environment.
|
||||
syncenv Sync this project's virtual environment to Red's latest
|
||||
dependencies.
|
||||
endef
|
||||
export HELP_BODY
|
||||
|
||||
# Python Code Style
|
||||
reformat:
|
||||
$(PYTHON) -m black $(ROOT_DIR)
|
||||
@ -29,3 +50,7 @@ newenv:
|
||||
$(MAKE) syncenv
|
||||
syncenv:
|
||||
.venv/bin/pip install -Ur ./tools/dev-requirements.txt
|
||||
|
||||
# Help
|
||||
help:
|
||||
@echo "$$HELP_BODY"
|
||||
|
||||
28
make.bat
28
make.bat
@ -2,31 +2,32 @@
|
||||
|
||||
if [%1] == [] goto help
|
||||
|
||||
REM This allows us to expand variables at execution
|
||||
setlocal ENABLEDELAYEDEXPANSION
|
||||
|
||||
goto %1
|
||||
|
||||
:reformat
|
||||
black "%~dp0."
|
||||
exit /B %ERRORLEVEL%
|
||||
"%~dp0.venv\Scripts\black" "%~dp0."
|
||||
goto:eof
|
||||
|
||||
:stylecheck
|
||||
black --check "%~dp0."
|
||||
exit /B %ERRORLEVEL%
|
||||
"%~dp0.venv\Scripts\black" --check "%~dp0."
|
||||
goto:eof
|
||||
|
||||
:stylediff
|
||||
black --check --diff "%~dp0."
|
||||
exit /B %ERRORLEVEL%
|
||||
"%~dp0.venv\Scripts\black" --check --diff "%~dp0."
|
||||
goto:eof
|
||||
|
||||
:newenv
|
||||
py -3.8 -m venv --clear .venv
|
||||
.\.venv\Scripts\python -m pip install -U pip setuptools wheel
|
||||
"%~dp0.venv\Scripts\python" -m pip install -U pip setuptools wheel
|
||||
goto syncenv
|
||||
|
||||
:syncenv
|
||||
.\.venv\Scripts\python -m pip install -Ur .\tools\dev-requirements.txt
|
||||
exit /B %ERRORLEVEL%
|
||||
"%~dp0.venv\Scripts\python" -m pip install -Ur .\tools\dev-requirements.txt
|
||||
goto:eof
|
||||
|
||||
:activateenv
|
||||
CALL "%~dp0.venv\Scripts\activate.bat"
|
||||
goto:eof
|
||||
|
||||
:help
|
||||
echo Usage:
|
||||
@ -35,6 +36,9 @@ echo.
|
||||
echo Commands:
|
||||
echo reformat Reformat all .py files being tracked by git.
|
||||
echo stylecheck Check which tracked .py files need reformatting.
|
||||
echo stylediff Show the post-reformat diff of the tracked .py files
|
||||
echo without modifying them.
|
||||
echo newenv Create or replace this project's virtual environment.
|
||||
echo syncenv Sync this project's virtual environment to Red's latest
|
||||
echo dependencies.
|
||||
echo activateenv Activates project's virtual environment.
|
||||
|
||||
89
make.ps1
Normal file
89
make.ps1
Normal file
@ -0,0 +1,89 @@
|
||||
<#
|
||||
.Synopsis
|
||||
Makefile script in PowerShell that contains commands useful during development for Red.
|
||||
|
||||
.Description
|
||||
Available commands:
|
||||
reformat Reformat all .py files being tracked by git.
|
||||
stylecheck Check which tracked .py files need reformatting.
|
||||
stylediff Show the post-reformat diff of the tracked .py files
|
||||
without modifying them.
|
||||
newenv Create or replace this project's virtual environment.
|
||||
syncenv Sync this project's virtual environment to Red's latest
|
||||
dependencies.
|
||||
activateenv Activates project's virtual environment.
|
||||
|
||||
.Parameter Command
|
||||
Command to execute. See Cmdlet's description for more information.
|
||||
|
||||
#>
|
||||
|
||||
# I'm too dumb for PowerShell, so $script:availableCommands needs to be defined in 2 places // Jack
|
||||
|
||||
[CmdletBinding()]
|
||||
param (
|
||||
[Parameter(Mandatory=$false)]
|
||||
[ArgumentCompleter({
|
||||
param (
|
||||
$commandName,
|
||||
$parameterName,
|
||||
$wordToComplete,
|
||||
$commandAst,
|
||||
$fakeBoundParameters
|
||||
)
|
||||
$script:availableCommands = @("reformat", "stylecheck", "stylediff", "newenv", "syncenv", "activateenv")
|
||||
return $script:availableCommands | Where-Object { $_ -like "$wordToComplete*" }
|
||||
})]
|
||||
[String]
|
||||
$command,
|
||||
[switch]
|
||||
$help = $false
|
||||
)
|
||||
|
||||
function reformat() {
|
||||
black $PSScriptRoot
|
||||
}
|
||||
|
||||
function stylecheck() {
|
||||
black --check $PSScriptRoot
|
||||
}
|
||||
|
||||
function stylediff() {
|
||||
black --check --diff $PSScriptRoot
|
||||
}
|
||||
|
||||
function newenv() {
|
||||
py -3.8 -m venv --clear .venv
|
||||
.\.venv\Scripts\python.exe -m pip install -U pip setuptools
|
||||
syncenv
|
||||
}
|
||||
|
||||
function syncenv() {
|
||||
.\.venv\Scripts\python.exe -m pip install -Ur .\tools\dev-requirements.txt
|
||||
}
|
||||
|
||||
function activateenv() {
|
||||
.\.venv\Scripts\Activate.ps1
|
||||
}
|
||||
|
||||
$script:availableCommands = @("reformat", "stylecheck", "stylediff", "newenv", "syncenv", "activateenv")
|
||||
|
||||
if ($help -or !$command) {
|
||||
Get-Help $MyInvocation.InvocationName
|
||||
exit
|
||||
}
|
||||
|
||||
switch ($command) {
|
||||
{$script:availableCommands -contains $_} {
|
||||
& $command
|
||||
break
|
||||
}
|
||||
default {
|
||||
Write-Host (
|
||||
"""$command"" is not a valid command.",
|
||||
"To see available commands, type: ""$($MyInvocation.InvocationName) -help"""
|
||||
)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user