mirror of
https://github.com/wassname/cookiecutter-data-science.git
synced 2026-06-27 15:15:12 +08:00
tidy
This commit is contained in:
@@ -1,47 +0,0 @@
|
||||
import sys
|
||||
import pytest
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
from cookiecutter import main
|
||||
|
||||
CCDS_ROOT = Path(__file__).parents[1].resolve()
|
||||
|
||||
args = {
|
||||
'project_name': 'DrivenData',
|
||||
'author_name': 'DrivenData',
|
||||
'open_source_license': 'BSD-3-Clause',
|
||||
'python_interpreter': 'python'
|
||||
}
|
||||
|
||||
|
||||
def system_check(basename):
|
||||
platform = sys.platform
|
||||
if 'linux' in platform:
|
||||
basename = basename.lower()
|
||||
return basename
|
||||
|
||||
|
||||
@pytest.fixture(scope='class', params=[{}, args])
|
||||
def default_baked_project(tmpdir_factory, request):
|
||||
temp = tmpdir_factory.mktemp('data-project')
|
||||
out_dir = Path(temp).resolve()
|
||||
|
||||
pytest.param = request.param
|
||||
main.cookiecutter(
|
||||
str(CCDS_ROOT),
|
||||
no_input=True,
|
||||
extra_context=pytest.param,
|
||||
output_dir=out_dir
|
||||
)
|
||||
|
||||
pn = pytest.param.get('project_name') or 'project_name'
|
||||
|
||||
# project name gets converted to lower case on Linux but not Mac
|
||||
pn = system_check(pn)
|
||||
|
||||
proj = out_dir / pn
|
||||
request.cls.path = proj
|
||||
yield
|
||||
|
||||
# cleanup after
|
||||
shutil.rmtree(out_dir)
|
||||
@@ -1,119 +0,0 @@
|
||||
import os
|
||||
import pytest
|
||||
from subprocess import check_output
|
||||
from conftest import system_check
|
||||
|
||||
|
||||
def no_curlies(filepath):
|
||||
""" Utility to make sure no curly braces appear in a file.
|
||||
That is, was Jinja able to render everything?
|
||||
"""
|
||||
with open(filepath, 'r') as f:
|
||||
data = f.read()
|
||||
|
||||
template_strings = [
|
||||
'{{',
|
||||
'}}',
|
||||
'{%',
|
||||
'%}'
|
||||
]
|
||||
|
||||
template_strings_in_file = [s in data for s in template_strings]
|
||||
return not any(template_strings_in_file)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("default_baked_project")
|
||||
class TestCookieSetup(object):
|
||||
def test_project_name(self):
|
||||
project = self.path
|
||||
if pytest.param.get('project_name'):
|
||||
name = system_check('DrivenData')
|
||||
assert project.name == name
|
||||
else:
|
||||
assert project.name == 'project_name'
|
||||
|
||||
def test_author(self):
|
||||
setup_ = self.path / 'setup.py'
|
||||
args = ['python', str(setup_), '--author']
|
||||
p = check_output(args).decode('ascii').strip()
|
||||
if pytest.param.get('author_name'):
|
||||
assert p == 'DrivenData'
|
||||
else:
|
||||
assert p == 'Your name (or your organization/company/team)'
|
||||
|
||||
def test_readme(self):
|
||||
readme_path = self.path / 'README.md'
|
||||
assert readme_path.exists()
|
||||
assert no_curlies(readme_path)
|
||||
# if pytest.param.get('project_name'):
|
||||
# with open(readme_path) as fin:
|
||||
# assert 'DrivenData' == next(fin).strip()
|
||||
|
||||
def test_setup(self):
|
||||
setup_ = self.path / 'setup.py'
|
||||
args = ['python', str(setup_), '--version']
|
||||
p = check_output(args).decode('ascii').strip()
|
||||
assert p == '0.1.0'
|
||||
|
||||
# def test_license(self):
|
||||
# license_path = self.path / 'LICENSE'
|
||||
# assert license_path.exists()
|
||||
# assert no_curlies(license_path)
|
||||
|
||||
# def test_license_type(self):
|
||||
# setup_ = self.path / 'setup.py'
|
||||
# args = ['python', str(setup_), '--license']
|
||||
# p = check_output(args).decode('ascii').strip()
|
||||
# if pytest.param.get('open_source_license'):
|
||||
# assert p == 'BSD-3'
|
||||
# else:
|
||||
# assert p == 'MIT'
|
||||
|
||||
def test_requirements(self):
|
||||
reqs_path = self.path / 'requirements'/ 'environment.yaml'
|
||||
assert reqs_path.exists()
|
||||
assert no_curlies(reqs_path)
|
||||
# if pytest.param.get('python_interpreter'):
|
||||
# with open(reqs_path) as fin:
|
||||
# lines = list(map(lambda x: x.strip(), fin.readlines()))
|
||||
# assert 'pathlib2' in lines
|
||||
|
||||
def test_makefile(self):
|
||||
makefile_path = self.path / 'Makefile'
|
||||
assert makefile_path.exists()
|
||||
assert no_curlies(makefile_path)
|
||||
|
||||
def test_folders(self):
|
||||
expected_dirs = [
|
||||
'data',
|
||||
# 'data/external',
|
||||
'data/interim',
|
||||
'data/processed',
|
||||
'data/raw',
|
||||
# 'docs',
|
||||
'outputs',
|
||||
'notebooks',
|
||||
# 'references',
|
||||
# 'reports',
|
||||
# 'reports/figures',
|
||||
'drivendata',
|
||||
'drivendata/data',
|
||||
'drivendata/features',
|
||||
'drivendata/models',
|
||||
'drivendata/visualization',
|
||||
]
|
||||
|
||||
ignored_dirs = [
|
||||
str(self.path)
|
||||
]
|
||||
|
||||
abs_expected_dirs = [str(self.path / d) for d in expected_dirs]
|
||||
abs_dirs, _, _ = list(zip(*os.walk(self.path)))
|
||||
# if pytest.param.get('project_name'):
|
||||
# print('proj', pytest.param.get('project_name', 'project_name'))
|
||||
# print(abs_dirs)
|
||||
# print(set(abs_expected_dirs + ignored_dirs))
|
||||
# 1/0
|
||||
# print(set(abs_expected_dirs + ignored_dirs) - set(abs_dirs))
|
||||
assert len(set(abs_expected_dirs + ignored_dirs) - set(abs_dirs)) == 0
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
|
||||
# exclude data from source control by default
|
||||
/data/
|
||||
/outputs/
|
||||
|
||||
# DotEnv configuration
|
||||
.env
|
||||
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
@@ -56,9 +64,6 @@ docs/_build/
|
||||
# PyBuilder
|
||||
target/
|
||||
|
||||
# DotEnv configuration
|
||||
.env
|
||||
|
||||
# Database
|
||||
*.db
|
||||
*.rdb
|
||||
@@ -75,9 +80,6 @@ target/
|
||||
# Jupyter NB Checkpoints
|
||||
.ipynb_checkpoints/
|
||||
|
||||
# exclude data from source control by default
|
||||
/data/
|
||||
|
||||
# Mac OS-specific storage files
|
||||
.DS_Store
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
│ ├── 20_interim <- Intermediate data that has been transformed.
|
||||
│ └── 10_raw <- The original, immutable data dump.
|
||||
│
|
||||
│
|
||||
├── nbs <- Jupyter notebooks. Namiwith creator's initials, a number (for ordering), and short `-` delimited description, e.g.
|
||||
│ `jqp-1.0-initial-data-exploration`.
|
||||
│
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
# see https://cheatography.com/linux-china/cheat-sheets/justfile/
|
||||
|
||||
set dotenv-load
|
||||
|
||||
# Export all just variables as environment variables.
|
||||
set export
|
||||
|
||||
package := "{{cookiecutter.project_name.lower().replace(' ', '_')}}"
|
||||
|
||||
[private]
|
||||
default: @just --list
|
||||
|
||||
# put your run commands here
|
||||
app:
|
||||
echo "hello world"
|
||||
|
||||
@@ -7,7 +7,7 @@ license = "MIT"
|
||||
readme = "README.md"
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = ">=3.10,<3.13"
|
||||
python = ">=3.10"
|
||||
numpy = "^1.26.1"
|
||||
pandas = "^2.1.1"
|
||||
matplotlib = "^3.8.0"
|
||||
@@ -32,6 +32,7 @@ ipykernel = "^6.25.2"
|
||||
ruff = "^0.1.3"
|
||||
|
||||
[[tool.poetry.source]]
|
||||
# pytorch cuda needs to compe from another source https://python-poetry.org/docs/dependency-specification/#source-dependencies
|
||||
name = "pytorch"
|
||||
url = "https://download.pytorch.org/whl/cu124"
|
||||
priority = "explicit"
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
# 2024-06-09 16:05:45
|
||||
|
||||
Started project using cookiecutter data science project template.
|
||||
Reference in New Issue
Block a user