Skip to content

Commit 5c77bb6

Browse files
committed
Replace .format() w/ f-strings
1 parent c4615a0 commit 5c77bb6

7 files changed

Lines changed: 50 additions & 49 deletions

File tree

examples/assets/asset_scraper.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ def get_projects_from_team(
5151
# Add project_name and team_name to the dict
5252
proj["project_name"] = proj.get("name")
5353
proj["team_name"] = team_name
54-
print("Debug: Found project: {}".format(proj["project_name"]))
54+
print(f"Debug: Found project: {proj['project_name']}")
5555
projects_in_team.append(proj)
56-
print("Debug: projects in team now: {}".format(len(projects_in_team)))
56+
print(f"Debug: projects in team now: {len(projects_in_team)}")
5757

5858
return projects_in_team
5959

@@ -64,10 +64,10 @@ def get_projects_from_account(client) -> List[Dict]:
6464
teams = get_teams_from_account(client)
6565

6666
for team_id, team_name in teams.items():
67-
print("Debug: === Found team: {} ===".format(team_name))
67+
print(f"Debug: === Found team: {team_name} ===")
6868
projects_in_team = get_projects_from_team(client, team_id, team_name)
6969
projects_in_account.extend(projects_in_team)
70-
print("Debug: projects in account now: {}".format(len(projects_in_account)))
70+
print(f"Debug: projects in account now: {len(projects_in_account)}")
7171

7272
return projects_in_account
7373

@@ -81,7 +81,7 @@ def scrape_asset_data_from_projects(
8181
"""
8282
assets_in_projects = []
8383
for project in projects:
84-
print("Debug: Scanning project: {} for assets".format(project["name"]))
84+
print(f"Debug: Scanning project: {project['name']} for assets")
8585
assets_in_project = []
8686
proj_root_asset_id = project.get("root_asset_id")
8787
assets_in_project = scrape_asset_data(
@@ -182,7 +182,7 @@ def write_assets_to_csv(asset_list: List[Dict], filename: str) -> None:
182182
for a in asset_list:
183183
flat_assets_list.append(flatten_dict(a))
184184

185-
with open("asset_record_for_account_id-{}".format(filename), "w") as f:
185+
with open(f"asset_record_for_account_id-{filename}", "w") as f:
186186
f_csv = csv.DictWriter(f, headers, extrasaction="ignore")
187187
f_csv.writeheader()
188188
f_csv.writerows(flat_assets_list)

frameioclient/lib/download.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def get_path(self):
7272
def _evaluate_asset(self):
7373
if self.asset.get("_type") != "file":
7474
raise DownloadException(
75-
message="Unsupport Asset type: {}".format(self.asset.get("_type"))
75+
message=f"Unsupport Asset type: {self.asset.get('_type')}"
7676
)
7777

7878
# This logic may block uploads that were started before this field was introduced
@@ -98,7 +98,7 @@ def _create_file_stub(self):
9898
return True
9999

100100
def _get_path(self):
101-
logger.info("prefix: {}".format(self.prefix))
101+
logger.info(f"prefix: {self.prefix}")
102102
if self.prefix != None:
103103
self.filename = self.prefix + self.filename
104104

frameioclient/lib/telemetry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def build_context(self):
3131

3232
def push(self, event_name, properties):
3333
self.logger.info(
34-
("Pushing '{}' event to segment".format(event_name), properties)
34+
(f"Pushing '{event_name}' event to segment", properties)
3535
)
3636

3737
try:

frameioclient/lib/transfer.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,22 @@
88

99
import requests
1010

11-
from .exceptions import (AssetChecksumMismatch, AssetChecksumNotPresent,
12-
DownloadException)
11+
from .exceptions import (
12+
AssetChecksumMismatch,
13+
AssetChecksumNotPresent,
14+
DownloadException,
15+
)
1316
from .logger import SDKLogger
1417
from .utils import FormatTypes, Utils
1518

1619
logger = SDKLogger("downloads")
1720

1821
from .bandwidth import DiskBandwidth, NetworkBandwidth
19-
from .exceptions import (AssetNotFullyUploaded, DownloadException,
20-
WatermarkIDDownloadException)
22+
from .exceptions import (
23+
AssetNotFullyUploaded,
24+
DownloadException,
25+
WatermarkIDDownloadException,
26+
)
2127
from .transport import HTTPClient
2228

2329

@@ -71,7 +77,7 @@ def get_path(self):
7177
def _evaluate_asset(self):
7278
if self.asset.get("_type") != "file":
7379
raise DownloadException(
74-
message="Unsupport Asset type: {}".format(self.asset.get("_type"))
80+
message=f"Unsupport Asset type: {self.asset.get('_type')}"
7581
)
7682

7783
# This logic may block uploads that were started before this field was introduced
@@ -196,7 +202,7 @@ def __init__(self, downloader: FrameioDownloader, concurrency=None, progress=Tru
196202
self.bytes_completed = 0
197203
self.downloader = downloader
198204
self.futures = []
199-
self.original = self.downloader.asset['original']
205+
self.original = self.downloader.asset["original"]
200206

201207
# Ensure this is a valid number before assigning
202208
if concurrency is not None and type(concurrency) == int and concurrency > 0:
@@ -299,10 +305,7 @@ def _download_whole(self, url: str):
299305
math.ceil(self.downloader.filesize / (download_time))
300306
)
301307
print(
302-
"Downloaded {} at {}".format(
303-
Utils.format_value(self.downloader.filesize, type=FormatTypes.SIZE),
304-
download_speed,
305-
)
308+
f"Downloaded {Utils.format_value(self.downloader.filesize, type=FormatTypes.SIZE)} at {download_speed}"
306309
)
307310

308311
return self.destination, download_speed
@@ -378,10 +381,7 @@ def multi_thread_download(self):
378381
in_byte = 0 # Set initially here, but then override
379382

380383
print(
381-
"Multi-part download -- {} -- {}".format(
382-
self.downloader.asset["name"],
383-
Utils.format_value(self.downloader.filesize, type=FormatTypes.SIZE),
384-
)
384+
f"Multi-part download -- {self.downloader.asset['name']} -- {Utils.format_value(self.downloader.filesize, type=FormatTypes.SIZE)}"
385385
)
386386

387387
with concurrent.futures.ThreadPoolExecutor(
@@ -392,7 +392,7 @@ def multi_thread_download(self):
392392
out_byte = offset * (i + 1)
393393

394394
# Create task tuple
395-
task = (self.downloader.asset['original'], in_byte, out_byte, i)
395+
task = (self.downloader.asset["original"], in_byte, out_byte, i)
396396

397397
# Stagger start for each chunk by 0.1 seconds
398398
if i < self.concurrency:
@@ -423,22 +423,22 @@ def multi_thread_download(self):
423423
raise AssetChecksumNotPresent
424424

425425
# Calculate the file hash
426-
if Utils.calculate_hash(self.destination) != self.downloader.original_checksum:
426+
if (
427+
Utils.calculate_hash(self.destination)
428+
!= self.downloader.original_checksum
429+
):
427430
raise AssetChecksumMismatch
428431

429432
# Log completion event
430433
SDKLogger("downloads").info(
431-
"Downloaded {} at {}".format(
432-
Utils.format_value(self.downloader.filesize, type=FormatTypes.SIZE),
433-
download_speed,
434-
)
434+
f"Downloaded {Utils.format_value(self.downloader.filesize, type=FormatTypes.SIZE)} at {download_speed}"
435435
)
436436

437437
# Submit telemetry
438438
transfer_stats = {
439439
"speed": download_speed,
440440
"time": download_time,
441-
"cdn": AWSClient.check_cdn(self.original)
441+
"cdn": AWSClient.check_cdn(self.original),
442442
}
443443

444444
# Event(self.user_id, 'python-sdk-download-stats', transfer_stats)

frameioclient/lib/transport.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515

1616

1717
class HTTPMethods:
18-
GET = 'get'
19-
POST = 'post'
20-
PUT = 'put'
21-
DELETE = 'delete'
22-
PATCH = 'patch'
23-
HEAD = 'head'
18+
GET = "get"
19+
POST = "post"
20+
PUT = "put"
21+
DELETE = "delete"
22+
PATCH = "patch"
23+
HEAD = "head"
24+
2425

2526
class HTTPClient(object):
2627
"""HTTP Client base that automatically handles the following:
@@ -41,9 +42,7 @@ def __init__(self, threads: Optional[int] = default_thread_count):
4142
# Initialize empty thread object
4243
self.thread_local = None
4344
self.client_version = ClientVersion.version()
44-
self.shared_headers = {
45-
"x-frameio-client": "python/{}".format(self.client_version)
46-
}
45+
self.shared_headers = {"x-frameio-client": f"python/{self.client_version}"}
4746

4847
# Configure retry strategy (very broad right now)
4948
self.retry_strategy = Retry(
@@ -91,12 +90,14 @@ def __init__(self, token: str, host: str, threads: int, progress: bool):
9190
self.progress = progress
9291
self._initialize_thread()
9392
self.session = self._get_session()
94-
self.auth_header = {"Authorization": "Bearer {}".format(self.token)}
93+
self.auth_header = {"Authorization": f"Bearer {self.token}"}
9594

9695
def _format_api_call(self, endpoint: str):
97-
return "{}/v2{}".format(self.host, endpoint)
96+
return f"{self.host}/v2{endpoint}"
9897

99-
def _api_call(self, method, endpoint: str, payload: Dict = {}, limit: Optional[int] = None):
98+
def _api_call(
99+
self, method, endpoint: str, payload: Dict = {}, limit: Optional[int] = None
100+
):
100101
headers = {**self.shared_headers, **self.auth_header}
101102

102103
r = self.session.request(
@@ -128,7 +129,9 @@ def _api_call(self, method, endpoint: str, payload: Dict = {}, limit: Optional[i
128129

129130
return r.raise_for_status()
130131

131-
def get_specific_page(self, method: HTTPMethods, endpoint: str, payload: Dict, page: int):
132+
def get_specific_page(
133+
self, method: HTTPMethods, endpoint: str, payload: Dict, page: int
134+
):
132135
"""
133136
Gets a specific page for that endpoint, used by Pagination Class
134137
@@ -139,7 +142,7 @@ def get_specific_page(self, method: HTTPMethods, endpoint: str, payload: Dict, p
139142
page (int): What page to get
140143
"""
141144
if method == HTTPMethods.GET:
142-
endpoint = "{}?page={}".format(endpoint, page)
145+
endpoint = "{endpoint}?page={page}"
143146
return self._api_call(method, endpoint)
144147

145148
if method == HTTPMethods.POST:

frameioclient/lib/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ def format_headers(token: str, version: str) -> Dict:
169169
:param version: The version of the frameioclient sdk to add to our HTTP header
170170
"""
171171
return {
172-
"Authorization": "Bearer {}".format(token),
173-
"x-frameio-client": "python/{}".format(version),
172+
"Authorization": f"Bearer {token}",
173+
"x-frameio-client": f"python/{version}",
174174
}
175175

176176

setup.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ def run(self):
1717
tag = os.getenv('CIRCLE_TAG')
1818

1919
if tag != version:
20-
info = "Git tag: {0} does not match the version of this app: {1}".format(
21-
tag, version
22-
)
20+
info = f"Git tag: {tag} does not match the version of this app: {version}"
2321
sys.exit(info)
2422

2523
setuptools.setup(

0 commit comments

Comments
 (0)