Skip to content

Commit

Permalink
fix: install git user config in test projects, docker
Browse files Browse the repository at this point in the history
  • Loading branch information
shaunc committed May 11, 2022
1 parent 93e5c2b commit 03632c8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.8.12-slim-buster
FROM python:3.9-slim-buster

# system installs first -- unlikely to change
RUN apt-get update \
Expand All @@ -20,5 +20,7 @@ RUN poetry install && poetry update
ADD . /app
ADD ./bin/create-sample-project.sh bin/create-sample-project.sh
RUN sed -i.bak 's/\r$//' bin/create-sample-project.sh
RUN git config --global user.email "[email protected]"
RUN git config --global user.name "Dummy User"
RUN poetry exec create-sample-project example sample-project-basic
ENTRYPOINT [ "/bin/bash" ]
ENTRYPOINT [ "/bin/bash", "-c" ]
14 changes: 11 additions & 3 deletions src/kedro_dvc/create_sample_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pathlib
import shutil
import subprocess
from typing import Sequence
from typing import Callable, Sequence

import click
import virtualenv
Expand Down Expand Up @@ -30,11 +30,20 @@ class CantCheckout(KeyError):
DEFAULT_SAMPLE_BRANCH = "sample-project-basic"


def _default_initial_commit() -> None:
"""
Initial commit with sample project skeleton.
"""
subprocess.check_call(["git", "add", "."])
subprocess.check_call(["git", "commit", "-m", "chore: initial commit"])


def create_sample_project(
name: str,
from_branch: str = DEFAULT_SAMPLE_BRANCH,
kd_repo_path: str = "../..",
preserve_git: bool = False,
initial_commit_hook: Callable[[], None] = _default_initial_commit,
) -> None:
"""
Create a kedro sample project from repo branch with skeleton.
Expand Down Expand Up @@ -79,8 +88,7 @@ def create_sample_project(
new_req = f"-e {kd_repo_path}\n{new_req}"
pathlib.Path("src/requirements.txt").write_text(new_req)
subprocess.check_call(["pip", "install", "-r", "src/requirements.txt"])
subprocess.check_call(["git", "add", "."])
subprocess.check_call(["git", "commit", "-m", "chore: initial commit"])
initial_commit_hook()
finally:
# make sure we leave shell, return to original directory after finished
try:
Expand Down
18 changes: 17 additions & 1 deletion tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ def fix_empty_kedro_repo_session(
save_cache,
):
if save_cache:
create_sample_project("test", kd_repo_path=str(APP_DIR))
create_sample_project(
"test",
kd_repo_path=str(APP_DIR),
initial_commit_hook=_initial_commit_with_dummy_user,
)
for path in pathlib.Path("tmp/test").iterdir():
shutil.move(str(path), ".")
shutil.rmtree("tmp")
Expand Down Expand Up @@ -203,6 +207,18 @@ def fix_kd_context(empty_repo: DvcRepo) -> KDContext:
return KDContext(empty_repo.root_dir)


def _initial_commit_with_dummy_user() -> None:
"""
Initial commit of test sample project with dummy user.
"""
subprocess.check_call(["git", "config", "user.name", "dummy_user"])
subprocess.check_call(
["git", "config", "user.email", "[email protected]"]
)
subprocess.check_call(["git", "add", "."])
subprocess.check_call(["git", "commit", "-m", "chore: initial commit"])


def clear_fixture_cache() -> None: # pragma: no cover
"""
Removes the cached fixtures.
Expand Down

0 comments on commit 03632c8

Please sign in to comment.