Browse Source

add parameter to specify python interpreter and commands to create and test virtual environments

main
Colin Sullivan 8 years ago
parent
commit
d13bc88ab0
  1. 3
      cookiecutter.json
  2. 13
      {{ cookiecutter.repo_name }}/Makefile
  3. 24
      {{ cookiecutter.repo_name }}/test_environment.py

3
cookiecutter.json

@ -5,5 +5,6 @@
"description": "A short description of the project.", "description": "A short description of the project.",
"year": "2016", "year": "2016",
"open_source_license": ["MIT", "BSD", "Not open source"], "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"]
} }

13
{{ cookiecutter.repo_name }}/Makefile

@ -5,13 +5,15 @@
################################################################################# #################################################################################
BUCKET = {{ cookiecutter.s3_bucket }} BUCKET = {{ cookiecutter.s3_bucket }}
PROJECT_NAME = {{ cookiecutter.repo_name }}
PYTHON_INTERPRETER = {{ cookiecutter.python_interpreter }}
################################################################################# #################################################################################
# COMMANDS # # COMMANDS #
################################################################################# #################################################################################
## Install Python Dependencies ## Install Python Dependencies
requirements: requirements: test_environment
pip install -q -r requirements.txt pip install -q -r requirements.txt
## Make Dataset ## Make Dataset
@ -34,6 +36,15 @@ sync_data_to_s3:
sync_data_from_s3: sync_data_from_s3:
aws s3 sync s3://$(BUCKET)/data/ data/ 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 # # PROJECT RULES #
################################################################################# #################################################################################

24
{{ 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()
Loading…
Cancel
Save