-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tobias Schoch
authored and
Tobias Schoch
committed
May 4, 2018
1 parent
d25f5bf
commit 61f174d
Showing
4 changed files
with
156 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,107 @@ | ||
.idea | ||
.idea | ||
### Python template | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# celery beat schedule file | ||
celerybeat-schedule | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +0,0 @@ | ||
# -*- coding: utf-8 -*- | ||
import os | ||
import re | ||
import shutil | ||
|
||
|
||
def fix_template_expansion(content, replacements): | ||
""" | ||
fix template expansion after hook copy | ||
:param content: the duplicated hook content | ||
:param replacements: array of dictionaries | ||
cookiecutter_key => template key expanded | ||
""" | ||
for replacement in replacements: | ||
for key, to_be_replaced in replacement.items(): | ||
replacement = chr(123) + chr(123) + \ | ||
'cookiecutter.' + key + chr(125) + chr(125) | ||
content = content.replace(to_be_replaced, replacement) | ||
return content | ||
|
||
|
||
def get_file_content(file): | ||
""" | ||
get the content of a given file | ||
:param file: the file to get the content of | ||
""" | ||
return open(file, 'r').read() | ||
|
||
|
||
def set_file_content(file, content): | ||
""" | ||
write content to file | ||
:param file: the file to rewrite its content | ||
:param content: content to write to the given file | ||
""" | ||
return open(file, 'w').write(content) | ||
|
||
# format title of the generated readme file | ||
readme = os.getcwd() + '/README.md' | ||
if (os.path.exists(readme)): | ||
title_underliner = ''.center(len('{{cookiecutter.project_name}}'), '=') | ||
set_file_content( | ||
readme, | ||
re.sub( | ||
r'^=+$', title_underliner, get_file_content(readme), 1, flags=re.M | ||
) | ||
) | ||
# end format title of the generated readme file | ||
|
||
# issue #3 - copy post hook to project directory | ||
if (re.match(r'YES', '{{cookiecutter.copy_hooks}}', re.I)): | ||
if (re.match(r'^cookiecutter\-', '{{cookiecutter.project_slug}}')): | ||
hooksdir = os.getcwd() + '/hooks' | ||
posthook = hooksdir + '/post_gen_project.py' | ||
source = os.path.realpath(__file__) | ||
replacements = [ | ||
{'project_slug': '{{cookiecutter.project_slug}}'}, | ||
{'copy_hooks': '{{cookiecutter.copy_hooks}}'}, | ||
|
||
# project_name must be set after project_slug to prevent side | ||
# effects | ||
{'project_name': '{{cookiecutter.project_name}}'} | ||
] | ||
|
||
if (not os.path.exists(hooksdir)): | ||
os.makedirs(hooksdir) | ||
shutil.copyfile(source, posthook) | ||
|
||
set_file_content( | ||
posthook, | ||
fix_template_expansion( | ||
get_file_content(posthook), replacements | ||
) + "\n" | ||
) | ||
# end issue #3 | ||
|
||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
cookiecutter==1.6.0 | ||
flake8==3.5.0 | ||
pytest==3.3.2 | ||
pytest-cookies==0.3.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters