├── .gitattributes ├── {{ cookiecutter.repo_name }} ├── data │ └── .gitkeep ├── tests │ └── .gitkeep ├── figures │ └── .gitkeep ├── notebooks │ └── .gitkeep ├── {{ cookiecutter.python_module_name }} │ └── __init__.py ├── tox.ini ├── environment.yml ├── setup.py ├── .gitignore ├── README.md ├── LICENSE └── Makefile ├── requirements.txt ├── .gitignore ├── cookiecutter.json ├── README.md ├── LICENSE └── tests └── test_creation.py /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /{{ cookiecutter.repo_name }}/data/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /{{ cookiecutter.repo_name }}/tests/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | cookiecutter 2 | pytest 3 | -------------------------------------------------------------------------------- /{{ cookiecutter.repo_name }}/figures/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /{{ cookiecutter.repo_name }}/notebooks/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | docs/site/ 2 | 3 | # OSX Junk 4 | .DS_Store 5 | -------------------------------------------------------------------------------- /{{ cookiecutter.repo_name }}/{{ cookiecutter.python_module_name }}/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /{{ cookiecutter.repo_name }}/tox.ini: -------------------------------------------------------------------------------- 1 | [flake8] 2 | max-line-length = 79 3 | max-complexity = 10 4 | -------------------------------------------------------------------------------- /{{ cookiecutter.repo_name }}/environment.yml: -------------------------------------------------------------------------------- 1 | name: {{ cookiecutter.conda_environment }} 2 | dependencies: 3 | - python={{cookiecutter.python_version}} -------------------------------------------------------------------------------- /cookiecutter.json: -------------------------------------------------------------------------------- 1 | { 2 | "project_name": "project_name", 3 | "repo_name": "{{ cookiecutter.project_name.lower().replace(' ', '_') }}", 4 | "python_module_name": "{{ cookiecutter.repo_name }}", 5 | "author_name": "Your name (or your organization/company/team)", 6 | "description": "A short description of the project.", 7 | "open_source_license": [ "MIT", "BSD", "Not open source" ], 8 | "conda_environment": "{{ cookiecutter.repo_name }}", 9 | "python_version": "Python interpreter (e.g. 3, 3.5, 2.7)" 10 | } 11 | -------------------------------------------------------------------------------- /{{ cookiecutter.repo_name }}/setup.py: -------------------------------------------------------------------------------- 1 | import os 2 | from setuptools import setup, find_packages 3 | 4 | 5 | def read(fname): 6 | return open(os.path.join(os.path.dirname(__file__), fname)).read() 7 | 8 | 9 | setup( 10 | name="{{ cookiecutter.python_module_name }}", 11 | 12 | description="{{ cookiecutter.description }}", 13 | 14 | author="{{ cookiecutter.author_name }}", 15 | 16 | packages=find_packages(exclude=['data', 'figures', 'output', 'notebooks']), 17 | 18 | long_description=read('README.md'), 19 | ) 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cookiecutter Data Science for Python 2 | 3 | A minimal _Python_ project structure for doing and sharing data science work. 4 | 5 | This cookiecutter is based on [Cookiecutter Data Science](http://drivendata.github.io/cookiecutter-data-science/). 6 | 7 | 8 | ### Requirements to use the cookiecutter template: 9 | ----------- 10 | - Python 2.7 or 3.5 11 | - [Cookiecutter Python package](http://cookiecutter.readthedocs.org/en/latest/installation.html) >= 1.4.0: This can be installed with pip by or conda depending on how you manage your Python packages: 12 | 13 | ``` bash 14 | $ pip install cookiecutter 15 | ``` 16 | 17 | or 18 | 19 | ``` bash 20 | $ conda config --add channels conda-forge 21 | $ conda install cookiecutter 22 | ``` 23 | 24 | 25 | ### To start a new project, run: 26 | ------------ 27 | 28 | ```bash 29 | $ cookiecutter https://github.com/hgrif/cookiecutter-ds-python 30 | ``` 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2016 DrivenData, Inc. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 5 | 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 9 | -------------------------------------------------------------------------------- /{{ cookiecutter.repo_name }}/.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *,cover 47 | .hypothesis/ 48 | 49 | # Translations 50 | *.mo 51 | *.pot 52 | 53 | # Django stuff: 54 | *.log 55 | local_settings.py 56 | 57 | # Flask stuff: 58 | instance/ 59 | .webassets-cache 60 | 61 | # Scrapy stuff: 62 | .scrapy 63 | 64 | # Sphinx documentation 65 | docs/_build/ 66 | 67 | # PyBuilder 68 | target/ 69 | 70 | # Jupyter Notebook 71 | .ipynb_checkpoints 72 | 73 | # pyenv 74 | .python-version 75 | 76 | # celery beat schedule file 77 | celerybeat-schedule 78 | 79 | # dotenv 80 | .env 81 | 82 | # virtualenv 83 | .venv 84 | venv/ 85 | ENV/ 86 | 87 | # Spyder project settings 88 | .spyderproject 89 | 90 | # Rope project settings 91 | .ropeproject 92 | 93 | # Pycharm 94 | .idea 95 | 96 | # Cookiecutter folders 97 | /data/ 98 | /figures/ 99 | /output/ 100 | -------------------------------------------------------------------------------- /{{ cookiecutter.repo_name }}/README.md: -------------------------------------------------------------------------------- 1 | {{cookiecutter.project_name}} 2 | ============================== 3 | 4 | {{cookiecutter.description}} 5 | 6 | Project Organization 7 | ------------ 8 | 9 | │ 10 | ├── data/ <- The original, immutable data dump. 11 | │ 12 | ├── figures/ <- Figures saved by scripts or notebooks. 13 | │ 14 | ├── notebooks/ <- Jupyter notebooks. Naming convention is a short `-` delimited 15 | │ description, a number (for ordering), and the creator's initials, 16 | │ e.g. `initial-data-exploration-01-hg`. 17 | │ 18 | ├── output/ <- Manipulated data, logs, etc. 19 | │ 20 | ├── tests/ <- Unit tests. 21 | │ 22 | ├── {{ cookiecutter.python_module_name }}/ <- Python module with source code of this project. 23 | │ 24 | ├── environment.yml <- conda virtual environment definition file. 25 | │ 26 | ├── LICENSE 27 | │ 28 | ├── Makefile <- Makefile with commands like `make environment` 29 | │ 30 | ├── README.md <- The top-level README for developers using this project. 31 | │ 32 | └── tox.ini <- tox file with settings for running tox; see tox.testrun.org 33 | 34 | 35 | -------- 36 | 37 |

Project based on the cookiecutter data science project template.

38 | 39 | 40 | Set up 41 | ------------ 42 | 43 | Install the virtual environment with conda and activate it: 44 | 45 | ```bash 46 | $ conda env create -f environment.yml 47 | $ conda activate example-project 48 | ``` 49 | 50 | Install `{{ cookiecutter.python_module_name }}` in the virtual environment: 51 | 52 | ```bash 53 | $ pip install --editable . 54 | ``` 55 | -------------------------------------------------------------------------------- /{{ cookiecutter.repo_name }}/LICENSE: -------------------------------------------------------------------------------- 1 | {% if cookiecutter.open_source_license == 'MIT' %} 2 | The MIT License (MIT) 3 | Copyright (c) {% now 'utc', '%Y' %}, {{ cookiecutter.author_name }} 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | {% elif cookiecutter.open_source_license == 'BSD' %} 11 | Copyright (c) {% now 'utc', '%Y' %}, {{ cookiecutter.author_name }} 12 | All rights reserved. 13 | 14 | Redistribution and use in source and binary forms, with or without modification, 15 | are permitted provided that the following conditions are met: 16 | 17 | * Redistributions of source code must retain the above copyright notice, this 18 | list of conditions and the following disclaimer. 19 | 20 | * Redistributions in binary form must reproduce the above copyright notice, this 21 | list of conditions and the following disclaimer in the documentation and/or 22 | other materials provided with the distribution. 23 | 24 | * Neither the name of {{ cookiecutter.project_name }} nor the names of its 25 | contributors may be used to endorse or promote products derived from this 26 | software without specific prior written permission. 27 | 28 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 29 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 30 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 31 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 32 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 34 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 35 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 36 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 37 | OF THE POSSIBILITY OF SUCH DAMAGE. 38 | {% endif %} 39 | -------------------------------------------------------------------------------- /{{ cookiecutter.repo_name }}/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: create_environment git 2 | 3 | ################################################################################# 4 | # GLOBALS # 5 | ################################################################################# 6 | 7 | PROJECT_NAME = {{ cookiecutter.repo_name }} 8 | CONDA_ENVIRONMENT = {{ cookiecutter.conda_environment }} 9 | PYTHON_VERSION = {{ cookiecutter.python_version }} 10 | 11 | ################################################################################# 12 | # COMMANDS # 13 | ################################################################################# 14 | 15 | ## Set up python interpreter environment 16 | environment: 17 | conda env create -f environment.yml 18 | 19 | git: 20 | git init 21 | 22 | 23 | ################################################################################# 24 | # Self Documenting Commands # 25 | ################################################################################# 26 | 27 | .DEFAULT_GOAL := show-help 28 | 29 | # Inspired by 30 | # sed script explained: 31 | # /^##/: 32 | # * save line in hold space 33 | # * purge line 34 | # * Loop: 35 | # * append newline + line to hold space 36 | # * go to next line 37 | # * if line starts with doc comment, strip comment character off and loop 38 | # * remove target prerequisites 39 | # * append hold space (+ newline) to line 40 | # * replace newline plus comments by `---` 41 | # * print line 42 | # Separate expressions are necessary because labels cannot be delimited by 43 | # semicolon; see 44 | .PHONY: show-help 45 | show-help: 46 | @echo "$$(tput bold)Available rules:$$(tput sgr0)" 47 | @echo 48 | @sed -n -e "/^## / { \ 49 | h; \ 50 | s/.*//; \ 51 | :doc" \ 52 | -e "H; \ 53 | n; \ 54 | s/^## //; \ 55 | t doc" \ 56 | -e "s/:.*//; \ 57 | G; \ 58 | s/\\n## /---/; \ 59 | s/\\n/ /g; \ 60 | p; \ 61 | }" ${MAKEFILE_LIST} \ 62 | | LC_ALL='C' sort --ignore-case \ 63 | | awk -F '---' \ 64 | -v ncol=$$(tput cols) \ 65 | -v indent=19 \ 66 | -v col_on="$$(tput setaf 6)" \ 67 | -v col_off="$$(tput sgr0)" \ 68 | '{ \ 69 | printf "%s%*s%s ", col_on, -indent, $$1, col_off; \ 70 | n = split($$2, words, " "); \ 71 | line_length = ncol - indent; \ 72 | for (i = 1; i <= n; i++) { \ 73 | line_length -= length(words[i]) + 1; \ 74 | if (line_length <= 0) { \ 75 | line_length = ncol - indent - length(words[i]) - 1; \ 76 | printf "\n%*s ", -indent, " "; \ 77 | } \ 78 | printf "%s ", words[i]; \ 79 | } \ 80 | printf "\n"; \ 81 | }' \ 82 | | more $(shell test $(shell uname) == Darwin && echo '--no-init --raw-control-chars') 83 | -------------------------------------------------------------------------------- /tests/test_creation.py: -------------------------------------------------------------------------------- 1 | import os 2 | import shutil 3 | 4 | from cookiecutter import main 5 | import pytest 6 | 7 | CCDS_ROOT = os.path.abspath( 8 | os.path.join( 9 | __file__, 10 | os.pardir, 11 | os.pardir 12 | ) 13 | ) 14 | 15 | 16 | @pytest.fixture(scope='function') 17 | def default_baked_project(tmpdir): 18 | out_dir = str(tmpdir.mkdir('data-project')) 19 | 20 | main.cookiecutter( 21 | CCDS_ROOT, 22 | no_input=True, 23 | extra_context={}, 24 | output_dir=out_dir 25 | ) 26 | 27 | # default project name is project_name 28 | yield os.path.join(out_dir, 'project_name') 29 | 30 | # cleanup after 31 | shutil.rmtree(out_dir) 32 | 33 | 34 | def test_readme(default_baked_project): 35 | readme_path = os.path.join(default_baked_project, 'README.md') 36 | 37 | assert os.path.exists(readme_path) 38 | assert no_curlies(readme_path) 39 | 40 | 41 | def test_license(default_baked_project): 42 | license_path = os.path.join(default_baked_project, 'LICENSE') 43 | 44 | assert os.path.exists(license_path) 45 | assert no_curlies(license_path) 46 | 47 | 48 | def test_requirements(default_baked_project): 49 | reqs_path = os.path.join(default_baked_project, 'environment.yml') 50 | 51 | assert os.path.exists(reqs_path) 52 | assert no_curlies(reqs_path) 53 | 54 | 55 | def test_makefile(default_baked_project): 56 | makefile_path = os.path.join(default_baked_project, 'Makefile') 57 | 58 | assert os.path.exists(makefile_path) 59 | assert no_curlies(makefile_path) 60 | 61 | 62 | def test_setup(default_baked_project): 63 | makefile_path = os.path.join(default_baked_project, 'setup.py') 64 | 65 | assert os.path.exists(makefile_path) 66 | assert no_curlies(makefile_path) 67 | 68 | 69 | def test_folders(default_baked_project): 70 | expected_dirs = [ 71 | 'data', 72 | 'figures', 73 | 'notebooks', 74 | 'output', 75 | 'tests', 76 | 'project_name', 77 | ] 78 | 79 | ignored_dirs = [ 80 | default_baked_project, 81 | os.path.join(default_baked_project, '__pycache__') 82 | ] 83 | 84 | abs_expected_dirs = [os.path.join(default_baked_project, d) for 85 | d in expected_dirs] 86 | 87 | abs_dirs, _, _ = list(zip(*os.walk(default_baked_project))) 88 | 89 | assert len(set(abs_expected_dirs + ignored_dirs) - set(abs_dirs)) == 0 90 | 91 | 92 | def no_curlies(filepath): 93 | """ Utility to make sure no curly braces appear in a file. 94 | That is, was jinja able to render everthing? 95 | """ 96 | with open(filepath, 'r') as f: 97 | data = f.read() 98 | 99 | template_strings = [ 100 | '{{', 101 | '}}', 102 | '{%', 103 | '%}' 104 | ] 105 | 106 | template_strings_in_file = [s in data for s in template_strings] 107 | 108 | return not any(template_strings_in_file) 109 | --------------------------------------------------------------------------------