Skip to content

Commit

Permalink
Merge pull request #5614 from browniebroke/drop-python-2-hooks
Browse files Browse the repository at this point in the history
Drop support for Python 2 in template generation hooks
  • Loading branch information
browniebroke authored Jan 9, 2025
2 parents 7324393 + a623f7b commit c5b60d2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 53 deletions.
13 changes: 0 additions & 13 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
"""
NOTE:
the below code is to be maintained Python 2.x-compatible
as the whole Cookiecutter Django project initialization
can potentially be run in Python 2.x environment
(at least so we presume in `pre_gen_project.py`).
TODO: restrict Cookiecutter Django project initialization to
Python 3.x environments only
"""

from __future__ import print_function

import json
import os
import random
Expand Down
42 changes: 2 additions & 40 deletions hooks/pre_gen_project.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
"""
NOTE:
the below code is to be maintained Python 2.x-compatible
as the whole Cookiecutter Django project initialization
can potentially be run in Python 2.x environment.
TODO: restrict Cookiecutter Django project initialization
to Python 3.x environments only
"""

from __future__ import print_function

import sys

TERMINATOR = "\x1b[0m"
Expand All @@ -34,36 +22,10 @@

assert "\\" not in "{{ cookiecutter.author_name }}", "Don't include backslashes in author name."

if "{{ cookiecutter.use_docker }}".lower() == "n":
python_major_version = sys.version_info[0]
if python_major_version == 2:
print(
WARNING + "You're running cookiecutter under Python 2, but the generated "
"project requires Python 3.12+. Do you want to proceed (y/n)? " + TERMINATOR
)
yes_options, no_options = frozenset(["y"]), frozenset(["n"])
while True:
choice = raw_input().lower() # noqa: F821
if choice in yes_options:
break

elif choice in no_options:
print(INFO + "Generation process stopped as requested." + TERMINATOR)
sys.exit(1)
else:
print(
HINT
+ "Please respond with {} or {}: ".format(
", ".join(["'{}'".format(o) for o in yes_options if not o == ""]),
", ".join(["'{}'".format(o) for o in no_options if not o == ""]),
)
+ TERMINATOR
)

if "{{ cookiecutter.use_whitenoise }}".lower() == "n" and "{{ cookiecutter.cloud_provider }}" == "None":
print("You should either use Whitenoise or select a " "Cloud Provider to serve static files")
print("You should either use Whitenoise or select a Cloud Provider to serve static files")
sys.exit(1)

if "{{ cookiecutter.mail_service }}" == "Amazon SES" and "{{ cookiecutter.cloud_provider }}" != "AWS":
print("You should either use AWS or select a different " "Mail Service for sending emails.")
print("You should either use AWS or select a different Mail Service for sending emails.")
sys.exit(1)

0 comments on commit c5b60d2

Please sign in to comment.