Skip to content

Commit 9eba033

Browse files
committed
🎨 style(tests): Improve code formatting
1 parent 057a772 commit 9eba033

File tree

9 files changed

+282
-238
lines changed

9 files changed

+282
-238
lines changed

‎Makefile‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,6 @@ phabfive-run-dev: phabfive-build ## run phabfive connected to local phorge insta
107107
--add-host=phorge-files.domain.tld:host-gateway \
108108
$(PHABFIVE_CONFIG_MOUNT) \
109109
phabfive $(ARGS)
110+
111+
format: ## format code using ruff
112+
ruff format .

‎phabfive/diffusion.py‎

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ def _validate_credential_type(self, credential):
3737
m = credential[credential_phid]["monogram"]
3838
t = credential[credential_phid]["type"]
3939

40-
raise PhabfiveDataException(f"{m} is not type of 'ssh-generated-key', 'ssh-key-text' or 'token' but type '{t}'")
40+
raise PhabfiveDataException(
41+
f"{m} is not type of 'ssh-generated-key', 'ssh-key-text' or 'token' but type '{t}'"
42+
)
4143

4244
return credential_phid
4345

@@ -111,12 +113,14 @@ def create_repository(self, name=None, vcs=None, status=None):
111113
if name in repo["fields"]["name"]:
112114
raise PhabfiveDataException(f"Repository {name} already exists")
113115

114-
transactions = self.to_transactions({
115-
"name": name,
116-
"shortName": name,
117-
"vcs": vcs,
118-
"status": status,
119-
})
116+
transactions = self.to_transactions(
117+
{
118+
"name": name,
119+
"shortName": name,
120+
"vcs": vcs,
121+
"status": status,
122+
}
123+
)
120124

121125
new_repo = self.phab.diffusion.repository.edit(
122126
transactions=transactions,
@@ -151,7 +155,9 @@ def edit_repositories(self, names=None, status=None):
151155
# TODO: Choose a suitable return when the function is being implemented in cli.py
152156
return True
153157

154-
def create_uri(self, repository_name=None, new_uri=None, io=None, display=None, credential=None):
158+
def create_uri(
159+
self, repository_name=None, new_uri=None, io=None, display=None, credential=None
160+
):
155161
"""
156162
Phabfive wrapper that connects to Phabricator and create uri
157163
@@ -172,10 +178,14 @@ def create_uri(self, repository_name=None, new_uri=None, io=None, display=None,
172178
display = display or "always"
173179

174180
if io not in IO_NEW_URI_CHOICES:
175-
raise PhabfiveConfigException(f"'{io}' is not valid. Valid IO values are 'default', 'observe', 'mirror' or 'never'")
181+
raise PhabfiveConfigException(
182+
f"'{io}' is not valid. Valid IO values are 'default', 'observe', 'mirror' or 'never'"
183+
)
176184

177185
if display not in DISPLAY_CHOICES:
178-
raise PhabfiveConfigException(f"'{display}' is not valid. Valid Display values are 'default', 'always' or 'hidden'")
186+
raise PhabfiveConfigException(
187+
f"'{display}' is not valid. Valid Display values are 'default', 'always' or 'hidden'"
188+
)
179189

180190
repos = self.get_repositories(attachments={"uris": True})
181191

@@ -225,16 +235,20 @@ def create_uri(self, repository_name=None, new_uri=None, io=None, display=None,
225235
)
226236

227237
if not repository_exist:
228-
raise PhabfiveDataException(f"'{repository_name}' does not exist. Please create a new repository")
238+
raise PhabfiveDataException(
239+
f"'{repository_name}' does not exist. Please create a new repository"
240+
)
229241
# TODO: raise an exception and let CLI handle print and exit
230242

231-
transactions = self.to_transactions({
232-
"repository": repository_phid,
233-
"uri": new_uri,
234-
"io": io,
235-
"display": display,
236-
"credential": credential_phid,
237-
})
243+
transactions = self.to_transactions(
244+
{
245+
"repository": repository_phid,
246+
"uri": new_uri,
247+
"io": io,
248+
"display": display,
249+
"credential": credential_phid,
250+
}
251+
)
238252

239253
try:
240254
self.phab.diffusion.uri.edit(transactions=transactions)
@@ -243,7 +257,15 @@ def create_uri(self, repository_name=None, new_uri=None, io=None, display=None,
243257

244258
return new_uri
245259

246-
def edit_uri(self, uri=None, io=None, display=None, credential=None, disable=None, object_identifier=None):
260+
def edit_uri(
261+
self,
262+
uri=None,
263+
io=None,
264+
display=None,
265+
credential=None,
266+
disable=None,
267+
object_identifier=None,
268+
):
247269
"""
248270
Phabfive wrapper that connects to Phabricator and edit uri
249271
@@ -388,7 +410,9 @@ def get_branches(self, repo_id=None, repo_callsign=None, repo_shortname=None):
388410
if resolved:
389411
return self.phab.diffusion.branchquery(repository=resolved)
390412
else:
391-
raise PhabfiveDataException(f"Repository '{repo_shortname}' is not a valid repository")
413+
raise PhabfiveDataException(
414+
f"Repository '{repo_shortname}' is not a valid repository"
415+
)
392416

393417
def print_repositories(self, status=None, url=False):
394418
"""
@@ -402,11 +426,7 @@ def print_repositories(self, status=None, url=False):
402426
raise PhabfiveDataException("No data or other error")
403427

404428
# filter based on active or inactive status
405-
repos = [
406-
repo
407-
for repo in repos
408-
if repo["fields"]["status"] in status
409-
]
429+
repos = [repo for repo in repos if repo["fields"]["status"] in status]
410430

411431
# sort based on name
412432
repos = sorted(
@@ -442,9 +462,7 @@ def print_branches(self, repo):
442462
branches = self.get_branches(repo_shortname=repo)
443463

444464
branch_names = sorted(
445-
branch["shortName"]
446-
for branch in branches
447-
if branch["refType"] == "branch"
465+
branch["shortName"] for branch in branches if branch["refType"] == "branch"
448466
)
449467

450468
for branch_name in branch_names:
@@ -454,9 +472,7 @@ def _resolve_shortname_to_id(self, shortname):
454472
repos = self.get_repositories()
455473

456474
repo_ids = [
457-
repo["id"]
458-
for repo in repos
459-
if repo["fields"]["shortName"] == shortname
475+
repo["id"] for repo in repos if repo["fields"]["shortName"] == shortname
460476
]
461477

462478
return repo_ids[0] if repo_ids else None

‎phabfive/maniphest_transitions.py‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,15 @@ def matches(self, task_transactions, current_column, column_info):
4747
"""
4848
# All conditions must match for the pattern to match
4949
for condition in self.conditions:
50-
if not self._matches_condition(condition, task_transactions, current_column, column_info):
50+
if not self._matches_condition(
51+
condition, task_transactions, current_column, column_info
52+
):
5153
return False
5254
return True
5355

54-
def _matches_condition(self, condition, task_transactions, current_column, column_info):
56+
def _matches_condition(
57+
self, condition, task_transactions, current_column, column_info
58+
):
5559
"""Check if a single condition matches."""
5660
condition_type = condition.get("type")
5761

@@ -113,9 +117,15 @@ def _matches_from(self, condition, task_transactions, column_info):
113117

114118
# Check direction
115119
if new_col_info:
116-
if direction == "forward" and new_col_info["sequence"] > old_col_info["sequence"]:
120+
if (
121+
direction == "forward"
122+
and new_col_info["sequence"] > old_col_info["sequence"]
123+
):
117124
return True
118-
elif direction == "backward" and new_col_info["sequence"] < old_col_info["sequence"]:
125+
elif (
126+
direction == "backward"
127+
and new_col_info["sequence"] < old_col_info["sequence"]
128+
):
119129
return True
120130

121131
return False
@@ -283,7 +293,9 @@ def _parse_single_condition(condition_str):
283293

284294
# Patterns with parameters: type:value or type:value:direction
285295
if ":" not in condition_str:
286-
raise PhabfiveException(f"Invalid transition condition syntax: '{condition_str}'")
296+
raise PhabfiveException(
297+
f"Invalid transition condition syntax: '{condition_str}'"
298+
)
287299

288300
parts = condition_str.split(":", 2) # Split into max 3 parts
289301
condition_type = parts[0].strip()

‎phabfive/passphrase.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ def get_secret(self, ids):
4848
log.debug(json.dumps(response["data"], indent=2))
4949

5050
# When Conduit Access is not accepted for Passphrase the "response" will return value "noAPIAccess" in key "material" instead of the secret
51-
api_access_value = response["data"].get(next(iter(response["data"])))["material"]
51+
api_access_value = response["data"].get(next(iter(response["data"])))[
52+
"material"
53+
]
5254
no_api_access = "noAPIAccess" in api_access_value
5355

5456
if no_api_access:

‎phabfive/paste.py‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ def _convert_ids(self, ids):
3636

3737
return ids_list_int
3838

39-
def create_paste(self, title=None, file=None, language=None, tags=None, subscribers=None):
39+
def create_paste(
40+
self, title=None, file=None, language=None, tags=None, subscribers=None
41+
):
4042
"""
4143
Wrapper that connects to Phabricator and creates paste.
4244
@@ -68,9 +70,7 @@ def create_paste(self, title=None, file=None, language=None, tags=None, subscrib
6870

6971
# Phabricator does not take None (empty list is ok for projects/subscribers) as a value, therefor only "type" that has valid value can be sent as an argument
7072
transactions = [
71-
item
72-
for item in transactions_values
73-
if None not in item.values()
73+
item for item in transactions_values if None not in item.values()
7474
]
7575

7676
try:
@@ -119,10 +119,7 @@ def print_pastes(self, ids=None):
119119
raise PhabfiveDataException("No data or other error")
120120

121121
# sort based on title
122-
response = sorted(
123-
pastes,
124-
key=lambda key: key["fields"]["title"]
125-
)
122+
response = sorted(pastes, key=lambda key: key["fields"]["title"])
126123

127124
for item in response:
128125
paste = item["fields"]["title"]

‎phabfive/priority_transitions.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ def matches(self, priority_transactions, current_priority):
7777
"""
7878
# All conditions must match for the pattern to match
7979
for condition in self.conditions:
80-
if not self._matches_condition(condition, priority_transactions, current_priority):
80+
if not self._matches_condition(
81+
condition, priority_transactions, current_priority
82+
):
8183
return False
8284
return True
8385

@@ -284,7 +286,9 @@ def _parse_single_condition(condition_str):
284286
)
285287

286288
if len(parts) < 2:
287-
raise PhabfiveException(f"Missing priority name for condition: '{condition_str}'")
289+
raise PhabfiveException(
290+
f"Missing priority name for condition: '{condition_str}'"
291+
)
288292

289293
priority_name = parts[1].strip()
290294
if not priority_name:

0 commit comments

Comments
 (0)