mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-07-05 04:43:08 +03:00
style changes
This commit is contained in:
parent
5f9d74ae7c
commit
ebbe28d93d
|
@ -10,11 +10,11 @@ TODO: restrict Cookiecutter Django project initialization to
|
||||||
"""
|
"""
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
|
import json
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import shutil
|
import shutil
|
||||||
import string
|
import string
|
||||||
import json
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Inspired by
|
# Inspired by
|
||||||
|
@ -343,7 +343,9 @@ def handle_licenses():
|
||||||
with open(os.path.join("licenses", titles_dict[selected_title])) as f:
|
with open(os.path.join("licenses", titles_dict[selected_title])) as f:
|
||||||
contents = f.readlines()
|
contents = f.readlines()
|
||||||
|
|
||||||
with open(special_license_files.get(titles_dict[selected_title], "LICENSE"), "w") as f:
|
with open(
|
||||||
|
special_license_files.get(titles_dict[selected_title], "LICENSE"), "w"
|
||||||
|
) as f:
|
||||||
# +2 to get rid of the --- and and an extra new line
|
# +2 to get rid of the --- and and an extra new line
|
||||||
f.writelines(contents[contents.index("---\n", 1) + 2 :])
|
f.writelines(contents[contents.index("---\n", 1) + 2 :])
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,9 @@
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
|
|
||||||
# script to check if licenses generated have placeholders not replaced with cookiecutter rendering
|
# script to check if licenses generated have placeholders not replaced
|
||||||
def check_scripts_for_placeholders():
|
def check_scripts_for_placeholders():
|
||||||
brackets = []
|
brackets = []
|
||||||
for filename in os.listdir('../{{cookiecutter.project_slug}}/licenses'):
|
for filename in os.listdir('../{{cookiecutter.project_slug}}/licenses'):
|
||||||
|
@ -13,8 +12,9 @@ def check_scripts_for_placeholders():
|
||||||
|
|
||||||
# 'found' stores all found bracket instances
|
# 'found' stores all found bracket instances
|
||||||
found = []
|
found = []
|
||||||
# dashes counts the '---\n' lines in the licenses. it skips instances of brackets until after the first 2 as to
|
|
||||||
# skip the jekyll header
|
# dashes counts the '---\n' lines in the licenses.
|
||||||
|
# it skips instances of brackets until after 2 as to skip the jekyll header
|
||||||
dashes = 0
|
dashes = 0
|
||||||
for i, line in enumerate(file.readlines()):
|
for i, line in enumerate(file.readlines()):
|
||||||
if line == '---\n':
|
if line == '---\n':
|
||||||
|
@ -26,7 +26,8 @@ def check_scripts_for_placeholders():
|
||||||
if line != []:
|
if line != []:
|
||||||
found += (i, line)
|
found += (i, line)
|
||||||
|
|
||||||
# add any found instaces of bracket placeholders to the brackets array, and print it after the loop is executed
|
# add any found instances of placeholders to the brackets array
|
||||||
|
# print it after the loop is executed
|
||||||
if found != []:
|
if found != []:
|
||||||
brackets += (filename, found)
|
brackets += (filename, found)
|
||||||
if len(brackets) > 0:
|
if len(brackets) > 0:
|
||||||
|
|
|
@ -21,13 +21,12 @@ def main() -> None:
|
||||||
content = codecs.decode(file.decoded_content)
|
content = codecs.decode(file.decoded_content)
|
||||||
# make below line into a dictionary mapping to filename
|
# make below line into a dictionary mapping to filename
|
||||||
titles_dict[content.split("\n", maxsplit=2)[1].replace("title: ", "")] = file.name
|
titles_dict[content.split("\n", maxsplit=2)[1].replace("title: ", "")] = file.name
|
||||||
#titles.append(content.split("\n", maxsplit=2)[1].replace("title: ", ""))
|
|
||||||
path = license_dir / file.name
|
path = license_dir / file.name
|
||||||
if not path.is_file():
|
if not path.is_file():
|
||||||
path.touch()
|
path.touch()
|
||||||
(license_dir / file.name).write_text(replace_content_options(content))
|
(license_dir / file.name).write_text(replace_content_options(content))
|
||||||
|
|
||||||
# write the titles dictionary to a json file and put it in workflows so it can be accessed by other files
|
# write the titles dictionary to a json file so it can be accessed by other files
|
||||||
with open('{{cookiecutter.project_slug}}/licenses/licenses.json', 'w') as licenses_dict:
|
with open('{{cookiecutter.project_slug}}/licenses/licenses.json', 'w') as licenses_dict:
|
||||||
json.dump(titles_dict, licenses_dict, indent=2)
|
json.dump(titles_dict, licenses_dict, indent=2)
|
||||||
# Put "Not open source" at front so people know it's an option
|
# Put "Not open source" at front so people know it's an option
|
||||||
|
|
Loading…
Reference in New Issue
Block a user