cookiecutter-flit

A Cookiecutter template for a Flit package
git clone git://git.danielmoch.com/cookiecutter-flit.git
Log | Files | Refs | LICENSE

commit 4da21073897e5fbc7be1a107aff921072a4e7ce8
parent e9c004c366c98a7b2898c06a07f68376de20fa4c
Author: Daniel Moch <daniel@danielmoch.com>
Date:   Sat, 15 Sep 2018 17:01:07 -0400

Add make.bat for Windows support

Diffstat:
Mhooks/post_gen_project.py | 1+
A{{cookiecutter.project_slug}}/make.bat | 179+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 180 insertions(+), 0 deletions(-)

diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py @@ -22,6 +22,7 @@ def remove_file(filepath): if 'n' == '{{ cookiecutter.windows_support }}': remove_file('appveyor.yml') remove_file(os.path.sep.join(['docs', 'make.bat'])) + remove_file('make.bat') if 'n' == '{{ cookiecutter.docs }}': remove_dir('docs') diff --git a/{{cookiecutter.project_slug}}/make.bat b/{{cookiecutter.project_slug}}/make.bat @@ -0,0 +1,179 @@ +@echo off +set BROWSER_PYSCRIPT=import os, webbrowser, sys^ + +try:^ + + from urllib import pathname2url^ + +except:^ + + from urllib.request import pathname2url^ + +webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1]))) + +set PRINT_HELP_PYSCRIPT=import re, sys^ + +for line in sys.stdin:^ + + match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$', line)^ + + if match:^ + + target, help = match.groups()^ + + print("%-20s %s" % (target, help)) + +if "%PYTHON%"=="" ( + set PYTHON=python +) else ( + set "PATH=%PYTHON%;%PYTHON%\Scripts;%PATH%" + set PYTHON=python +) + +set PIP=pip +set PIPENV=pipenv +set PIPRUN=%PIPENV% run +set PIPINST=%PIPENV% --bare install --dev --skip-lock +set BROWSER=%PYTHON% -c %BROWSER_PYSCRIPT% + +if "%1" == "help" ( + %PYTHON% -c "%PRINT_HELP_PYSCRIPT%" < %~f0 + goto :end +) + +if "%1" == "clean" ( + call :cleanbuild + call :cleanpyc + call :cleantest + goto :end +) + +if "%1" == "cleanbuild" ( + call :cleanbuild + goto :end +) + +if "%1" == "cleanpyc" ( + call :cleanpyc + goto :end +) + +if "%1" == "cleantest" ( + call :cleantest + goto :end +) + +if "%1" == "lint" ( + @echo on + %PIPRUN% pylint {{ cookiecutter.project_slug }} tests --disable=parse-error + @echo off + goto :end +) + +if "%1" == "test" ( + @echo on + %PIPRUN% python -m pytest + @echo off + goto :end +) + +if "%1" == "test-all" ( + @echo on + %PIPRUN% tox + @echo off + goto :end +) + +if "%1" == "test-install" ( + @echo on + %PYTHON% -m %PIP% install --upgrade pip pipenv + %PIPINST% + @echo off + goto :end +) + +if "%1" == "coverage" ( + @echo on + %PIPRUN% python -m pytest --cov={{ cookiecutter.project_slug }} + @echo off + goto :end +) + +if "%1" == "coverage-html" ( + @echo on + %PIPRUN% python -m pytest --cov={{ cookiecutter.project_slug }} + %PIPRUN% coverage html + %BROWSER% htmlcov\index.html + @echo off + goto :end +) + +if "%1" == "release" ( + @echo on + %PIPRUN% flit build + dir dist + %PIPRUN% flit publish + @echo off + goto :end +) + +if "%1" == "dist" ( + @echo on + %PIPRUN% flit build + dir dist + @echo off + goto :end +) + +if "%1" == "install" ( + @echo on + %PIPRUN% flit install --deps=none + @echo off + goto :end +) + +if "%1" == "run" ( + @echo on + %PIPRUN% python -m {{ cookiecutter.project_slug }} %cmd% + @echo off + goto :end +) + +if "%1" == "debug" ( + @echo on + %PIPRUN% flit install --deps=none + %PIPRUN% pudb3 {{ cookiecutter.project_slug }} %cmd% + @echo off + goto :end +) + +:cleanbuild +@echo on +rmdir /S /Q build +rmdir /S /Q dist +rmdir /S /Q .eggs +del /S *.egg-info +del /S *.egg +@echo off +exit /B 0 + +:cleanpyc +@echo on +del /S *.pyc +del /S *.pyo +del /S *~ +del /S __pycache__ +%PIPRUN% pip uninstall -y {{ cookiecutter.project_slug }} +@echo off +exit /B 0 + +:cleantest +@echo on +del .coverage +rmdir /S /Q htmlcov +rmdir /S /Q .pytest_cache +rmdir /S /Q .tox +@echo off +exit /B 0 + +:end