Skip to content

Commit 122b8ab

Browse files
committed
lint
1 parent 51b9e59 commit 122b8ab

File tree

6 files changed

+64
-24
lines changed

6 files changed

+64
-24
lines changed

linode_api4/groups/image.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import BinaryIO, Tuple, List
1+
from typing import BinaryIO, List, Tuple
22

33
import requests
44

@@ -29,7 +29,9 @@ def __call__(self, *filters):
2929
"""
3030
return self.client._get_and_filter(Image, *filters)
3131

32-
def create(self, disk, label=None, description=None, cloud_init=False, tags=None):
32+
def create(
33+
self, disk, label=None, description=None, cloud_init=False, tags=None
34+
):
3335
"""
3436
Creates a new Image from a disk you own.
3537
@@ -54,7 +56,7 @@ def create(self, disk, label=None, description=None, cloud_init=False, tags=None
5456
"disk_id": disk.id if issubclass(type(disk), Base) else disk,
5557
"label": label,
5658
"description": description,
57-
"tags": tags
59+
"tags": tags,
5860
}
5961

6062
if cloud_init:
@@ -98,7 +100,12 @@ def create_upload(
98100
:returns: A tuple containing the new image and the image upload URL.
99101
:rtype: (Image, str)
100102
"""
101-
params = {"label": label, "region": region, "description": description, "tags": tags}
103+
params = {
104+
"label": label,
105+
"region": region,
106+
"description": description,
107+
"tags": tags,
108+
}
102109

103110
if cloud_init:
104111
params["cloud_init"] = cloud_init
@@ -116,7 +123,12 @@ def create_upload(
116123
return Image(self.client, result_image["id"], result_image), result_url
117124

118125
def upload(
119-
self, label: str, region: str, file: BinaryIO, description: str = None, tags: List[str] = None,
126+
self,
127+
label: str,
128+
region: str,
129+
file: BinaryIO,
130+
description: str = None,
131+
tags: List[str] = None,
120132
) -> Image:
121133
"""
122134
Creates and uploads a new image.
@@ -137,7 +149,9 @@ def upload(
137149
:rtype: Image
138150
"""
139151

140-
image, url = self.create_upload(label, region, description=description, tags=tags)
152+
image, url = self.create_upload(
153+
label, region, description=description, tags=tags
154+
)
141155

142156
requests.put(
143157
url,

linode_api4/linode_client.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import json
44
import logging
55
from importlib.metadata import version
6-
from typing import BinaryIO, Tuple, List
6+
from typing import BinaryIO, List, Tuple
77
from urllib import parse
88

99
import requests
@@ -383,27 +383,42 @@ def image_create(self, disk, label=None, description=None, tags=None):
383383
.. note:: This method is an alias to maintain backwards compatibility.
384384
Please use :meth:`LinodeClient.images.create(...) <.ImageGroup.create>` for all new projects.
385385
"""
386-
return self.images.create(disk, label=label, description=description, tags=tags)
386+
return self.images.create(
387+
disk, label=label, description=description, tags=tags
388+
)
387389

388390
def image_create_upload(
389-
self, label: str, region: str, description: str = None, tags: List[str] = None
391+
self,
392+
label: str,
393+
region: str,
394+
description: str = None,
395+
tags: List[str] = None,
390396
) -> Tuple[Image, str]:
391397
"""
392398
.. note:: This method is an alias to maintain backwards compatibility.
393399
Please use :meth:`LinodeClient.images.create_upload(...) <.ImageGroup.create_upload>`
394400
for all new projects.
395401
"""
396402

397-
return self.images.create_upload(label, region, description=description, tags=tags)
403+
return self.images.create_upload(
404+
label, region, description=description, tags=tags
405+
)
398406

399407
def image_upload(
400-
self, label: str, region: str, file: BinaryIO, description: str = None, tags: List[str] = None
408+
self,
409+
label: str,
410+
region: str,
411+
file: BinaryIO,
412+
description: str = None,
413+
tags: List[str] = None,
401414
) -> Image:
402415
"""
403416
.. note:: This method is an alias to maintain backwards compatibility.
404417
Please use :meth:`LinodeClient.images.upload(...) <.ImageGroup.upload>` for all new projects.
405418
"""
406-
return self.images.upload(label, region, file, description=description, tags=tags)
419+
return self.images.upload(
420+
label, region, file, description=description, tags=tags
421+
)
407422

408423
def nodebalancer_create(self, region, **kwargs):
409424
"""

linode_api4/objects/image.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,33 @@
22
from enum import StrEnum
33
from typing import List, Union
44

5-
from linode_api4.objects.serializable import JSONObject
65
from linode_api4.objects import Base, Property, Region
6+
from linode_api4.objects.serializable import JSONObject
7+
78

89
class ReplicationStatus(StrEnum):
910
"""
1011
The Enum class represents image replication status.
1112
"""
13+
1214
pending_replication = "pending replication"
1315
pending_deletion = "pending deletion"
1416
available = "available"
1517
creating = "creating"
1618
pending = "pending"
1719
replicating = "replicating"
1820

21+
1922
@dataclass
2023
class ImageReplica(JSONObject):
2124
"""
2225
The region and status of an image replica.
2326
"""
27+
2428
region: str = ""
2529
status: ReplicationStatus = None
2630

31+
2732
class Image(Base):
2833
"""
2934
An Image is something a Linode Instance or Disk can be deployed from.
@@ -67,7 +72,12 @@ def replicate(self, regions: Union[List[str], List[Region]]):
6772
Existing images in the regions not passed will be removed.
6873
:type regions: List[str]
6974
"""
70-
params = {"regions": [region.id if isinstance(region, Region) else region for region in regions]}
75+
params = {
76+
"regions": [
77+
region.id if isinstance(region, Region) else region
78+
for region in regions
79+
]
80+
}
7181

7282
result = self._client.post(
7383
"{}/regions".format(self.api_endpoint), model=self, data=params

test/integration/models/image/test_image.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ def test_image_create_upload(test_linode_client):
4545
"us-ord",
4646
BytesIO(test_image_content),
4747
description="integration test image upload",
48-
tags=["tests"]
48+
tags=["tests"],
4949
)
5050

5151
assert image.label == label
5252
assert image.description == "integration test image upload"
5353
assert image.tags[0] == "tests"
5454

55+
5556
@pytest.mark.smoke
5657
def test_image_replication(test_linode_client, image_upload):
5758
image = test_linode_client.load(Image, image_upload.id)
@@ -60,4 +61,4 @@ def test_image_replication(test_linode_client, image_upload):
6061

6162
assert image.label == image_upload.label
6263
assert image.total_size == image_upload.size * 2
63-
assert len(image.regions) == 2
64+
assert len(image.regions) == 2

test/unit/linode_client_test.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ def test_image_create(self):
127127
Tests that an Image can be created successfully
128128
"""
129129
with self.mock_post("images/private/123") as m:
130-
i = self.client.image_create(654, "Test-Image", "This is a test", ["test"])
130+
i = self.client.image_create(
131+
654, "Test-Image", "This is a test", ["test"]
132+
)
131133

132134
self.assertIsNotNone(i)
133135
self.assertEqual(i.id, "private/123")
@@ -141,7 +143,7 @@ def test_image_create(self):
141143
"disk_id": 654,
142144
"label": "Test-Image",
143145
"description": "This is a test",
144-
"tags": ["test"]
146+
"tags": ["test"],
145147
},
146148
)
147149

test/unit/objects/image_test.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def test_image_create_upload(self):
6666
"Realest Image Upload",
6767
"us-southeast",
6868
description="very real image upload.",
69-
tags=["test_tag", "test2"]
69+
tags=["test_tag", "test2"],
7070
)
7171

7272
self.assertEqual(m.call_url, "/images/upload")
@@ -77,7 +77,7 @@ def test_image_create_upload(self):
7777
"label": "Realest Image Upload",
7878
"region": "us-southeast",
7979
"description": "very real image upload.",
80-
"tags": ["test_tag", "test2"]
80+
"tags": ["test_tag", "test2"],
8181
},
8282
)
8383

@@ -105,7 +105,7 @@ def put_mock(url: str, data: BinaryIO = None, **kwargs):
105105
"us-southeast",
106106
BytesIO(TEST_IMAGE_CONTENT),
107107
description="very real image upload.",
108-
tags=["test_tag", "test2"]
108+
tags=["test_tag", "test2"],
109109
)
110110

111111
self.assertEqual(image.id, "private/1337")
@@ -158,7 +158,5 @@ def test_image_replication(self):
158158
self.assertEqual(replication_url, m.call_url)
159159
self.assertEqual(
160160
m.call_data,
161-
{
162-
"regions": ["us-east", "us-west"]
163-
},
161+
{"regions": ["us-east", "us-west"]},
164162
)

0 commit comments

Comments
 (0)