mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-07-16 11:02:22 +03:00
trying to fix confusing colon error
This commit is contained in:
parent
ebbe28d93d
commit
1775bf0e1a
|
@ -347,7 +347,7 @@ def handle_licenses():
|
||||||
special_license_files.get(titles_dict[selected_title], "LICENSE"), "w"
|
special_license_files.get(titles_dict[selected_title], "LICENSE"), "w"
|
||||||
) as f:
|
) 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:])
|
||||||
|
|
||||||
shutil.rmtree("licenses")
|
shutil.rmtree("licenses")
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
@ -7,8 +6,10 @@ from pprint import pprint
|
||||||
# script to check if licenses generated have placeholders not replaced
|
# 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"):
|
||||||
file = open('../{{cookiecutter.project_slug}}/licenses/' + filename, 'r', encoding="utf8")
|
file = open(
|
||||||
|
"../{{cookiecutter.project_slug}}/licenses/" + filename, encoding="utf8"
|
||||||
|
)
|
||||||
|
|
||||||
# 'found' stores all found bracket instances
|
# 'found' stores all found bracket instances
|
||||||
found = []
|
found = []
|
||||||
|
@ -17,12 +18,12 @@ def check_scripts_for_placeholders():
|
||||||
# it skips instances of brackets until after 2 as to skip the jekyll header
|
# 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":
|
||||||
dashes += 1
|
dashes += 1
|
||||||
# skips any possible brackets until the jekyll header is skipped
|
# skips any possible brackets until the jekyll header is skipped
|
||||||
if dashes < 2:
|
if dashes < 2:
|
||||||
continue
|
continue
|
||||||
line = re.findall(r'\[.*\]', line)
|
line = re.findall(r"\[.*\]", line)
|
||||||
if line != []:
|
if line != []:
|
||||||
found += (i, line)
|
found += (i, line)
|
||||||
|
|
||||||
|
@ -33,7 +34,8 @@ def check_scripts_for_placeholders():
|
||||||
if len(brackets) > 0:
|
if len(brackets) > 0:
|
||||||
print()
|
print()
|
||||||
pprint(brackets)
|
pprint(brackets)
|
||||||
assert(len(brackets) == 0)
|
assert len(brackets) == 0
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
check_scripts_for_placeholders()
|
check_scripts_for_placeholders()
|
||||||
|
|
|
@ -3,12 +3,14 @@ import json
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from github import Github
|
from github import Github
|
||||||
|
|
||||||
CURRENT_FILE = Path(__file__)
|
CURRENT_FILE = Path(__file__)
|
||||||
ROOT = CURRENT_FILE.parents[1]
|
ROOT = CURRENT_FILE.parents[1]
|
||||||
GITHUB_TOKEN = os.getenv("GITHUB_TOKEN", None)
|
GITHUB_TOKEN = os.getenv("GITHUB_TOKEN", None)
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
"""
|
"""
|
||||||
Script entry point.
|
Script entry point.
|
||||||
|
@ -20,14 +22,18 @@ def main() -> None:
|
||||||
for file in repo.get_contents("_licenses", "gh-pages"):
|
for file in repo.get_contents("_licenses", "gh-pages"):
|
||||||
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
|
||||||
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 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
|
||||||
front_options = [
|
front_options = [
|
||||||
|
@ -59,7 +65,7 @@ def update_cookiecutter(titles: list):
|
||||||
with open("cookiecutter.json") as f:
|
with open("cookiecutter.json") as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
data["open_source_license"] = titles
|
data["open_source_license"] = titles
|
||||||
with open("cookiecutter.json", "wt") as f:
|
with open("cookiecutter.json", "w") as f:
|
||||||
json.dump(data, f, indent=2)
|
json.dump(data, f, indent=2)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user