mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-08-08 05:54:53 +03:00
Introduce keep_local_envs_in_vcs option
This commit is contained in:
parent
aba1b3aca9
commit
50c8762dd0
|
@ -192,6 +192,7 @@ Answer the prompts with your own desired options_. For example::
|
||||||
4 - Apache Software License 2.0
|
4 - Apache Software License 2.0
|
||||||
5 - Not open source
|
5 - Not open source
|
||||||
Choose from 1, 2, 3, 4, 5 [1]: 1
|
Choose from 1, 2, 3, 4, 5 [1]: 1
|
||||||
|
keep_local_envs_in_vcs [y]: y
|
||||||
|
|
||||||
Enter the project and take a look around::
|
Enter the project and take a look around::
|
||||||
|
|
||||||
|
|
|
@ -39,5 +39,6 @@
|
||||||
"use_opbeat": "n",
|
"use_opbeat": "n",
|
||||||
"use_whitenoise": "y",
|
"use_whitenoise": "y",
|
||||||
"use_heroku": "n",
|
"use_heroku": "n",
|
||||||
"use_travisci": "n"
|
"use_travisci": "n",
|
||||||
|
"keep_local_envs_in_vcs": "y"
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,6 +94,11 @@ use_heroku [n]
|
||||||
use_travisci [n]
|
use_travisci [n]
|
||||||
Indicates whether the project should be configured to use `Travis CI`_.
|
Indicates whether the project should be configured to use `Travis CI`_.
|
||||||
|
|
||||||
|
keep_local_envs_in_vcs [y]
|
||||||
|
Indicates whether the project's `.envs/.local/` should be kept in VCS
|
||||||
|
(comes in handy when working in teams where local environment reproducibility
|
||||||
|
is strongly encouraged).
|
||||||
|
|
||||||
|
|
||||||
.. _MIT: https://opensource.org/licenses/MIT
|
.. _MIT: https://opensource.org/licenses/MIT
|
||||||
.. _BSD: https://opensource.org/licenses/BSD-3-Clause
|
.. _BSD: https://opensource.org/licenses/BSD-3-Clause
|
||||||
|
|
|
@ -216,39 +216,37 @@ def set_postgres_password(file_path):
|
||||||
return postgres_password
|
return postgres_password
|
||||||
|
|
||||||
|
|
||||||
def append_to_gitignore_file(s) -> None:
|
def append_to_gitignore_file(s):
|
||||||
with open(os.path.join(PROJECT_DIR_PATH, '.gitignore'), 'a') as gitignore_file:
|
with open(os.path.join(PROJECT_DIR_PATH, '.gitignore'), 'a') as gitignore_file:
|
||||||
gitignore_file.write(s)
|
gitignore_file.write(s)
|
||||||
gitignore_file.write(os.linesep)
|
gitignore_file.write(os.linesep)
|
||||||
|
|
||||||
|
|
||||||
def initialize_envs(postgres_user):
|
def set_flags_in_envs(postgres_user):
|
||||||
envs_dir_path = '.envs'
|
append_to_gitignore_file('.envs' + '/**/*')
|
||||||
|
|
||||||
append_to_gitignore_file(envs_dir_path + '/**/*')
|
local_postgres_envs_path = os.path.join(PROJECT_DIR_PATH, '.envs', '.local', '.postgres')
|
||||||
|
|
||||||
local_postgres_envs_path = os.path.join(PROJECT_DIR_PATH, envs_dir_path, '.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)
|
||||||
|
|
||||||
production_django_envs_path = os.path.join(PROJECT_DIR_PATH, envs_dir_path, '.production', '.django')
|
production_django_envs_path = os.path.join(PROJECT_DIR_PATH, '.envs', '.production', '.django')
|
||||||
set_django_secret_key(production_django_envs_path)
|
set_django_secret_key(production_django_envs_path)
|
||||||
set_django_admin_url(production_django_envs_path)
|
set_django_admin_url(production_django_envs_path)
|
||||||
|
|
||||||
production_postgres_envs_path = os.path.join(PROJECT_DIR_PATH, envs_dir_path, '.production', '.postgres')
|
production_postgres_envs_path = os.path.join(PROJECT_DIR_PATH, '.envs', '.production', '.postgres')
|
||||||
set_postgres_user(production_postgres_envs_path, value=postgres_user)
|
set_postgres_user(production_postgres_envs_path, value=postgres_user)
|
||||||
set_postgres_password(production_postgres_envs_path)
|
set_postgres_password(production_postgres_envs_path)
|
||||||
|
|
||||||
|
|
||||||
def initialize_settings_files():
|
def set_flags_in_settings_files():
|
||||||
set_django_secret_key(os.path.join(PROJECT_DIR_PATH, 'config', 'settings', 'local.py'))
|
set_django_secret_key(os.path.join(PROJECT_DIR_PATH, 'config', 'settings', 'local.py'))
|
||||||
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 main():
|
def main():
|
||||||
postgres_user = generate_postgres_user()
|
postgres_user = generate_postgres_user()
|
||||||
initialize_envs(postgres_user)
|
set_flags_in_envs(postgres_user)
|
||||||
initialize_settings_files()
|
set_flags_in_settings_files()
|
||||||
|
|
||||||
if '{{ cookiecutter.open_source_license }}' == 'Not open source':
|
if '{{ cookiecutter.open_source_license }}' == 'Not open source':
|
||||||
remove_open_source_project_only_files()
|
remove_open_source_project_only_files()
|
||||||
|
@ -293,6 +291,9 @@ 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':
|
||||||
|
append_to_gitignore_file('!.envs/.local/')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user