mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-08-08 14:04:52 +03:00
Remove envs when not opted for
This commit is contained in:
parent
50c8762dd0
commit
6ee9ed28ea
|
@ -7,12 +7,12 @@ NOTE:
|
||||||
|
|
||||||
TODO: ? restrict Cookiecutter Django project initialization to Python 3.x environments only
|
TODO: ? restrict Cookiecutter Django project initialization to Python 3.x environments only
|
||||||
"""
|
"""
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import shutil
|
import shutil
|
||||||
import string
|
import string
|
||||||
import sys
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Inspired by
|
# Inspired by
|
||||||
|
@ -22,6 +22,12 @@ try:
|
||||||
except NotImplementedError:
|
except NotImplementedError:
|
||||||
using_sysrandom = False
|
using_sysrandom = False
|
||||||
|
|
||||||
|
TERMINATOR = "\x1b[0m"
|
||||||
|
WARNING = "\x1b[1;33m [WARNING]: "
|
||||||
|
INFO = "\x1b[1;33m [INFO]: "
|
||||||
|
HINT = "\x1b[3;33m"
|
||||||
|
SUCCESS = "\x1b[1;32m [SUCCESS]: "
|
||||||
|
|
||||||
PROJECT_DIR_PATH = os.path.realpath(os.path.curdir) # TODO: ? I doubt even need that
|
PROJECT_DIR_PATH = os.path.realpath(os.path.curdir) # TODO: ? I doubt even need that
|
||||||
|
|
||||||
|
|
||||||
|
@ -146,8 +152,7 @@ def set_flag(file_path,
|
||||||
if value is None:
|
if value is None:
|
||||||
random_string = generate_random_string(*args, **kwargs)
|
random_string = generate_random_string(*args, **kwargs)
|
||||||
if random_string is None:
|
if random_string is None:
|
||||||
import sys
|
print(
|
||||||
sys.stdout.write(
|
|
||||||
"We couldn't find a secure pseudo-random number generator on your system. "
|
"We couldn't find a secure pseudo-random number generator on your system. "
|
||||||
"Please, make sure to manually {} later.".format(flag)
|
"Please, make sure to manually {} later.".format(flag)
|
||||||
)
|
)
|
||||||
|
@ -223,8 +228,6 @@ def append_to_gitignore_file(s):
|
||||||
|
|
||||||
|
|
||||||
def set_flags_in_envs(postgres_user):
|
def set_flags_in_envs(postgres_user):
|
||||||
append_to_gitignore_file('.envs' + '/**/*')
|
|
||||||
|
|
||||||
local_postgres_envs_path = os.path.join(PROJECT_DIR_PATH, '.envs', '.local', '.postgres')
|
local_postgres_envs_path = os.path.join(PROJECT_DIR_PATH, '.envs', '.local', '.postgres')
|
||||||
set_postgres_user(local_postgres_envs_path, value=postgres_user)
|
set_postgres_user(local_postgres_envs_path, value=postgres_user)
|
||||||
set_postgres_password(local_postgres_envs_path)
|
set_postgres_password(local_postgres_envs_path)
|
||||||
|
@ -243,6 +246,11 @@ def set_flags_in_settings_files():
|
||||||
set_django_secret_key(os.path.join(PROJECT_DIR_PATH, 'config', 'settings', 'test.py'))
|
set_django_secret_key(os.path.join(PROJECT_DIR_PATH, 'config', 'settings', 'test.py'))
|
||||||
|
|
||||||
|
|
||||||
|
def remove_envs_and_associated_files():
|
||||||
|
shutil.rmtree('.envs')
|
||||||
|
os.remove('merge_production_dotenvs_in_dotenv.py')
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
postgres_user = generate_postgres_user()
|
postgres_user = generate_postgres_user()
|
||||||
set_flags_in_envs(postgres_user)
|
set_flags_in_envs(postgres_user)
|
||||||
|
@ -262,6 +270,24 @@ def main():
|
||||||
if '{{ cookiecutter.use_heroku }}'.lower() == 'n':
|
if '{{ cookiecutter.use_heroku }}'.lower() == 'n':
|
||||||
remove_heroku_files()
|
remove_heroku_files()
|
||||||
|
|
||||||
|
envs_make_sense = '{{ cookiecutter.use_docker }}'.lower() == 'n' \
|
||||||
|
and '{{ cookiecutter.use_heroku }}'.lower() == 'n'
|
||||||
|
if envs_make_sense:
|
||||||
|
if '{{ cookiecutter.keep_local_envs_in_vcs }}'.lower() == 'y':
|
||||||
|
print(
|
||||||
|
INFO +
|
||||||
|
".env(s) are only utilized when Docker Compose and/or "
|
||||||
|
"Heroku support is enabled so keeping them does not "
|
||||||
|
"make sense given your current setup." +
|
||||||
|
TERMINATOR
|
||||||
|
)
|
||||||
|
remove_envs_and_associated_files()
|
||||||
|
else:
|
||||||
|
append_to_gitignore_file('.env')
|
||||||
|
append_to_gitignore_file('.envs' + '/**/*')
|
||||||
|
if '{{ cookiecutter.keep_local_envs_in_vcs }}'.lower() == 'y':
|
||||||
|
append_to_gitignore_file('!.envs/.local/')
|
||||||
|
|
||||||
if '{{ cookiecutter.js_task_runner}}'.lower() == 'gulp':
|
if '{{ cookiecutter.js_task_runner}}'.lower() == 'gulp':
|
||||||
remove_grunt_files()
|
remove_grunt_files()
|
||||||
elif '{{ cookiecutter.js_task_runner}}'.lower() == 'grunt':
|
elif '{{ cookiecutter.js_task_runner}}'.lower() == 'grunt':
|
||||||
|
@ -270,18 +296,20 @@ def main():
|
||||||
remove_gulp_files()
|
remove_gulp_files()
|
||||||
remove_grunt_files()
|
remove_grunt_files()
|
||||||
remove_packagejson_file()
|
remove_packagejson_file()
|
||||||
|
|
||||||
if '{{ cookiecutter.js_task_runner }}'.lower() in ['grunt', 'gulp'] \
|
if '{{ cookiecutter.js_task_runner }}'.lower() in ['grunt', 'gulp'] \
|
||||||
and '{{ cookiecutter.use_docker }}'.lower() == 'y':
|
and '{{ cookiecutter.use_docker }}'.lower() == 'y':
|
||||||
TERMINATOR = "\x1b[0m"
|
print(
|
||||||
INFO = "\x1b[1;33m [INFO]: "
|
WARNING +
|
||||||
sys.stdout.write(
|
"Docker and {} JS task runner ".format(
|
||||||
INFO +
|
'{{ cookiecutter.js_task_runner }}'
|
||||||
"Docker and {} JS task runner ".format('{{ cookiecutter.js_task_runner }}'.lower().capitalize()) +
|
.lower()
|
||||||
|
.capitalize()
|
||||||
|
) +
|
||||||
"working together not supported yet. "
|
"working together not supported yet. "
|
||||||
"You can continue using the generated project like you normally would, "
|
"You can continue using the generated project like you "
|
||||||
"however you would need to add a JS task runner service "
|
"normally would, however you would need to add a JS "
|
||||||
"to your Docker Compose configuration manually." +
|
"task runner service to your Docker Compose configuration "
|
||||||
|
"manually." +
|
||||||
TERMINATOR
|
TERMINATOR
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -291,8 +319,11 @@ def main():
|
||||||
if '{{ cookiecutter.use_travisci }}'.lower() == 'n':
|
if '{{ cookiecutter.use_travisci }}'.lower() == 'n':
|
||||||
remove_dottravisyml_file()
|
remove_dottravisyml_file()
|
||||||
|
|
||||||
if '{{ cookiecutter.keep_local_envs_in_vcs }}'.lower() == 'y':
|
print(
|
||||||
append_to_gitignore_file('!.envs/.local/')
|
SUCCESS +
|
||||||
|
"Project initialized, keep up the good work!" +
|
||||||
|
TERMINATOR
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -6,6 +6,15 @@ NOTE:
|
||||||
|
|
||||||
TODO: ? restrict Cookiecutter Django project initialization to Python 3.x environments only
|
TODO: ? restrict Cookiecutter Django project initialization to Python 3.x environments only
|
||||||
"""
|
"""
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
TERMINATOR = "\x1b[0m"
|
||||||
|
WARNING = "\x1b[1;33m [WARNING]: "
|
||||||
|
INFO = "\x1b[1;33m [INFO]: "
|
||||||
|
HINT = "\x1b[3;33m"
|
||||||
|
SUCCESS = "\x1b[1;32m [SUCCESS]: "
|
||||||
|
|
||||||
project_slug = '{{ cookiecutter.project_slug }}'
|
project_slug = '{{ cookiecutter.project_slug }}'
|
||||||
if hasattr(project_slug, 'isidentifier'):
|
if hasattr(project_slug, 'isidentifier'):
|
||||||
|
@ -13,20 +22,11 @@ if hasattr(project_slug, 'isidentifier'):
|
||||||
|
|
||||||
assert "\\" not in "{{ cookiecutter.author_name }}", "Don't include backslashes in author name."
|
assert "\\" not in "{{ cookiecutter.author_name }}", "Don't include backslashes in author name."
|
||||||
|
|
||||||
|
|
||||||
using_docker = '{{ cookiecutter.use_docker }}'.lower()
|
using_docker = '{{ cookiecutter.use_docker }}'.lower()
|
||||||
if using_docker == 'n':
|
if using_docker == 'n':
|
||||||
TERMINATOR = "\x1b[0m"
|
|
||||||
WARNING = "\x1b[1;33m [WARNING]: "
|
|
||||||
INFO = "\x1b[1;33m [INFO]: "
|
|
||||||
HINT = "\x1b[3;33m"
|
|
||||||
SUCCESS = "\x1b[1;32m [SUCCESS]: "
|
|
||||||
|
|
||||||
import sys
|
|
||||||
|
|
||||||
python_major_version = sys.version_info[0]
|
python_major_version = sys.version_info[0]
|
||||||
if python_major_version == 2:
|
if python_major_version == 2:
|
||||||
sys.stdout.write(
|
print(
|
||||||
WARNING +
|
WARNING +
|
||||||
"Cookiecutter Django does not support Python 2. "
|
"Cookiecutter Django does not support Python 2. "
|
||||||
"Stability is guaranteed with Python 3.6+ only, "
|
"Stability is guaranteed with Python 3.6+ only, "
|
||||||
|
@ -39,14 +39,14 @@ if using_docker == 'n':
|
||||||
if choice in yes_options:
|
if choice in yes_options:
|
||||||
break
|
break
|
||||||
elif choice in no_options:
|
elif choice in no_options:
|
||||||
sys.stdout.write(
|
print(
|
||||||
INFO +
|
INFO +
|
||||||
"Generation process stopped as requested." +
|
"Generation process stopped as requested." +
|
||||||
TERMINATOR
|
TERMINATOR
|
||||||
)
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
sys.stdout.write(
|
print(
|
||||||
HINT +
|
HINT +
|
||||||
"Please respond with {} or {}: ".format(
|
"Please respond with {} or {}: ".format(
|
||||||
', '.join(["'{}'".format(o) for o in yes_options if not o == '']),
|
', '.join(["'{}'".format(o) for o in yes_options if not o == '']),
|
||||||
|
@ -54,9 +54,3 @@ if using_docker == 'n':
|
||||||
) +
|
) +
|
||||||
TERMINATOR
|
TERMINATOR
|
||||||
)
|
)
|
||||||
|
|
||||||
sys.stdout.write(
|
|
||||||
SUCCESS +
|
|
||||||
"Project initialized, keep up the good work!" +
|
|
||||||
TERMINATOR
|
|
||||||
)
|
|
||||||
|
|
2
{{cookiecutter.project_slug}}/.gitignore
vendored
2
{{cookiecutter.project_slug}}/.gitignore
vendored
|
@ -348,5 +348,3 @@ mailhog
|
||||||
# See issue https://github.com/pydanny/cookiecutter-django/issues/1321
|
# See issue https://github.com/pydanny/cookiecutter-django/issues/1321
|
||||||
!/compose/local/
|
!/compose/local/
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
.env
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user