diff --git a/README.rst b/README.rst index c5f9d06b3..3f8245f83 100644 --- a/README.rst +++ b/README.rst @@ -192,6 +192,7 @@ Answer the prompts with your own desired options_. For example:: 4 - Apache Software License 2.0 5 - Not open source Choose from 1, 2, 3, 4, 5 [1]: 1 + keep_local_envs_in_vcs [y]: y Enter the project and take a look around:: diff --git a/cookiecutter.json b/cookiecutter.json index 27834a517..aa341801b 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -39,5 +39,6 @@ "use_opbeat": "n", "use_whitenoise": "y", "use_heroku": "n", - "use_travisci": "n" + "use_travisci": "n", + "keep_local_envs_in_vcs": "y" } diff --git a/docs/project-generation-options.rst b/docs/project-generation-options.rst index 3f7928c50..9e09f0e5d 100644 --- a/docs/project-generation-options.rst +++ b/docs/project-generation-options.rst @@ -94,6 +94,11 @@ use_heroku [n] use_travisci [n] 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 .. _BSD: https://opensource.org/licenses/BSD-3-Clause diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 7557e4987..235b337df 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -216,39 +216,37 @@ def set_postgres_password(file_path): 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: gitignore_file.write(s) gitignore_file.write(os.linesep) -def initialize_envs(postgres_user): - envs_dir_path = '.envs' +def set_flags_in_envs(postgres_user): + append_to_gitignore_file('.envs' + '/**/*') - append_to_gitignore_file(envs_dir_path + '/**/*') - - local_postgres_envs_path = os.path.join(PROJECT_DIR_PATH, envs_dir_path, '.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_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_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_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', 'test.py')) def main(): postgres_user = generate_postgres_user() - initialize_envs(postgres_user) - initialize_settings_files() + set_flags_in_envs(postgres_user) + set_flags_in_settings_files() if '{{ cookiecutter.open_source_license }}' == 'Not open source': remove_open_source_project_only_files() @@ -293,6 +291,9 @@ def main(): if '{{ cookiecutter.use_travisci }}'.lower() == 'n': remove_dottravisyml_file() + if '{{ cookiecutter.keep_local_envs_in_vcs }}'.lower() == 'y': + append_to_gitignore_file('!.envs/.local/') + if __name__ == '__main__': main()