-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* #252 Using the pytest plugins * #252 Using the pytest plugins * #252 Using the pytest plugins * #252 Using the pytest plugins * [CodeBuild] * #252 Updated dependencies * [CodeBuild] * #252 Fixed language_container_factory * [CodeBuild] * #252 Fixed the slc fixture name [CodeBuild] * #252 Fixed some tests [CodeBuild] * #252 Set proper dependencies [CodeBuild] * #252 Added a unit test for the language_container.py [CodeBuild]
- Loading branch information
Showing
34 changed files
with
669 additions
and
1,550 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ n/a | |
|
||
### Refactorings | ||
|
||
- #252: Use the pytest plugins for in the integration tests. | ||
|
||
n/a | ||
|
||
### Security | ||
|
116 changes: 19 additions & 97 deletions
116
exasol_transformers_extension/deployment/language_container.py
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 |
---|---|---|
@@ -1,105 +1,27 @@ | ||
import shutil | ||
import subprocess | ||
from pathlib import Path | ||
from typing import Dict, Optional | ||
from contextlib import contextmanager | ||
import re | ||
|
||
from exasol_integration_test_docker_environment.lib.docker.images.image_info import ImageInfo | ||
from exasol_script_languages_container_tool.lib import api | ||
from exasol_script_languages_container_tool.lib.tasks.export.export_containers import ExportContainerResult | ||
|
||
|
||
def find_file_or_folder_backwards(name: str) -> Path: | ||
current_path = Path(__file__).parent | ||
result_path = None | ||
while current_path != current_path.root: | ||
result_path = Path(current_path, name) | ||
if result_path.exists(): | ||
break | ||
current_path = current_path.parent | ||
if result_path is not None and result_path.exists(): | ||
return result_path | ||
else: | ||
raise RuntimeError(f"Could not find {name} when searching backwards from {Path(__file__).parent}") | ||
from exasol.python_extension_common.deployment.language_container_builder import ( | ||
LanguageContainerBuilder, find_path_backwards, exclude_cuda) | ||
|
||
|
||
CONTAINER_NAME = "exasol_transformers_extension_container" | ||
|
||
|
||
def find_flavor_path() -> Path: | ||
language_container_path = find_file_or_folder_backwards("language_container") | ||
flavor_path = language_container_path / CONTAINER_NAME | ||
return flavor_path | ||
|
||
|
||
def build_language_container(flavor_path: Path) -> Dict[str, ImageInfo]: | ||
image_infos = api.build(flavor_path=(str(flavor_path),), goal=("release",)) | ||
return image_infos | ||
|
||
|
||
def export(flavor_path: Path, | ||
export_path: Optional[Path] = None) -> ExportContainerResult: | ||
if export_path is not None: | ||
export_path = str(export_path) | ||
export_result = api.export(flavor_path=(str(flavor_path),), export_path=export_path) | ||
return export_result | ||
|
||
|
||
def upload( | ||
flavor_path: Path, | ||
bucketfs_name: str, | ||
bucket_name: str, | ||
database_host: str, | ||
bucketfs_port: int, | ||
user: str, | ||
password: str, | ||
path_in_bucket: str, | ||
release_name: str | ||
): | ||
api.upload( | ||
flavor_path=(str(flavor_path),), | ||
bucketfs_name=bucketfs_name, | ||
bucket_name=bucket_name, | ||
bucketfs_port=bucketfs_port, | ||
database_host=database_host, | ||
bucketfs_username=user, | ||
bucketfs_password=password, | ||
path_in_bucket=path_in_bucket, | ||
release_name=release_name | ||
) | ||
|
||
|
||
def prepare_flavor(flavor_path: Path): | ||
flavor_base_path = flavor_path / "flavor_base" | ||
add_requirements_to_flavor(flavor_base_path) | ||
add_wheel_to_flavor(flavor_base_path) | ||
|
||
|
||
def find_project_directory(): | ||
project_directory = find_file_or_folder_backwards("pyproject.toml").parent | ||
return project_directory | ||
|
||
|
||
def add_wheel_to_flavor(flavor_base_path): | ||
project_directory = find_project_directory() | ||
subprocess.call(["poetry", "build"], cwd=project_directory) | ||
dist_path = project_directory / "dist" | ||
wheels = list(dist_path.glob("*.whl")) | ||
if len(wheels) != 1: | ||
raise RuntimeError(f"Did not find exactly one wheel file in dist directory {dist_path}. " | ||
f"Found the following wheels: {wheels}") | ||
wheel = wheels[0] | ||
wheel_target = flavor_base_path / "release" / "dist" | ||
wheel_target.mkdir(parents=True, exist_ok=True) | ||
shutil.copyfile(wheel, wheel_target / wheel.name) | ||
def add_pytorch_to_requirements(container_builder: LanguageContainerBuilder) -> None: | ||
"""Modifies the default dependencies/Dockerfile""" | ||
dockerfile_file = 'flavor_base/dependencies/Dockerfile' | ||
dockerfile = container_builder.read_file(dockerfile_file) | ||
install_pattern = r'^\s*(?i:run)\s+python\d.\d+\s+-m\s+pip\s+install\s+-r\s+/project/requirements.txt' | ||
install_extra = '--extra-index-url https://download.pytorch.org/whl/cpu' | ||
dockerfile = re.sub(install_pattern, rf"\g<0> {install_extra}", dockerfile, flags=re.MULTILINE) | ||
container_builder.write_file(dockerfile_file, dockerfile) | ||
|
||
|
||
def add_requirements_to_flavor(flavor_base_path: Path): | ||
project_directory = find_project_directory() | ||
requirements_bytes = subprocess.check_output(["poetry", "export", "--without-hashes", "--without-urls"], | ||
cwd=project_directory) | ||
requirements = requirements_bytes.decode("UTF-8") | ||
requirements_without_cuda = "\n".join(line | ||
for line in requirements.splitlines() | ||
if not line.startswith("nvidia")) | ||
requirements_file = flavor_base_path / "dependencies" / "requirements.txt" | ||
requirements_file.write_text(requirements_without_cuda) | ||
@contextmanager | ||
def language_container_factory(): | ||
with LanguageContainerBuilder(CONTAINER_NAME) as container_builder: | ||
add_pytorch_to_requirements(container_builder) | ||
project_directory = find_path_backwards("pyproject.toml", __file__).parent | ||
container_builder.prepare_flavor(project_directory, requirement_filter=exclude_cuda) | ||
yield container_builder |
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
language_container/exaslct_scripts/construct_docker_runner_image_name.sh
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
language_container/exaslct_scripts/exaslct_install_template.sh
This file was deleted.
Oops, something went wrong.
133 changes: 0 additions & 133 deletions
133
language_container/exaslct_scripts/exaslct_within_docker_container.sh
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.