mirror of
https://github.com/wassname/cookiecutter-data-science.git
synced 2026-06-27 20:21:10 +08:00
1fe968d24e
* WIP - New version with cleaner options * Fix find-replace error (#177) * Remove unnecessary .gitkeep * Remove unused tox.ini * Split reqs into dev/non-dev * Add basic packages support * Add tests for testing environment creation and requirements * Set up CI with Azure Pipelines (#194) * Change archived asciinema example (#163) * Change archived asciinema example * Update README.md Fix Asciinema powerline error * Update docs to show updated asciinema example * Added source and destination to Make data target (#169) * Fix broken Airflow link (#182) * Fixed: Typo in Makefile (#184) Fixed typo in Makefile, section "Set up python interpreter environment": intalled --> installed * Set up CI with Azure Pipelines [skip ci] * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * str paths for windows support * handle multiple data providers (#199) * Add missing env directory bin/activate path * Remove version from PYTHON_INTERPRETER command * Search for virtualenvwrapper.sh path if executable not found * Try chardet for character encoding detection * Specify python and virtualenv binaries for virtualenvwrapper * Add shebang to virtualenvwrapper.sh * Diagnostic * Try virtualenvwrapper-win * Set encoding if detected None * Fixes to Mac and Windows tests on Azure pipelines (#217) * Temporarily comment out py36 * Update azure-pipelines.yml * Fix tests on Windows and Mac (#1) * Temporarily remove py37 * Update virtualenv_harness.sh * put py37 back in * Set encoding to utf-8 * Comment out rmvirtualenv * Update test_creation.py * Update virtualenv_harness.sh * Add --show-capture * Update azure-pipelines.yml * Update azure-pipelines.yml * Update test_creation.py * Update virtualenv_harness.sh * Update virtualenv_harness.sh * Update virtualenv_harness.sh * Update virtualenv_harness.sh * Update Makefile * Update virtualenv_harness.sh * Update cookiecutter.json * Update cookiecutter.json * Update virtualenv_harness.sh * Update Makefile * Update Makefile * Update Makefile * Update virtualenv_harness.sh * Update virtualenv_harness.sh * Update virtualenv_harness.sh * Update virtualenv_harness.sh * Update virtualenv_harness.sh * Update virtualenv_harness.sh * Update virtualenv_harness.sh * Update virtualenv_harness.sh * Update Makefile * Update Makefile * Update Makefile * Update Makefile * Update virtualenv_harness.sh * Update virtualenv_harness.sh * Update virtualenv_harness.sh * Update Makefile * Update Makefile * Update virtualenv_harness.sh * Update Makefile * Update virtualenv_harness.sh * Update virtualenv_harness.sh * Update test_creation.py * Update azure-pipelines.yml * Update virtualenv_harness.sh * Update virtualenv_harness.sh * Update virtualenv_harness.sh * Update virtualenv_harness.sh * Update cookiecutter.json * Update conda_harness.sh * Update conda_harness.sh * Update conda_harness.sh Co-authored-by: Eric Jalbert <ericmjalbert@users.noreply.github.com> Co-authored-by: Jonathan Raviotta <jraviotta@users.noreply.github.com> Co-authored-by: Wes Roach <wesr000@gmail.com> Co-authored-by: Christopher Geis <16896724+geisch@users.noreply.github.com> Co-authored-by: Peter Bull <pjbull@gmail.com> Co-authored-by: Ian Preston <17241371+ianepreston@users.noreply.github.com> Co-authored-by: Jay Qi <jayqi@users.noreply.github.com> Co-authored-by: inchiosa <4316698+inchiosa@users.noreply.github.com> * More graceful deprecation * Make tests pass locally * test version match installed version * Remove unused imports * Unremove used import * Move to GH Actions * Fix typo * Test non-windows * Add netlify configs * Update suggestion to keep using deprecated cookiecutter template (#231) * Add mkdocs requirements file to docs directory * Try setting python version in runtime txt for netlify * Trigger build * Python 3.8 netlify * Python 3.6 netlify * Do not specify python runtime for netlify * Use 3.7 This reverts commit 898d7d3cf6008e47e89ed607167fad7aee1e065e. Co-authored-by: James Myatt <james@jamesmyatt.co.uk> Co-authored-by: drivendata <info@drivendata.org> Co-authored-by: Eric Jalbert <ericmjalbert@users.noreply.github.com> Co-authored-by: Jonathan Raviotta <jraviotta@users.noreply.github.com> Co-authored-by: Wes Roach <wesr000@gmail.com> Co-authored-by: Christopher Geis <16896724+geisch@users.noreply.github.com> Co-authored-by: Ian Preston <17241371+ianepreston@users.noreply.github.com> Co-authored-by: Jay Qi <jayqi@users.noreply.github.com> Co-authored-by: inchiosa <4316698+inchiosa@users.noreply.github.com> Co-authored-by: Robert Gibboni <robert@drivendata.org>
162 lines
4.8 KiB
Python
162 lines
4.8 KiB
Python
from pathlib import Path
|
|
from subprocess import run, PIPE
|
|
|
|
import pytest
|
|
import chardet
|
|
|
|
from conftest import bake_project, config_generator
|
|
|
|
|
|
def no_curlies(filepath):
|
|
""" Utility to make sure no curly braces appear in a file.
|
|
That is, was Jinja able to render everything?
|
|
"""
|
|
data = filepath.open('r').read()
|
|
|
|
template_strings = [
|
|
'{{',
|
|
'}}',
|
|
'{%',
|
|
'%}'
|
|
]
|
|
|
|
template_strings_in_file = [s in data for s in template_strings]
|
|
return not any(template_strings_in_file)
|
|
|
|
|
|
@pytest.mark.parametrize("config", config_generator())
|
|
def test_baking_configs(config):
|
|
""" For every generated config in the config_generator, run all
|
|
of the tests.
|
|
"""
|
|
print("using config", config)
|
|
with bake_project(config) as project_directory:
|
|
verify_folders(project_directory, config)
|
|
verify_files(project_directory, config)
|
|
verify_makefile_commands(project_directory, config)
|
|
|
|
|
|
def verify_folders(root, config):
|
|
''' Tests that expected folders and only expected folders exist.
|
|
'''
|
|
expected_dirs = [
|
|
'.',
|
|
'data',
|
|
'data/external',
|
|
'data/interim',
|
|
'data/processed',
|
|
'data/raw',
|
|
'docs',
|
|
'models',
|
|
'notebooks',
|
|
'references',
|
|
'reports',
|
|
'reports/figures',
|
|
config['module_name'],
|
|
f"{config['module_name']}/data",
|
|
f"{config['module_name']}/features",
|
|
f"{config['module_name']}/models",
|
|
f"{config['module_name']}/visualization",
|
|
]
|
|
|
|
expected_dirs = [
|
|
# (root / d).resolve().relative_to(root) for d in expected_dirs
|
|
Path(d) for d in expected_dirs
|
|
]
|
|
|
|
existing_dirs = [
|
|
d.resolve().relative_to(root) for d in root.glob('**') if d.is_dir()
|
|
]
|
|
|
|
assert sorted(existing_dirs) == sorted(expected_dirs)
|
|
|
|
|
|
def verify_files(root, config):
|
|
''' Test that expected files and only expected files exist.
|
|
'''
|
|
expected_files = [
|
|
'Makefile',
|
|
'README.md',
|
|
'setup.py',
|
|
".env",
|
|
".gitignore",
|
|
"data/external/.gitkeep",
|
|
"data/interim/.gitkeep",
|
|
"data/processed/.gitkeep",
|
|
"data/raw/.gitkeep",
|
|
"docs/Makefile",
|
|
"docs/commands.rst",
|
|
"docs/conf.py",
|
|
"docs/getting-started.rst",
|
|
"docs/index.rst",
|
|
"docs/make.bat",
|
|
"notebooks/.gitkeep",
|
|
"references/.gitkeep",
|
|
"reports/.gitkeep",
|
|
"reports/figures/.gitkeep",
|
|
"models/.gitkeep",
|
|
f"{config['module_name']}/__init__.py",
|
|
f"{config['module_name']}/data/__init__.py",
|
|
f"{config['module_name']}/data/make_dataset.py",
|
|
f"{config['module_name']}/features/__init__.py",
|
|
f"{config['module_name']}/features/build_features.py",
|
|
f"{config['module_name']}/models/__init__.py",
|
|
f"{config['module_name']}/models/train_model.py",
|
|
f"{config['module_name']}/models/predict_model.py",
|
|
f"{config['module_name']}/visualization/__init__.py",
|
|
f"{config['module_name']}/visualization/visualize.py",
|
|
]
|
|
|
|
# conditional files
|
|
if not config["open_source_license"].startswith("No license"):
|
|
expected_files.append('LICENSE')
|
|
|
|
expected_files.append(config["dependency_file"])
|
|
|
|
expected_files = [
|
|
Path(f) for f in expected_files
|
|
]
|
|
|
|
existing_files = [
|
|
f.relative_to(root) for f in root.glob('**/*') if f.is_file()
|
|
]
|
|
|
|
assert sorted(existing_files) == sorted(expected_files)
|
|
|
|
for f in existing_files:
|
|
assert no_curlies(root / f)
|
|
|
|
|
|
def verify_makefile_commands(root, config):
|
|
""" Actually shell out to bash and run the make commands for:
|
|
- create_environment
|
|
- requirements
|
|
Ensure that these use the proper environment.
|
|
"""
|
|
test_path = Path(__file__).parent
|
|
|
|
if config["environment_manager"] == 'conda':
|
|
harness_path = test_path / "conda_harness.sh"
|
|
elif config["environment_manager"] == 'virtualenv':
|
|
harness_path = test_path / "virtualenv_harness.sh"
|
|
elif config["environment_manager"] == 'pipenv':
|
|
|
|
harness_path = test_path / "pipenv_harness.sh"
|
|
elif config["environment_manager"] == 'none':
|
|
return True
|
|
else:
|
|
raise ValueError(f"Environment manager '{config['environment_manager']}' not found in test harnesses.")
|
|
|
|
result = run(["bash", str(harness_path), str(root.resolve())], stderr=PIPE, stdout=PIPE)
|
|
result_returncode = result.returncode
|
|
|
|
encoding = chardet.detect(result.stdout)["encoding"]
|
|
if encoding is None:
|
|
encoding = "utf-8"
|
|
|
|
# normally hidden by pytest except in failure we want this displayed
|
|
print("\n======================= STDOUT ======================")
|
|
|
|
print("\n======================= STDERR ======================")
|
|
assert result_returncode == 0
|