Skip to content

Commit e1d9073

Browse files
committed
Fix code style
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
1 parent 550c654 commit e1d9073

File tree

4 files changed

+62
-58
lines changed

4 files changed

+62
-58
lines changed

src/fetchcode/package.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ def get_cocoapods_data_from_purl(purl):
390390
gh_repo_name = name
391391
podspec_api_url = f"https://raw.githubusercontent.com/CocoaPods/Specs/master/Specs/{hashed_path}/{name}/{tag}/{name}.podspec.json"
392392
podspec_api_response = get_response(podspec_api_url)
393-
podspec_homepage = podspec_api_response.get('homepage')
393+
podspec_homepage = podspec_api_response.get("homepage")
394394

395395
if podspec_homepage.startswith("https://github.com/"):
396396
podspec_homepage_remove_gh_prefix = podspec_homepage.replace("https://github.com/", "")
@@ -399,13 +399,7 @@ def get_cocoapods_data_from_purl(purl):
399399
gh_repo_name = podspec_homepage_split[-1]
400400

401401
tag_pkg = construct_cocoapods_package(
402-
version_purl,
403-
name,
404-
hashed_path,
405-
cocoapods_org_url,
406-
gh_repo_owner,
407-
gh_repo_name,
408-
tag
402+
version_purl, name, hashed_path, cocoapods_org_url, gh_repo_owner, gh_repo_name, tag
409403
)
410404

411405
yield tag_pkg

src/fetchcode/package_util.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@ def get_package_info(cls, gh_purl, package_name):
291291
IPKG_RELEASES = json.loads((DATA / "ipkg_releases.json").read_text(encoding="UTF-8"))
292292

293293

294-
295294
def get_cocoapod_tags(spec, name):
296295
try:
297296
response = utils.get_text_response(spec)
@@ -309,13 +308,7 @@ def get_cocoapod_tags(spec, name):
309308

310309

311310
def construct_cocoapods_package(
312-
purl,
313-
name,
314-
hashed_path,
315-
cocoapods_org_url,
316-
gh_repo_owner,
317-
gh_repo_name,
318-
tag
311+
purl, name, hashed_path, cocoapods_org_url, gh_repo_owner, gh_repo_name, tag
319312
):
320313
name = name
321314
homepage_url = None
@@ -394,4 +387,3 @@ def construct_cocoapods_package(
394387
purl_pkg.version = tag
395388

396389
return purl_pkg
397-

src/fetchcode/packagedcode_models.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -238,23 +238,23 @@ def purl(self):
238238
).to_string()
239239

240240
repository_homepage_url = String(
241-
label='package repository homepage URL.',
242-
help='URL to the page for this package in its package repository. '
243-
'This is typically different from the package homepage URL proper.'
244-
)
241+
label="package repository homepage URL.",
242+
help="URL to the page for this package in its package repository. "
243+
"This is typically different from the package homepage URL proper.",
244+
)
245245

246246
repository_download_url = String(
247-
label='package repository download URL.',
248-
help='download URL to download the actual archive of code of this '
249-
'package in its package repository. '
250-
'This may be different from the actual download URL.'
251-
)
247+
label="package repository download URL.",
248+
help="download URL to download the actual archive of code of this "
249+
"package in its package repository. "
250+
"This may be different from the actual download URL.",
251+
)
252252

253253
api_data_url = String(
254-
label='package repository API URL.',
255-
help='API URL to obtain structured data for this package such as the '
256-
'URL to a JSON or XML api its package repository.'
257-
)
254+
label="package repository API URL.",
255+
help="API URL to obtain structured data for this package such as the "
256+
"URL to a JSON or XML api its package repository.",
257+
)
258258

259259
def set_purl(self, package_url):
260260
"""
@@ -279,11 +279,11 @@ def to_dict(self, **kwargs):
279279
Return an OrderedDict of primitive Python types.
280280
"""
281281
mapping = attr.asdict(self, dict_factory=OrderedDict)
282-
if not kwargs.get('exclude_properties'):
283-
mapping['purl'] = self.purl
284-
mapping['repository_homepage_url'] = self.repository_homepage_url
285-
mapping['repository_download_url'] = self.repository_download_url
286-
mapping['api_data_url'] = self.api_data_url
282+
if not kwargs.get("exclude_properties"):
283+
mapping["purl"] = self.purl
284+
mapping["repository_homepage_url"] = self.repository_homepage_url
285+
mapping["repository_download_url"] = self.repository_download_url
286+
mapping["api_data_url"] = self.api_data_url
287287
if self.qualifiers:
288288
mapping["qualifiers"] = normalize_qualifiers(self.qualifiers, encode=False)
289289
return mapping

tests/test_package.py

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def test_rubygems_packages(mock_get):
109109
mock_get_01_list_of_versions,
110110
mock_get_02_1st_in_list,
111111
mock_get_03_2nd_in_list,
112-
mock_get_04_3rd_in_list
112+
mock_get_04_3rd_in_list,
113113
]
114114

115115
packages = list(info(purl))
@@ -140,16 +140,20 @@ def test_cocoapods_packages(
140140
mock_get_hashed_path.return_value = "5/5/b"
141141

142142
mock_get_cocoapod_tags.return_value = [
143-
'0.1.5',
144-
'0.1.4',
145-
'0.1.3',
146-
'0.1.2',
147-
'0.1.1',
148-
'0.1.0',
143+
"0.1.5",
144+
"0.1.4",
145+
"0.1.3",
146+
"0.1.2",
147+
"0.1.1",
148+
"0.1.0",
149149
]
150150

151-
mock_get_response.side_effect = file_json("tests/data/cocoapods/mock_get_response_side_effect.json")
152-
mock_get_github_rest.return_value = load_json("tests/data/cocoapods/mock_get_github_rest_return_value.json")
151+
mock_get_response.side_effect = file_json(
152+
"tests/data/cocoapods/mock_get_response_side_effect.json"
153+
)
154+
mock_get_github_rest.return_value = load_json(
155+
"tests/data/cocoapods/mock_get_github_rest_return_value.json"
156+
)
153157

154158
mock_response = mock.Mock()
155159
mock_response.status_code = 200
@@ -181,16 +185,20 @@ def test_get_cocoapods_data_from_purl(
181185
mock_get_hashed_path.return_value = "5/5/b"
182186

183187
mock_get_cocoapod_tags.return_value = [
184-
'0.1.5',
185-
'0.1.4',
186-
'0.1.3',
187-
'0.1.2',
188-
'0.1.1',
189-
'0.1.0',
188+
"0.1.5",
189+
"0.1.4",
190+
"0.1.3",
191+
"0.1.2",
192+
"0.1.1",
193+
"0.1.0",
190194
]
191195

192-
mock_get_response.side_effect = file_json("tests/data/cocoapods/mock_get_response_side_effect.json")
193-
mock_get_github_rest.return_value = load_json("tests/data/cocoapods/mock_get_github_rest_return_value.json")
196+
mock_get_response.side_effect = file_json(
197+
"tests/data/cocoapods/mock_get_response_side_effect.json"
198+
)
199+
mock_get_github_rest.return_value = load_json(
200+
"tests/data/cocoapods/mock_get_github_rest_return_value.json"
201+
)
194202

195203
mock_response = mock.Mock()
196204
mock_response.status_code = 200
@@ -216,7 +224,7 @@ def test_get_cocoapod_tags(mock_get):
216224
hashed_path_underscore = hashed_path.replace("/", "_")
217225
file_prefix = "all_pods_versions_"
218226
spec = f"{api}/{file_prefix}{hashed_path_underscore}.txt"
219-
expected_tags = ['0.1.0', '0.1.1', '0.2.0', '0.3.0']
227+
expected_tags = ["0.1.0", "0.1.1", "0.2.0", "0.3.0"]
220228
tags = get_cocoapod_tags(spec, cocoapods_org_pod_name)
221229
tags = sorted(tags)
222230
assert tags == expected_tags
@@ -225,16 +233,24 @@ def test_get_cocoapod_tags(mock_get):
225233
@mock.patch("fetchcode.package_util.utils.get_response")
226234
@mock.patch("fetchcode.package_util.utils.make_head_request")
227235
@mock.patch("fetchcode.package_util.utils.get_github_rest")
228-
def test_construct_cocoapods_package(mock_get_github_rest, mock_make_head_request, mock_get_response):
229-
mock_get_github_rest.return_value = "Failed to fetch: https://api.github.com/repos/KevalPatel94/KVLLibraries"
236+
def test_construct_cocoapods_package(
237+
mock_get_github_rest, mock_make_head_request, mock_get_response
238+
):
239+
mock_get_github_rest.return_value = (
240+
"Failed to fetch: https://api.github.com/repos/KevalPatel94/KVLLibraries"
241+
)
230242

231243
mock_response = mock.Mock()
232244
mock_response.status_code = 404
233245
mock_make_head_request.return_value = mock_response
234246

235-
mock_get_response.return_value = load_json("tests/data/cocoapods/get_response_kvllibraries.json")
247+
mock_get_response.return_value = load_json(
248+
"tests/data/cocoapods/get_response_kvllibraries.json"
249+
)
236250

237-
expected_construct_cocoapods_package = load_json("tests/data/cocoapods/expected_construct_cocoapods_package.json")
251+
expected_construct_cocoapods_package = load_json(
252+
"tests/data/cocoapods/expected_construct_cocoapods_package.json"
253+
)
238254

239255
purl = PackageURL.from_string("pkg:cocoapods/KVLLibraries")
240256
name = "KVLLibraries"
@@ -244,7 +260,9 @@ def test_construct_cocoapods_package(mock_get_github_rest, mock_make_head_reques
244260
gh_repo_name = "KVLLibraries"
245261
tag = "1.1.0"
246262

247-
actual_output = construct_cocoapods_package(purl, name, hashed_path, repository_homepage_url, gh_repo_owner, gh_repo_name, tag)
263+
actual_output = construct_cocoapods_package(
264+
purl, name, hashed_path, repository_homepage_url, gh_repo_owner, gh_repo_name, tag
265+
)
248266
actual = json.dumps(actual_output.to_dict())
249267
expected = json.dumps(expected_construct_cocoapods_package)
250268
assert actual == expected

0 commit comments

Comments
 (0)