From d13bc88ab0398195db466f99e2f58e31f1e241fb Mon Sep 17 00:00:00 2001 From: Colin Sullivan Date: Wed, 5 Oct 2016 15:16:42 -0400 Subject: [PATCH] add parameter to specify python interpreter and commands to create and test virtual environments --- cookiecutter.json | 3 ++- {{ cookiecutter.repo_name }}/Makefile | 13 +++++++++- .../test_environment.py | 24 +++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 {{ cookiecutter.repo_name }}/test_environment.py diff --git a/cookiecutter.json b/cookiecutter.json index 22302ac..cf3ad39 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -5,5 +5,6 @@ "description": "A short description of the project.", "year": "2016", "open_source_license": ["MIT", "BSD", "Not open source"], - "s3_bucket": "[OPTIONAL] your-bucket-for-syncing-data (do not include 's3://')" + "s3_bucket": "[OPTIONAL] your-bucket-for-syncing-data (do not include 's3://')", + "python_interpreter": ["python", "python3"] } diff --git a/{{ cookiecutter.repo_name }}/Makefile b/{{ cookiecutter.repo_name }}/Makefile index b99ac61..c3ef900 100644 --- a/{{ cookiecutter.repo_name }}/Makefile +++ b/{{ cookiecutter.repo_name }}/Makefile @@ -5,13 +5,15 @@ ################################################################################# BUCKET = {{ cookiecutter.s3_bucket }} +PROJECT_NAME = {{ cookiecutter.repo_name }} +PYTHON_INTERPRETER = {{ cookiecutter.python_interpreter }} ################################################################################# # COMMANDS # ################################################################################# ## Install Python Dependencies -requirements: +requirements: test_environment pip install -q -r requirements.txt ## Make Dataset @@ -34,6 +36,15 @@ sync_data_to_s3: sync_data_from_s3: aws s3 sync s3://$(BUCKET)/data/ data/ +## Set up python interpreter environment +setup_environment: + source /usr/local/bin/virtualenvwrapper.sh; mkvirtualenv $(PROJECT_NAME) --python=$(PYTHON_INTERPRETER) + @echo ">>> Activate virtualenv with:\nworkon $(PROJECT_NAME)" + +## Test python environment is setup correctly +test_environment: + python test_environment.py + ################################################################################# # PROJECT RULES # ################################################################################# diff --git a/{{ cookiecutter.repo_name }}/test_environment.py b/{{ cookiecutter.repo_name }}/test_environment.py new file mode 100644 index 0000000..ed8c3a9 --- /dev/null +++ b/{{ cookiecutter.repo_name }}/test_environment.py @@ -0,0 +1,24 @@ +import sys + +REQUIRED_PYTHON = "{{ cookiecutter.python_interpreter }}" + + +def main(): + system_major = sys.version_info.major + if REQUIRED_PYTHON == "python": + required_major = 2 + elif REQUIRED_PYTHON == "python3": + required_major = 3 + else: + raise ValueError("Unrecognized python interpreter: {}".format( + REQUIRED_PYTHON)) + + if system_major != required_major: + raise TypeError("This project requires Python {}. Found: {}".format( + required_major, sys.version)) + else: + print(">>> Development environment passes all tests!") + + +if __name__ == '__main__': + main() \ No newline at end of file