• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SwissDataScienceCenter / renku-python / 5948296099

23 Aug 2023 07:23AM UTC coverage: 85.801% (+0.04%) from 85.766%
5948296099

Pull #3601

github-actions

olevski
chore: run poetry lock
Pull Request #3601: hotfix: v2.6.1

40 of 48 new or added lines in 10 files covered. (83.33%)

285 existing lines in 25 files now uncovered.

25875 of 30157 relevant lines covered (85.8%)

4.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.43
/renku/core/dataset/context.py
1
# Copyright Swiss Data Science Center (SDSC). A partnership between
2
# École Polytechnique Fédérale de Lausanne (EPFL) and
3
# Eidgenössische Technische Hochschule Zürich (ETHZ).
4
#
5
# Licensed under the Apache License, Version 2.0 (the "License");
6
# you may not use this file except in compliance with the License.
7
# You may obtain a copy of the License at
8
#
9
#     http://www.apache.org/licenses/LICENSE-2.0
10
#
11
# Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS,
13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
# See the License for the specific language governing permissions and
15
# limitations under the License.
16
"""Dataset context managers."""
11✔
17

18
from pathlib import Path
11✔
19
from typing import Optional
11✔
20

21
from renku.core import errors
11✔
22
from renku.core.dataset.dataset import create_dataset
11✔
23
from renku.core.dataset.datasets_provenance import DatasetsProvenance
11✔
24
from renku.domain_model.dataset import Dataset
11✔
25
from renku.domain_model.project_context import project_context
11✔
26
from renku.domain_model.provenance.agent import Person
11✔
27

28

29
class DatasetContext:
11✔
30
    """Dataset context manager for metadata changes."""
31

32
    def __init__(
11✔
33
        self,
34
        name: str,
35
        create: Optional[bool] = False,
36
        commit_database: Optional[bool] = False,
37
        creator: Optional[Person] = None,
38
        datadir: Optional[Path] = None,
39
        storage: Optional[str] = None,
40
    ) -> None:
41
        self.name = name
9✔
42
        self.create = create
9✔
43
        self.commit_database = commit_database
9✔
44
        self.creator = creator
9✔
45
        self.dataset_provenance = DatasetsProvenance()
9✔
46
        self.dataset: Optional[Dataset] = None
9✔
47
        self.datadir: Optional[Path] = datadir
9✔
48
        self.storage = storage
9✔
49

50
    def __enter__(self):
11✔
51
        """Enter context."""
52
        self.dataset = self.dataset_provenance.get_by_name(name=self.name)
9✔
53
        if self.dataset is None:
9✔
54
            if not self.create:
9✔
55
                raise errors.DatasetNotFound(name=self.name)
4✔
56

57
            # NOTE: Don't update provenance when creating here because it will be updated later
58
            self.dataset = create_dataset(
9✔
59
                name=self.name, update_provenance=False, datadir=self.datadir, storage=self.storage
60
            )
61
        elif self.create:
7✔
62
            raise errors.DatasetExistsError(self.name)
3✔
63

64
        return self.dataset
9✔
65

66
    def __exit__(self, exc_type, exc_value, traceback):
11✔
67
        """Exit context."""
68
        if exc_type:
9✔
69
            # TODO use a general clean-up strategy: https://github.com/SwissDataScienceCenter/renku-python/issues/736
70
            # NOTE: Re-raise exception
71
            return False
6✔
72

73
        if self.dataset and self.commit_database:
9✔
UNCOV
74
            self.datasets_provenance = DatasetsProvenance()
×
UNCOV
75
            self.datasets_provenance.add_or_update(self.dataset, creator=self.creator)
×
UNCOV
76
            project_context.database.commit()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc