From e1d9073bdff46bbcc643f9f2a55e9c8a69b4134c Mon Sep 17 00:00:00 2001 From: Keshav Priyadarshi Date: Thu, 19 Sep 2024 20:18:26 +0530 Subject: [PATCH] Fix code style Signed-off-by: Keshav Priyadarshi --- src/fetchcode/package.py | 10 +---- src/fetchcode/package_util.py | 10 +---- src/fetchcode/packagedcode_models.py | 36 ++++++++-------- tests/test_package.py | 64 ++++++++++++++++++---------- 4 files changed, 62 insertions(+), 58 deletions(-) diff --git a/src/fetchcode/package.py b/src/fetchcode/package.py index a0b7fec..e4140d0 100644 --- a/src/fetchcode/package.py +++ b/src/fetchcode/package.py @@ -390,7 +390,7 @@ def get_cocoapods_data_from_purl(purl): gh_repo_name = name podspec_api_url = f"https://raw.githubusercontent.com/CocoaPods/Specs/master/Specs/{hashed_path}/{name}/{tag}/{name}.podspec.json" podspec_api_response = get_response(podspec_api_url) - podspec_homepage = podspec_api_response.get('homepage') + podspec_homepage = podspec_api_response.get("homepage") if podspec_homepage.startswith("https://github.com/"): podspec_homepage_remove_gh_prefix = podspec_homepage.replace("https://github.com/", "") @@ -399,13 +399,7 @@ def get_cocoapods_data_from_purl(purl): gh_repo_name = podspec_homepage_split[-1] tag_pkg = construct_cocoapods_package( - version_purl, - name, - hashed_path, - cocoapods_org_url, - gh_repo_owner, - gh_repo_name, - tag + version_purl, name, hashed_path, cocoapods_org_url, gh_repo_owner, gh_repo_name, tag ) yield tag_pkg diff --git a/src/fetchcode/package_util.py b/src/fetchcode/package_util.py index 7415734..aedfd42 100644 --- a/src/fetchcode/package_util.py +++ b/src/fetchcode/package_util.py @@ -291,7 +291,6 @@ def get_package_info(cls, gh_purl, package_name): IPKG_RELEASES = json.loads((DATA / "ipkg_releases.json").read_text(encoding="UTF-8")) - def get_cocoapod_tags(spec, name): try: response = utils.get_text_response(spec) @@ -309,13 +308,7 @@ def get_cocoapod_tags(spec, name): def construct_cocoapods_package( - purl, - name, - hashed_path, - cocoapods_org_url, - gh_repo_owner, - gh_repo_name, - tag + purl, name, hashed_path, cocoapods_org_url, gh_repo_owner, gh_repo_name, tag ): name = name homepage_url = None @@ -394,4 +387,3 @@ def construct_cocoapods_package( purl_pkg.version = tag return purl_pkg - diff --git a/src/fetchcode/packagedcode_models.py b/src/fetchcode/packagedcode_models.py index 51d873d..09dabfd 100644 --- a/src/fetchcode/packagedcode_models.py +++ b/src/fetchcode/packagedcode_models.py @@ -238,23 +238,23 @@ def purl(self): ).to_string() repository_homepage_url = String( - label='package repository homepage URL.', - help='URL to the page for this package in its package repository. ' - 'This is typically different from the package homepage URL proper.' - ) + label="package repository homepage URL.", + help="URL to the page for this package in its package repository. " + "This is typically different from the package homepage URL proper.", + ) repository_download_url = String( - label='package repository download URL.', - help='download URL to download the actual archive of code of this ' - 'package in its package repository. ' - 'This may be different from the actual download URL.' - ) + label="package repository download URL.", + help="download URL to download the actual archive of code of this " + "package in its package repository. " + "This may be different from the actual download URL.", + ) api_data_url = String( - label='package repository API URL.', - help='API URL to obtain structured data for this package such as the ' - 'URL to a JSON or XML api its package repository.' - ) + label="package repository API URL.", + help="API URL to obtain structured data for this package such as the " + "URL to a JSON or XML api its package repository.", + ) def set_purl(self, package_url): """ @@ -279,11 +279,11 @@ def to_dict(self, **kwargs): Return an OrderedDict of primitive Python types. """ mapping = attr.asdict(self, dict_factory=OrderedDict) - if not kwargs.get('exclude_properties'): - mapping['purl'] = self.purl - mapping['repository_homepage_url'] = self.repository_homepage_url - mapping['repository_download_url'] = self.repository_download_url - mapping['api_data_url'] = self.api_data_url + if not kwargs.get("exclude_properties"): + mapping["purl"] = self.purl + mapping["repository_homepage_url"] = self.repository_homepage_url + mapping["repository_download_url"] = self.repository_download_url + mapping["api_data_url"] = self.api_data_url if self.qualifiers: mapping["qualifiers"] = normalize_qualifiers(self.qualifiers, encode=False) return mapping diff --git a/tests/test_package.py b/tests/test_package.py index 5cc3e41..be24b58 100644 --- a/tests/test_package.py +++ b/tests/test_package.py @@ -109,7 +109,7 @@ def test_rubygems_packages(mock_get): mock_get_01_list_of_versions, mock_get_02_1st_in_list, mock_get_03_2nd_in_list, - mock_get_04_3rd_in_list + mock_get_04_3rd_in_list, ] packages = list(info(purl)) @@ -140,16 +140,20 @@ def test_cocoapods_packages( mock_get_hashed_path.return_value = "5/5/b" mock_get_cocoapod_tags.return_value = [ - '0.1.5', - '0.1.4', - '0.1.3', - '0.1.2', - '0.1.1', - '0.1.0', + "0.1.5", + "0.1.4", + "0.1.3", + "0.1.2", + "0.1.1", + "0.1.0", ] - mock_get_response.side_effect = file_json("tests/data/cocoapods/mock_get_response_side_effect.json") - mock_get_github_rest.return_value = load_json("tests/data/cocoapods/mock_get_github_rest_return_value.json") + mock_get_response.side_effect = file_json( + "tests/data/cocoapods/mock_get_response_side_effect.json" + ) + mock_get_github_rest.return_value = load_json( + "tests/data/cocoapods/mock_get_github_rest_return_value.json" + ) mock_response = mock.Mock() mock_response.status_code = 200 @@ -181,16 +185,20 @@ def test_get_cocoapods_data_from_purl( mock_get_hashed_path.return_value = "5/5/b" mock_get_cocoapod_tags.return_value = [ - '0.1.5', - '0.1.4', - '0.1.3', - '0.1.2', - '0.1.1', - '0.1.0', + "0.1.5", + "0.1.4", + "0.1.3", + "0.1.2", + "0.1.1", + "0.1.0", ] - mock_get_response.side_effect = file_json("tests/data/cocoapods/mock_get_response_side_effect.json") - mock_get_github_rest.return_value = load_json("tests/data/cocoapods/mock_get_github_rest_return_value.json") + mock_get_response.side_effect = file_json( + "tests/data/cocoapods/mock_get_response_side_effect.json" + ) + mock_get_github_rest.return_value = load_json( + "tests/data/cocoapods/mock_get_github_rest_return_value.json" + ) mock_response = mock.Mock() mock_response.status_code = 200 @@ -216,7 +224,7 @@ def test_get_cocoapod_tags(mock_get): hashed_path_underscore = hashed_path.replace("/", "_") file_prefix = "all_pods_versions_" spec = f"{api}/{file_prefix}{hashed_path_underscore}.txt" - expected_tags = ['0.1.0', '0.1.1', '0.2.0', '0.3.0'] + expected_tags = ["0.1.0", "0.1.1", "0.2.0", "0.3.0"] tags = get_cocoapod_tags(spec, cocoapods_org_pod_name) tags = sorted(tags) assert tags == expected_tags @@ -225,16 +233,24 @@ def test_get_cocoapod_tags(mock_get): @mock.patch("fetchcode.package_util.utils.get_response") @mock.patch("fetchcode.package_util.utils.make_head_request") @mock.patch("fetchcode.package_util.utils.get_github_rest") -def test_construct_cocoapods_package(mock_get_github_rest, mock_make_head_request, mock_get_response): - mock_get_github_rest.return_value = "Failed to fetch: https://api.github.com/repos/KevalPatel94/KVLLibraries" +def test_construct_cocoapods_package( + mock_get_github_rest, mock_make_head_request, mock_get_response +): + mock_get_github_rest.return_value = ( + "Failed to fetch: https://api.github.com/repos/KevalPatel94/KVLLibraries" + ) mock_response = mock.Mock() mock_response.status_code = 404 mock_make_head_request.return_value = mock_response - mock_get_response.return_value = load_json("tests/data/cocoapods/get_response_kvllibraries.json") + mock_get_response.return_value = load_json( + "tests/data/cocoapods/get_response_kvllibraries.json" + ) - expected_construct_cocoapods_package = load_json("tests/data/cocoapods/expected_construct_cocoapods_package.json") + expected_construct_cocoapods_package = load_json( + "tests/data/cocoapods/expected_construct_cocoapods_package.json" + ) purl = PackageURL.from_string("pkg:cocoapods/KVLLibraries") name = "KVLLibraries" @@ -244,7 +260,9 @@ def test_construct_cocoapods_package(mock_get_github_rest, mock_make_head_reques gh_repo_name = "KVLLibraries" tag = "1.1.0" - actual_output = construct_cocoapods_package(purl, name, hashed_path, repository_homepage_url, gh_repo_owner, gh_repo_name, tag) + actual_output = construct_cocoapods_package( + purl, name, hashed_path, repository_homepage_url, gh_repo_owner, gh_repo_name, tag + ) actual = json.dumps(actual_output.to_dict()) expected = json.dumps(expected_construct_cocoapods_package) assert actual == expected