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

colour-science / colour-datasets / 7853010122

10 Feb 2024 05:53AM UTC coverage: 96.225%. Remained the same
7853010122

push

github

KelSolaar
Use `np.reshape` function instead of `.reshape` method.

2243 of 2331 relevant lines covered (96.22%)

0.96 hits per line

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

86.84
/colour_datasets/records/configuration.py
1
"""
2
Configuration
3
=============
4

5
Defines various objects related to the configuration of *Colour - Datasets*.
6
"""
7

8
from __future__ import annotations
1✔
9

10
import functools
1✔
11
import os
1✔
12

13
from colour.hints import Any, Callable, Dict
1✔
14
from colour.utilities import Structure
1✔
15
from colour.utilities.documentation import (
1✔
16
    DocstringDict,
17
    is_documentation_building,
18
)
19

20
__author__ = "Colour Developers"
1✔
21
__copyright__ = "Copyright 2019 Colour Developers"
1✔
22
__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"
1✔
23
__maintainer__ = "Colour Developers"
1✔
24
__email__ = "colour-developers@colour-science.org"
1✔
25
__status__ = "Production"
1✔
26

27
__all__ = [
1✔
28
    "DEFAULT_CONFIGURATION",
29
    "Configuration",
30
    "use_sandbox",
31
    "sandbox",
32
]
33

34
DEFAULT_CONFIGURATION: Dict = {
1✔
35
    "repository": os.environ.get(
36
        "COLOUR_SCIENCE__COLOUR_DATASETS__REPOSITORY",
37
        os.path.join(
38
            os.path.expanduser("~"),
39
            ".colour-science",
40
            "colour-datasets",
41
        ),
42
    ),
43
    "downloads_directory": "downloads",
44
    "deflate_directory": "dataset",
45
    "api_url": "https://zenodo.org/api",
46
    "community": "colour-science-datasets",
47
    "urls_txt_file": "urls.txt",
48
}
49
if is_documentation_building():  # pragma: no cover
50
    DEFAULT_CONFIGURATION = DocstringDict(DEFAULT_CONFIGURATION)
51
    DEFAULT_CONFIGURATION.__doc__ = """
52
*Colour - Datasets* default configuration.
53
"""
54

55

56
class Configuration(Structure):
1✔
57
    """
58
    *Colour - Datasets* configuration factory based on
59
    :class:`colour.utilities.Structure` class and allowing to access key values
60
    using dot syntax.
61

62
    Parameters
63
    ----------
64
    configuration
65
        Configuration to use instead of the default one.
66
    """
67

68
    def __init__(self, configuration: Dict | None = None) -> None:
1✔
69
        super().__init__(
1✔
70
            DEFAULT_CONFIGURATION if configuration is None else configuration
71
        )
72

73

74
def use_sandbox(
1✔
75
    state: bool = True,
76
    api_url: str = "https://sandbox.zenodo.org/api",
77
    community: str = "colour-science-datasets",
78
):
79
    """
80
    Modify the *Colour - Datasets* configuration to use *Zenodo* sandbox.
81

82
    Parameters
83
    ----------
84
    state
85
        Whether to use *Zenodo* sandbox.
86
    api_url
87
        *Zenodo* sandbox url.
88
    community
89
        *Zenodo* community.
90
    """
91

92
    global DEFAULT_CONFIGURATION  # noqa: PLW0602
93

94
    if state:
1✔
95
        DEFAULT_CONFIGURATION["api_url"] = api_url
1✔
96
        DEFAULT_CONFIGURATION["community"] = community
1✔
97
    else:
98
        DEFAULT_CONFIGURATION["api_url"] = "https://zenodo.org/api"
1✔
99
        DEFAULT_CONFIGURATION["community"] = "colour-science-datasets"
1✔
100

101

102
class sandbox:
1✔
103
    """
104
    A context manager and decorator temporarily setting the configuration to
105
    the *Zenodo* sandbox.
106

107
    Parameters
108
    ----------
109
    api_url
110
        *Zenodo* sandbox url.
111
    community
112
        *Zenodo* community.
113
    """
114

115
    def __init__(
1✔
116
        self,
117
        api_url: str = "https://sandbox.zenodo.org/api",
118
        community: str = "colour-science-datasets",
119
    ) -> None:
120
        self._api_url = api_url
1✔
121
        self._community = community
1✔
122

123
    def __enter__(self) -> sandbox:
1✔
124
        """
125
        Set the configuration to the *Zenodo* sandbox upon entering the context
126
        manager.
127
        """
128

129
        use_sandbox(True, self._api_url, self._community)
1✔
130

131
        return self
1✔
132

133
    def __exit__(self, *args: Any):
1✔
134
        """Restore the configuration upon exiting the context manager."""
135

136
        use_sandbox(False)
1✔
137

138
    def __call__(self, function: Callable) -> Callable:
1✔
139
        """Call the wrapped definition."""
140

141
        @functools.wraps(function)
×
142
        def wrapper(*args: Any, **kwargs: Any) -> Callable:
×
143
            with self:
×
144
                return function(*args, **kwargs)
×
145

146
        return wrapper
×
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

© 2025 Coveralls, Inc