Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
m-alisafaee committed Oct 1, 2023
1 parent 8c3c6ab commit aeaea2d
Show file tree
Hide file tree
Showing 17 changed files with 76 additions and 54 deletions.
19 changes: 15 additions & 4 deletions docs/reference/core.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ Schema classes used to serialize domain models to JSON-LD.
:members:
:show-inheritance:

.. automodule:: renku.command.schema.image
:members:
:show-inheritance:

.. automodule:: renku.command.schema.parameter
:members:
:show-inheritance:
Expand Down Expand Up @@ -105,10 +109,6 @@ Datasets
:members:
:show-inheritance:

.. automodule:: renku.core.dataset.request_model
:members:
:show-inheritance:

.. automodule:: renku.core.dataset.tag
:members:
:show-inheritance:
Expand Down Expand Up @@ -237,6 +237,17 @@ Errors that can be raised by ``renku.core``.
:members:
:show-inheritance:

Project/Dataset Images
----------------------

.. automodule:: renku.core.image
:members:
:show-inheritance:

.. automodule:: renku.domain_model.image
:members:


Utilities
---------

Expand Down
16 changes: 8 additions & 8 deletions renku/core/dataset/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from renku.core.dataset.providers.git import GitProvider
from renku.core.dataset.providers.models import DatasetUpdateAction, ProviderDataset
from renku.core.dataset.tag import get_dataset_by_tag, prompt_access_token, prompt_tag_selection
from renku.core.image import ImageRequestModel
from renku.core.image import ImageObjectRequest
from renku.core.interface.dataset_gateway import IDatasetGateway
from renku.core.storage import check_external_storage, track_paths_in_storage
from renku.core.util import communication
Expand Down Expand Up @@ -109,7 +109,7 @@ def create_dataset(
description: Optional[str] = None,
creators: Optional[List[Person]] = None,
keywords: Optional[List[str]] = None,
images: Optional[List[ImageRequestModel]] = None,
images: Optional[List[ImageObjectRequest]] = None,
update_provenance: bool = True,
custom_metadata: Optional[Dict[str, Any]] = None,
storage: Optional[str] = None,
Expand All @@ -123,7 +123,7 @@ def create_dataset(
description(Optional[str], optional): Dataset description (Default value = None).
creators(Optional[List[Person]], optional): Dataset creators (Default value = None).
keywords(Optional[List[str]], optional): Dataset keywords (Default value = None).
images(Optional[List[ImageRequestModel]], optional): Dataset images (Default value = None).
images(Optional[List[ImageObjectRequest]], optional): Dataset images (Default value = None).
update_provenance(bool, optional): Whether to add this dataset to dataset provenance
(Default value = True).
custom_metadata(Optional[Dict[str, Any]], optional): Custom JSON-LD metadata (Default value = None).
Expand Down Expand Up @@ -199,7 +199,7 @@ def edit_dataset(
description: Optional[Union[str, NoValueType]],
creators: Optional[Union[List[Person], NoValueType]],
keywords: Optional[Union[List[str], NoValueType]] = NO_VALUE,
images: Optional[Union[List[ImageRequestModel], NoValueType]] = NO_VALUE,
images: Optional[Union[List[ImageObjectRequest], NoValueType]] = NO_VALUE,
custom_metadata: Optional[Union[Dict, List[Dict], NoValueType]] = NO_VALUE,
custom_metadata_source: Optional[Union[str, NoValueType]] = NO_VALUE,
):
Expand All @@ -211,7 +211,7 @@ def edit_dataset(
description(Optional[Union[str, NoValueType]]): New description for the dataset.
creators(Optional[Union[List[Person], NoValueType]]): New creators for the dataset.
keywords(Optional[Union[List[str], NoValueType]]): New keywords for dataset (Default value = ``NO_VALUE``).
images(Optional[Union[List[ImageRequestModel], NoValueType]]): New images for dataset
images(Optional[Union[List[ImageObjectRequest], NoValueType]]): New images for dataset
(Default value = ``NO_VALUE``).
custom_metadata(Optional[Union[Dict, List[Dict], NoValueType]]): Custom JSON-LD metadata
(Default value = ``NO_VALUE``).
Expand Down Expand Up @@ -248,7 +248,7 @@ def edit_dataset(
if images == NO_VALUE:
images_updated = False
else:
images_updated = set_dataset_images(dataset=dataset, images=cast(Optional[List[ImageRequestModel]], images))
images_updated = set_dataset_images(dataset=dataset, images=cast(Optional[List[ImageObjectRequest]], images))

if images_updated:
updated["images"] = (
Expand Down Expand Up @@ -855,12 +855,12 @@ def add_datadir_files_to_dataset(dataset: Dataset) -> None:
dataset.add_or_update_files(dataset_files)


def set_dataset_images(dataset: Dataset, images: Optional[List[ImageRequestModel]]):
def set_dataset_images(dataset: Dataset, images: Optional[List[ImageObjectRequest]]):
"""Set a dataset's images.
Args:
dataset(Dataset): The dataset to set images on.
images(List[ImageRequestModel]): The images to set.
images(List[ImageObjectRequest]): The images to set.
Returns:
True if images were set/modified.
Expand Down
2 changes: 1 addition & 1 deletion renku/core/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from renku.domain_model.project_context import project_context


class ImageRequestModel:
class ImageObjectRequest:
"""Model for passing image information."""

def __init__(
Expand Down
14 changes: 7 additions & 7 deletions renku/core/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from renku.core.constant import DATA_DIR_CONFIG_KEY, RENKU_HOME
from renku.core.git import with_worktree
from renku.core.githooks import install_githooks
from renku.core.image import ImageRequestModel
from renku.core.image import ImageObjectRequest
from renku.core.interface.database_gateway import IDatabaseGateway
from renku.core.migration.utils import OLD_METADATA_PATH
from renku.core.project import set_project_image
Expand Down Expand Up @@ -103,7 +103,7 @@ def init_project(
name: Optional[str],
description: Optional[str],
keywords: Optional[List[str]],
image_request: Optional[ImageRequestModel],
image_request: Optional[ImageObjectRequest],
template_id: Optional[str],
template_source: Optional[str],
template_ref: Optional[str],
Expand All @@ -122,7 +122,7 @@ def init_project(
name: Name of the project.
description: Description of the project.
keywords: keywords for the project.
image_request(Optional[ImageRequestModel]): Project's image.
image_request(Optional[ImageObjectRequest]): Project's image.
template_id: id of the template to use.
template_source: Source to get the template from.
template_ref: Reference to use to get the template.
Expand Down Expand Up @@ -271,7 +271,7 @@ def create_from_template(
commit_message: Optional[str] = None,
description: Optional[str] = None,
keywords: Optional[List[str]] = None,
image_request: Optional[ImageRequestModel] = None,
image_request: Optional[ImageObjectRequest] = None,
install_mergetool: bool = False,
):
"""Initialize a new project from a template.
Expand All @@ -286,7 +286,7 @@ def create_from_template(
commit_message(Optional[str]): Message for initial commit (Default value = None).
description(Optional[str]): Description of the project (Default value = None).
keywords(Optional[List[str]]): Keywords for project (Default value = None).
image_request(Optional[ImageRequestModel]): Project's image (Default value = None).
image_request(Optional[ImageObjectRequest]): Project's image (Default value = None).
install_mergetool(bool): Whether to set up renku metadata mergetool (Default value = False).
"""
commit_only = [f"{RENKU_HOME}/", str(project_context.template_checksums_path)] + list(rendered_template.get_files())
Expand Down Expand Up @@ -349,7 +349,7 @@ def create_from_template_local(
keywords: Optional[List[str]] = None,
data_dir: Optional[str] = None,
ssh_supported: bool = False,
image_request: Optional[ImageRequestModel] = None,
image_request: Optional[ImageObjectRequest] = None,
):
"""Initialize a new project from a template.
Expand All @@ -369,7 +369,7 @@ def create_from_template_local(
description(Optional[str]): Project description (Default value = None).
keywords(Optional[List[str]]): Project keywords (Default value = None).
data_dir(Optional[str]): Project base data directory (Default value = None).
image_request(Optional[ImageRequestModel]): Project's image (Default value = None).
image_request(Optional[ImageObjectRequest]): Project's image (Default value = None).
"""
metadata = metadata or {}
default_metadata = default_metadata or {}
Expand Down
17 changes: 11 additions & 6 deletions renku/core/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
from renku.command.command_builder import inject
from renku.command.view_model.project import ProjectViewModel
from renku.core import errors
from renku.core.image import ImageRequestModel
from renku.core.image import ImageObjectRequest
from renku.core.interface.project_gateway import IProjectGateway
from renku.core.util.metadata import construct_creator
from renku.core.util.os import get_relative_path
from renku.domain_model.constant import NO_VALUE, NoValueType
from renku.domain_model.dataset import ImageObjectRequestJson
from renku.domain_model.project_context import project_context
from renku.domain_model.provenance.agent import Person

Expand All @@ -41,7 +42,7 @@ def edit_project(
keywords: Optional[Union[List[str], NoValueType]],
custom_metadata: Optional[Union[Dict, List[Dict], NoValueType]],
custom_metadata_source: Optional[Union[str, NoValueType]],
image_request: Optional[Union[ImageRequestModel, NoValueType]],
image_request: Optional[Union[ImageObjectRequest, NoValueType]],
project_gateway: IProjectGateway,
):
"""Edit dataset metadata.
Expand All @@ -53,7 +54,7 @@ def edit_project(
custom_metadata(Union[Optional[Dict, List[Dict]]): Custom JSON-LD metadata.
custom_metadata_source(Optional[str]): Custom metadata source.
project_gateway(IProjectGateway): Injected project gateway.
image_request(Optional[ImageRequestModel]): Project's image.
image_request(Optional[ImageObjectRequest]): Project's image.
Returns:
Tuple of fields that were updated and dictionary of warnings.
Expand All @@ -63,7 +64,11 @@ def edit_project(
"description": description,
"keywords": keywords,
"custom_metadata": custom_metadata,
"image": image_request,
"image": NO_VALUE
if image_request is NO_VALUE
else None
if image_request is None
else ImageObjectRequestJson().dump(image_request),
}

no_email_warnings: Optional[Union[Dict, str]] = None
Expand Down Expand Up @@ -103,11 +108,11 @@ def show_project() -> ProjectViewModel:
return ProjectViewModel.from_project(project_context.project)


def set_project_image(image_request: Optional[ImageRequestModel]) -> None:
def set_project_image(image_request: Optional[ImageObjectRequest]) -> None:
"""Download and set a project's images.
Args:
image_request(Optional[ImageRequestModel]): The image to set.
image_request(Optional[ImageObjectRequest]): The image to set.
"""
if image_request is None:
return
Expand Down
2 changes: 1 addition & 1 deletion renku/domain_model/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ class ImageObjectRequestJson(marshmallow.Schema):
file_id = marshmallow.fields.String()
content_url = marshmallow.fields.String()
position = marshmallow.fields.Integer(load_default=0)
mirror_locally = marshmallow.fields.Bool(dump_default=False)
mirror_locally = marshmallow.fields.Bool(load_default=False)


def get_file_path_in_dataset(dataset: Dataset, dataset_file: DatasetFile) -> Path:
Expand Down
4 changes: 2 additions & 2 deletions renku/ui/cli/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def init(
"""Initialize a project in PATH. Default is the current path."""
from renku.command.init import init_project_command
from renku.core.constant import FILESYSTEM_ROOT
from renku.core.image import ImageRequestModel
from renku.core.image import ImageObjectRequest
from renku.core.util.git import check_global_git_user_is_configured
from renku.ui.cli.utils.callback import ClickCallback

Expand All @@ -304,7 +304,7 @@ def init(
if metadata:
custom_metadata = json.loads(Path(metadata).read_text())

image_request = ImageRequestModel(content_url=image, safe_image_paths=[FILESYSTEM_ROOT]) if image else None
image_request = ImageObjectRequest(content_url=image, safe_image_paths=[FILESYSTEM_ROOT]) if image else None

communicator = ClickCallback()
init_project_command().with_communicator(communicator).build().execute(
Expand Down
6 changes: 3 additions & 3 deletions renku/ui/cli/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def edit(description, keywords, creators, image, metadata, unset, metadata_sourc
"""Edit project metadata."""
from renku.command.project import edit_project_command
from renku.core.constant import FILESYSTEM_ROOT
from renku.core.image import ImageRequestModel
from renku.core.image import ImageObjectRequest

if list(creators) == [NO_VALUE]:
creators = NO_VALUE
Expand All @@ -112,9 +112,9 @@ def edit(description, keywords, creators, image, metadata, unset, metadata_sourc
if "i" in unset or "image" in unset:
if image is not NO_VALUE:
raise click.UsageError("Cant use '--image' together with unsetting image")
image_request: Optional[Union[ImageRequestModel, NoValueType]] = None
image_request: Optional[Union[ImageObjectRequest, NoValueType]] = None
elif image is not NO_VALUE:
image_request = ImageRequestModel(content_url=image, safe_image_paths=[FILESYSTEM_ROOT])
image_request = ImageObjectRequest(content_url=image, safe_image_paths=[FILESYSTEM_ROOT])
else:
image_request = NO_VALUE

Expand Down
4 changes: 2 additions & 2 deletions renku/ui/service/controllers/datasets_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# limitations under the License.
"""Renku service datasets create controller."""
from renku.command.dataset import create_dataset_command
from renku.core.image import ImageRequestModel
from renku.core.image import ImageObjectRequest
from renku.core.util.metadata import construct_creators
from renku.ui.service.cache.models.job import Job
from renku.ui.service.config import CACHE_UPLOADS_PATH, MESSAGE_PREFIX
Expand Down Expand Up @@ -53,7 +53,7 @@ def renku_op(self):
set_url_for_uploaded_images(images=images, cache=self.cache, user=self.user)

images = [
ImageRequestModel(
ImageObjectRequest(
content_url=img["content_url"],
position=img["position"],
mirror_locally=img.get("mirror_locally", False),
Expand Down
4 changes: 2 additions & 2 deletions renku/ui/service/controllers/datasets_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from typing import Dict, List, Union, cast

from renku.command.dataset import edit_dataset_command
from renku.core.image import ImageRequestModel
from renku.core.image import ImageObjectRequest
from renku.core.util.metadata import construct_creators
from renku.domain_model.constant import NO_VALUE, NoValueType
from renku.domain_model.provenance.agent import Person
Expand Down Expand Up @@ -61,7 +61,7 @@ def renku_op(self):
set_url_for_uploaded_images(images=images, cache=self.cache, user=self.user)

images = [
ImageRequestModel(
ImageObjectRequest(
content_url=img["content_url"],
position=img["position"],
mirror_locally=img.get("mirror_locally", False),
Expand Down
15 changes: 9 additions & 6 deletions renku/ui/service/controllers/project_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Renku service project edit controller."""

from typing import Dict, Optional, Union, cast

from renku.command.project import edit_project_command
from renku.core.image import ImageRequestModel
from renku.core.image import ImageObjectRequest
from renku.domain_model.constant import NO_VALUE, NoValueType
from renku.ui.service.cache.models.job import Job
from renku.ui.service.config import CACHE_UPLOADS_PATH
Expand Down Expand Up @@ -79,21 +80,23 @@ def renku_op(self):
else:
keywords = NO_VALUE

if "image" in self.ctx:
if "image" not in self.ctx:
image_request = NO_VALUE
elif self.ctx["image"] is None:
image_request = None
else:
image: Dict = self.ctx.get("image") # type: ignore

user_cache_dir = CACHE_UPLOADS_PATH / self.user.user_id

set_url_for_uploaded_images(images=[image], cache=self.cache, user=self.user)

image_request: Optional[Union[ImageRequestModel, NoValueType]] = ImageRequestModel(
image_request: Optional[Union[ImageObjectRequest, NoValueType]] = ImageObjectRequest(
content_url=image["content_url"],
position=0,
mirror_locally=image.get("mirror_locally", True),
mirror_locally=image.get("mirror_locally", False),
safe_image_paths=[user_cache_dir],
)
else:
image_request = NO_VALUE

result = (
edit_project_command()
Expand Down
4 changes: 2 additions & 2 deletions renku/ui/service/controllers/templates_create_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from renku.command.init import create_from_template_local_command
from renku.core import errors
from renku.core.image import ImageRequestModel
from renku.core.image import ImageObjectRequest
from renku.core.template.template import fetch_templates_source
from renku.core.util.contexts import renku_project_context
from renku.domain_model.template import Template
Expand Down Expand Up @@ -157,7 +157,7 @@ def new_project(self):
user_cache_dir = CACHE_UPLOADS_PATH / self.user.user_id
set_url_for_uploaded_images(images=[image], cache=self.cache, user=self.user)

image = ImageRequestModel(
image = ImageObjectRequest(
content_url=image["content_url"],
position=0,
mirror_locally=image.get("mirror_locally", False),
Expand Down
Loading

0 comments on commit aeaea2d

Please sign in to comment.