-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unify the container templates (#342)
Working with pretty much a duplicate of the container template directory was annoying, so this PR unifies the templates by introducing a `template_kind` option.
- Loading branch information
Showing
56 changed files
with
167 additions
and
389 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
evalutils/templates/algorithm/{{ cookiecutter.package_name }}/.gitattributes.j2
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
evalutils/templates/algorithm/{{ cookiecutter.package_name }}/Dockerfile
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
evalutils/templates/algorithm/{{ cookiecutter.package_name }}/README.md
This file was deleted.
Oops, something went wrong.
File renamed without changes.
10 changes: 7 additions & 3 deletions
10
...ils/templates/algorithm/cookiecutter.json → ...ils/templates/container/cookiecutter.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import os | ||
import shutil | ||
from pathlib import Path | ||
|
||
from evalutils.utils import ( | ||
convert_line_endings, | ||
generate_requirements_txt, | ||
generate_source_wheel, | ||
) | ||
|
||
TASK_KIND = "{{ cookiecutter.task_kind }}" | ||
TEMPLATE_KIND = "{{ cookiecutter.template_kind }}" | ||
IS_DEV_BUILD = int("{{ cookiecutter.dev_build }}") == 1 | ||
|
||
template_dir = Path(os.getcwd()) | ||
|
||
templated_files = template_dir.glob("*.j2") | ||
for f in templated_files: | ||
shutil.move(f.name, f.stem) | ||
|
||
if TEMPLATE_KIND == "Evaluation": # noqa: C901 | ||
shutil.rmtree("algorithm_test") | ||
os.remove("process.py") | ||
os.rename("evaluation_test", "test") | ||
|
||
def remove_classification_files(): | ||
os.remove(Path("ground-truth") / "reference.csv") | ||
os.remove(Path("test") / "submission.csv") | ||
|
||
def remove_segmentation_files(): | ||
files = [] | ||
for ext in ["mhd", "zraw"]: | ||
files.extend(Path(".").glob(f"**/*.{ext}")) | ||
|
||
for file in files: | ||
os.remove(str(file)) | ||
|
||
def remove_detection_files(): | ||
os.remove(Path("ground-truth") / "detection-reference.csv") | ||
os.remove(Path("test") / "detection-submission.csv") | ||
|
||
if TASK_KIND.lower() != "segmentation": | ||
remove_segmentation_files() | ||
|
||
if TASK_KIND.lower() != "detection": | ||
remove_detection_files() | ||
|
||
if TASK_KIND.lower() != "classification": | ||
remove_classification_files() | ||
|
||
elif TEMPLATE_KIND == "Algorithm": | ||
shutil.rmtree("evaluation_test") | ||
shutil.rmtree("ground-truth") | ||
os.remove("evaluation.py") | ||
os.rename("algorithm_test", "test") | ||
|
||
template_test_dir = template_dir / "test" | ||
|
||
def remove_result_files(): | ||
for task_kind in ["segmentation", "detection", "classification"]: | ||
os.remove(template_test_dir / f"results_{task_kind}.json") | ||
|
||
expected_output_file = ( | ||
template_test_dir / f"results_{TASK_KIND.lower()}.json" | ||
) | ||
|
||
shutil.copy( | ||
str(expected_output_file), template_test_dir / "expected_output.json" | ||
) | ||
|
||
remove_result_files() | ||
|
||
if IS_DEV_BUILD: | ||
generate_source_wheel(template_dir / "vendor") | ||
|
||
generate_requirements_txt() | ||
convert_line_endings() |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
33 changes: 33 additions & 0 deletions
33
evalutils/templates/container/{{ cookiecutter.package_name }}/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
FROM python:{{ cookiecutter.python_major_version }}.{{ cookiecutter.python_minor_version }}-slim | ||
|
||
RUN groupadd -r user && useradd -m --no-log-init -r -g user user | ||
|
||
RUN mkdir -p /opt/app /input /output \ | ||
&& chown user:user /opt/app /input /output | ||
|
||
USER user | ||
WORKDIR /opt/app | ||
|
||
ENV PATH="/home/user/.local/bin:${PATH}" | ||
|
||
RUN python -m pip install --user -U pip && python -m pip install --user pip-tools | ||
|
||
{% if cookiecutter.dev_build|int -%} | ||
COPY --chown=user:user vendor /opt/app/vendor | ||
{%- endif %} | ||
|
||
COPY --chown=user:user requirements.txt /opt/app/ | ||
RUN python -m piptools sync requirements.txt | ||
|
||
{% if cookiecutter.template_kind == "Evaluation" -%} | ||
COPY --chown=user:user ground-truth /opt/app/ground-truth | ||
COPY --chown=user:user evaluation.py /opt/app/ | ||
|
||
ENTRYPOINT [ "python", "-m", "evaluation" ] | ||
{%- endif %} | ||
|
||
{% if cookiecutter.template_kind == "Algorithm" -%} | ||
COPY --chown=user:user process.py /opt/app/ | ||
|
||
ENTRYPOINT [ "python", "-m", "process" ] | ||
{%- endif %} |
6 changes: 6 additions & 0 deletions
6
evalutils/templates/container/{{ cookiecutter.package_name }}/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# {{ cookiecutter.full_project_name }} {{ cookiecutter.template_kind }} | ||
|
||
The source code for the {{ cookiecutter.template_kind.lower() }} container for | ||
{{ cookiecutter.full_project_name }}, generated with | ||
evalutils version {{ cookiecutter.evalutils_version }} | ||
using Python {{ cookiecutter.python_major_version }}.{{ cookiecutter.python_minor_version }}. |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.