diff --git a/.dockerignore b/.dockerignore index 0842790..61f7fab 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,3 @@ venv/**/* venv -tmp \ No newline at end of file +tmp diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..e0ea542 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,3 @@ +[flake8] +max-line-length = 88 +extend-ignore = E203 \ No newline at end of file diff --git a/src/kedro_dvc/create_sample_project.py b/src/kedro_dvc/create_sample_project.py new file mode 100644 index 0000000..2a3d5ae --- /dev/null +++ b/src/kedro_dvc/create_sample_project.py @@ -0,0 +1,44 @@ +import os +import subprocess +import sys + + +def create_sample_project( + name: str, from_branch: str = "sample-project-basic" +): # type: ignore + if name == "": + print("usage: python3.8 setup_sample_project.py [from_branch]") + return + + print("creating sample project $name from branch $from_branch") + + os.makedirs(f"tmp/{name}") + os.chdir(f"tmp/{name}") + subprocess.check_call( + [ + "git", + "clone", + "https://github.com/FactFiber/kedro-dvc.git", + "-b", + from_branch, + ".", + ] + ) + # using virtualenv.create_environment no longer works + subprocess.check_call(["virtualenv", f"env/{name}"]) + activate_this_file = "env/test/bin/activate_this.py" + exec( + compile( + open(activate_this_file, "rb").read(), activate_this_file, "exec" + ), + dict(__file__=activate_this_file), + ) + subprocess.check_call(["pip", "install", "--upgrade", "pip"]) + subprocess.check_call(["pip", "install", "-r", "src/requirements.txt"]) + # we should see kedro-dvc commands listed + print(subprocess.check_output(["pip", "freeze"])) + print('to use the sample project run "source env/$name/bin/activate"') + + +if __name__ == "__main__": + create_sample_project(name=sys.argv[1], from_branch=sys.argv[2]) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/conftest.py b/tests/conftest.py index e69de29..bf9157f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -0,0 +1,3 @@ +# from tests.fixtures import * # noqa + +# pytest_plugins = ["fixtures"] diff --git a/tests/test_create-sample-project.py b/tests/test_create-sample-project.py new file mode 100644 index 0000000..9303b53 --- /dev/null +++ b/tests/test_create-sample-project.py @@ -0,0 +1,48 @@ +import os +import subprocess + +import pytest + +from src.kedro_dvc.create_sample_project import create_sample_project + + +def test_create_sample_project_success(): + prev_dir: str = os.getcwd() + name: str = "test" + from_branch: str = "sample-project-basic" + + create_sample_project(name, from_branch) + + current_dir: str = os.getcwd() + dirs = [d for d in os.listdir() if not os.path.isfile(d)] + # pip.utils.get_installed_distributions() no longer exists + freeze = subprocess.check_output(["pip", "freeze"]) + pip_modules = [ + i[i.find("\\n") + 2 :] for i in ("\\n" + str(freeze)[2:]).split("==") + ][:-1] + + assert prev_dir != current_dir + assert current_dir.endswith(f"tmp/{name}") + assert "env" in dirs + assert "src" in dirs + print(pip_modules) + assert "wcwidth" in pip_modules + + +def test_create_sample_project_no_name(): + prev_dir: str = os.getcwd() + name: str = "" + from_branch: str = "sample-project-basic" + + create_sample_project(name, from_branch) + + current_dir: str = os.getcwd() + + assert prev_dir == current_dir + + +def test_create_sample_project_nonexistant_branch(): + name: str = "test" + from_branch: str = "nonexistant-branch" + with pytest.raises(Exception): + create_sample_project(name, from_branch) diff --git a/tests/test_fixtures.py b/tests/test_fixtures.py new file mode 100644 index 0000000..0b148f9 --- /dev/null +++ b/tests/test_fixtures.py @@ -0,0 +1,2 @@ +# check info function of returned structs of each fixture +# test correct working directory