Skip to content

Commit

Permalink
Remove unused variables #515
Browse files Browse the repository at this point in the history
Signed-off-by: Jono Yang <[email protected]>
  • Loading branch information
JonoYang committed Aug 13, 2024
1 parent 4c7cfc0 commit 887359e
Show file tree
Hide file tree
Showing 29 changed files with 68 additions and 95 deletions.
4 changes: 1 addition & 3 deletions clearcode/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ def walk_and_load_from_filesystem(input_dir, cd_root_dir):

# Save to DB
try:
cditem = models.CDitem.objects.create(
path=cditem_rel_path, content=content
)
models.CDitem.objects.create(path=cditem_rel_path, content=content)
except IntegrityError:
# skip if we already have it in the DB
continue
Expand Down
21 changes: 13 additions & 8 deletions clearcode/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_known_package_types(self):
# This path starts with npm, which is known
cditem_1 = CDitem.objects.create(path="npm/name/version")
# asdf is not a proper type
cditem_2 = CDitem.objects.create(path="asdf/name/version")
CDitem.objects.create(path="asdf/name/version")
cditems = list(CDitem.objects.known_package_types())
self.assertEqual(1, len(cditems))
cditem = cditems[0]
Expand All @@ -50,7 +50,7 @@ def test_definitions(self):
path="composer/packagist/yoast/wordpress-seo/revision/9.5-RC3.json"
)
# harvest should not be in cditems
harvest = CDitem.objects.create(
CDitem.objects.create(
path="sourcearchive/mavencentral/io.nats/jnats/revision/2.6.6/tool/scancode/3.2.2.json"
)
cditems = list(CDitem.objects.definitions())
Expand All @@ -63,7 +63,7 @@ def test_scancode_harvests(self):
path="sourcearchive/mavencentral/io.nats/jnats/revision/2.6.6/tool/scancode/3.2.2.json"
)
# unexpected_harvest should not be in cditems
unexpected_harvest = CDitem.objects.create(
CDitem.objects.create(
path="sourcearchive/mavencentral/io.nats/jnats/revision/2.6.6/tool/licensee/9.13.0.json"
)
harvests = list(CDitem.objects.scancode_harvests())
Expand All @@ -75,7 +75,8 @@ def test_mappable(self):
definition_1 = CDitem.objects.create(
path="sourcearchive/mavencentral/io.nats/jnats/revision/2.6.6.json"
)
definition_2 = CDitem.objects.create(
# This should not be mappable
CDitem.objects.create(
path="sourcearchive/mavencentral/io.quarkus/quarkus-jsonb/revision/0.26.1.json",
last_map_date=timezone.now(),
map_error="error",
Expand All @@ -92,12 +93,14 @@ def test_mappable_definitions(self):
definition_1 = CDitem.objects.create(
path="sourcearchive/mavencentral/io.nats/jnats/revision/2.6.6.json"
)
definition_2 = CDitem.objects.create(
# This should not be mappable
CDitem.objects.create(
path="sourcearchive/mavencentral/io.quarkus/quarkus-jsonb/revision/0.26.1.json",
last_map_date=timezone.now(),
map_error="error",
)
harvest = CDitem.objects.create(
# This should not be mappable
CDitem.objects.create(
path="sourcearchive/mavencentral/io.nats/jnats/revision/2.6.6/tool/scancode/3.2.2.json"
)
mappables = list(CDitem.objects.mappable_definitions())
Expand All @@ -109,12 +112,14 @@ def test_mappable_scancode_harvests(self):
harvest_1 = CDitem.objects.create(
path="sourcearchive/mavencentral/io.nats/jnats/revision/2.6.6/tool/scancode/3.2.2.json"
)
harvest_2 = CDitem.objects.create(
# This should not be mappable
CDitem.objects.create(
path="sourcearchive/mavencentral/io.cucumber/cucumber-core/revision/5.0.0-RC1/tool/scancode/3.2.2.json",
last_map_date=timezone.now(),
map_error="error",
)
definition_1 = CDitem.objects.create(
# This should not be mappable
CDitem.objects.create(
path="sourcearchive/mavencentral/io.nats/jnats/revision/2.6.6.json"
)
mappables = list(CDitem.objects.mappable_scancode_harvests())
Expand Down
8 changes: 2 additions & 6 deletions clearindex/harvest.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ def create_from_harvest(package_scan={}, files_data=[], cditem_path=""):

download_url = package_data.get("download_url")
if not download_url:
logger.error(
f"Null `download_url` value for `package_data`: {package_data}"
)
logger.error(f"Null `download_url` value for `package_data`: {package_data}")
return

# This ugly block is needed until https://github.com/nexB/packagedb/issues/14
Expand All @@ -115,9 +113,7 @@ def create_from_harvest(package_scan={}, files_data=[], cditem_path=""):
merge_packages(
existing_package=package, new_package_data=package_data, replace=False
)
package.append_to_history(
f"Updated package from CDitem harvest: {cditem_path}"
)
package.append_to_history(f"Updated package from CDitem harvest: {cditem_path}")

logger.info(f"Merged package data from scancode harvest: {package}")

Expand Down
10 changes: 2 additions & 8 deletions matchcode_pipeline/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,8 @@ def test_matching_pipeline_api_matching_create(self, mock_execute_pipeline_task)
self.assertEqual("matching", response.data["runs"][0]["pipeline_name"])
mock_execute_pipeline_task.assert_called_once()

created_matching_project_detail_url = response.data["url"]
matching_project_uuid = response.data["uuid"]
results_url = reverse("matching-results", args=[matching_project_uuid])

# Check that the file was uploaded
created_matching_project_detail_url = response.data["url"]
response = self.csrf_client.get(created_matching_project_detail_url)
self.assertEqual("test-out.json", response.data["input_sources"][0]["filename"])

Expand All @@ -165,11 +162,8 @@ def test_matching_pipeline_api_matching_create_multiple_input_urls(
self.assertEqual("matching", response.data["runs"][0]["pipeline_name"])
mock_execute_pipeline_task.assert_called_once()

created_matching_project_detail_url = response.data["url"]
matching_project_uuid = response.data["uuid"]
results_url = reverse("matching-results", args=[matching_project_uuid])

# Check that the file was uploaded
created_matching_project_detail_url = response.data["url"]
response = self.csrf_client.get(created_matching_project_detail_url)
input_sources = response.data["input_sources"]
self.assertEqual(2, len(input_sources))
Expand Down
2 changes: 1 addition & 1 deletion minecode/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def index_package_scan(request, key):

user_id = signing.loads(key)
User = get_user_model()
user = get_object_or_404(User, id=user_id)
get_object_or_404(User, id=user_id)

results = json_data.get("results")
summary = json_data.get("summary")
Expand Down
4 changes: 3 additions & 1 deletion minecode/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ def index_package(
declared_license_expression = summary_data.get("declared_license_expression")
other_license_expressions = summary_data.get("other_license_expressions", [])
other_license_expressions = [
license_expression["value"] for license_expression in other_license_expressions if license_expression["value"]
license_expression["value"]
for license_expression in other_license_expressions
if license_expression["value"]
]
other_license_expression = combine_expressions(other_license_expressions)

Expand Down
4 changes: 3 additions & 1 deletion minecode/management/commands/import_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ def handle(self, *args, **options):
try:
errors = process_request(importable_uri)
except Exception as e:
errors = f"Error: Failed to process ImportableURI: {repr(importable_uri)}\n"
errors = (
f"Error: Failed to process ImportableURI: {repr(importable_uri)}\n"
)
errors += get_error_message(e)
finally:
if errors:
Expand Down
4 changes: 1 addition & 3 deletions minecode/management/commands/make_scannableuris.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ def handle(self, *args, **options):
uri=package_uri, package=package
)
if created:
self.stdout.write(
f"ScannableURI created for: {package_uri}"
)
self.stdout.write(f"ScannableURI created for: {package_uri}")
except Exception as e:
msg = f"Error creating ScannableURI for: {package_uri}"
msg += get_error_message(e)
Expand Down
12 changes: 7 additions & 5 deletions minecode/management/commands/run_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ def map_uri(resource_uri, _map_router=map_router):
return

except Exception as e:
msg = f"Error: Failed to map while processing ResourceURI: {repr(resource_uri)}\n"
msg = (
f"Error: Failed to map while processing ResourceURI: {repr(resource_uri)}\n"
)
msg += get_error_message(e)
logger.error(msg)
# we had an error, so mapped_scanned_packages is an error string
Expand Down Expand Up @@ -165,12 +167,12 @@ def map_uri(resource_uri, _map_router=map_router):
package=package,
)
if scannable_uri_created:
logger.debug(
f" + Inserted ScannableURI\t: {package_uri}"
)
logger.debug(f" + Inserted ScannableURI\t: {package_uri}")

except Exception as e:
msg = f"Error: Failed to map while processing ResourceURI: {repr(resource_uri)}\n"
msg = (
f"Error: Failed to map while processing ResourceURI: {repr(resource_uri)}\n"
)
msg += f"While processing scanned_package: {repr(scanned_package)}\n"
msg += get_error_message(e)
logger.error(msg)
Expand Down
8 changes: 2 additions & 6 deletions minecode/management/commands/run_visit.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,7 @@ def visit_uris(
)

if max_loops and int(visited_counter) > int(max_loops):
logger.info(
f"Stopping visits after max_loops: {max_loops} visit loops."
)
logger.info(f"Stopping visits after max_loops: {max_loops} visit loops.")
break

return visited_counter, inserted_counter
Expand Down Expand Up @@ -367,9 +365,7 @@ def visit_uri(
break

if max_uris and int(uri_counter_by_visitor[visitor_key]) > int(max_uris):
logger.info(
f" ! Breaking after processing max-uris: {max_uris} URIs."
)
logger.info(f" ! Breaking after processing max-uris: {max_uris} URIs.")
break

except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion minecode/management/commands/update_maven_package_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def update_maven_packages(
namespace = namespace.lower()
name = name.lower()
version = version.lower()
normalize_qualifiers = normalize_qualifiers.lower()
normalized_qualifiers = normalized_qualifiers.lower()

existing_packages = Package.objects.filter(
type="maven",
Expand Down
8 changes: 5 additions & 3 deletions minecode/mappers/bitbucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ def get_packages(self, uri, resource_uri):
"""Yield Package built from resource_uri record for a single package version."""
downloads_data = json.loads(resource_uri.data, object_pairs_hook=OrderedDict)
for download_data in downloads_data.get("values", []):
yield from build_bitbucket_download_packages(download_data, resource_uri.package_url)
yield from build_bitbucket_download_packages(
download_data, resource_uri.package_url
)


def build_bitbucket_download_packages(download_data, purl):
Expand All @@ -46,8 +48,8 @@ def build_bitbucket_download_packages(download_data, purl):
name = purl.name

# FIXME: add these ?
filename = download_data.get("name")
download_counts = download_data.get("downloads", 0)
# filename = download_data.get("name")
# download_counts = download_data.get("downloads", 0)

download_url = download_data.get("links", {}).get("self", {}).get("href")
size = download_data.get("size")
Expand Down
4 changes: 3 additions & 1 deletion minecode/mappers/cpan.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ def build_packages_from_release_json(metadata, uri=None):
# like perl_5. The license here under resources section is the
# url of license for example: http://dev.perl.org/licenses/ So
# it's useful to collect both information...
license_url = [lic for lic in resources.get("license", []) if lic and lic.strip()]
license_url = [
lic for lic in resources.get("license", []) if lic and lic.strip()
]
if license_url:
common_data["extracted_license_statement"].extend(license_url)

Expand Down
2 changes: 1 addition & 1 deletion minecode/mappers/fdroid.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def build_packages(purl, data):
size = file["size"]
download_url = f"https://f-droid.org/repo/{filename}"

package_mappping = dict(
package_mapping = dict(
version=version_code,
download_url=download_url,
repository_download_url=download_url,
Expand Down
4 changes: 1 addition & 3 deletions minecode/mappers/maven.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ def get_packages(self, uri, resource_uri):
)
package = get_package(resource_uri.data, resource_uri.package_url)
if package:
logger.debug(
f"MavenPomMapper.get_packages: uri: {uri}, package: {package}"
)
logger.debug(f"MavenPomMapper.get_packages: uri: {uri}, package: {package}")
yield package


Expand Down
4 changes: 1 addition & 3 deletions minecode/model_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,7 @@ def merge_packages(existing_package, new_package_data, replace=False):
logger.debug(f" No existing value: set to new: {new_value}")

if TRACE and replace:
logger.debug(
f" Existing value and replace: set to new: {new_value}"
)
logger.debug(f" Existing value and replace: set to new: {new_value}")

if existing_field == "parties":
# If `existing_field` is `parties`, then we update the `Party` table
Expand Down
8 changes: 5 additions & 3 deletions minecode/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ class ScannableURIAPITestCase(JsonBasedTesting, TestCase):

def setUp(self):
self.scan_queue_worker_user = User.objects.create_user(
username="username", email="[email protected]", password="secret" # NOQA
username="username",
email="[email protected]",
password="secret", # NOQA
)
scan_queue_workers_group, _ = Group.objects.get_or_create(
name="scan_queue_workers"
Expand All @@ -49,7 +51,7 @@ def setUp(self):
self.staff_user = User.objects.create_user(
username="staff_username",
email="[email protected]",
password="secret", # NOQA
password="secret", # NOQA
is_staff=True,
)
self.staff_auth = f"Token {self.staff_user.auth_token.key}"
Expand All @@ -60,7 +62,7 @@ def setUp(self):
self.regular_user = User.objects.create_user(
username="regular_username",
email="[email protected]",
password="secret", # NOQA
password="secret", # NOQA
)
self.regular_auth = f"Token {self.regular_user.auth_token.key}"
self.regular_client = APIClient(enforce_csrf_checks=True)
Expand Down
1 change: 0 additions & 1 deletion minecode/tests/test_maven.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,6 @@ def test_visit_and_map_with_index(self):
)

before_uri = [p.id for p in ResourceURI.objects.all()]
before_pkg = [p.id for p in packagedb.models.Package.objects.all()]

resource_uri = ResourceURI.objects.insert(uri=uri)

Expand Down
7 changes: 2 additions & 5 deletions minecode/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ def test_get_mappables(self):
self.assertEqual(2, ResourceURI.objects.get_mappables().count())
self.resource1.last_map_date = timezone.now()
self.resource1.save()
resource1 = ResourceURI.objects.get(id=self.resource1.id)
# resource2 should only be mappable
self.assertEqual([self.resource2], list(ResourceURI.objects.get_mappables()))

def test_get_mappables__map_error_must_make_a_resourceuri_non_mappable(self):
Expand All @@ -381,7 +381,6 @@ def test_get_mappables__map_error_must_make_a_resourceuri_non_mappable(self):
self.resource2.map_error = "Some error happened"
self.resource1.save()
self.resource2.save()
resource1 = ResourceURI.objects.get(id=self.resource1.id)
self.assertEqual([], list(ResourceURI.objects.get_mappables()))


Expand Down Expand Up @@ -457,9 +456,7 @@ def setUp(self):
)

def test_ScannableURI_create_basic_record(self):
scannable_uri = ScannableURI.objects.create(
uri=self.test_uri, package=self.test_package
)
ScannableURI.objects.create(uri=self.test_uri, package=self.test_package)
result = ScannableURI.objects.get(uri=self.test_uri)
self.assertEqual(self.test_uri, result.uri)
self.assertEqual(self.test_package, result.package)
Expand Down
2 changes: 0 additions & 2 deletions minecode/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ def _remove_fields_from_results(self, data, fields_to_remove):
]

if type(data) in (dict, OrderedDict, ReturnDict):
normalized_data = {}
# Remove fields from results and normalize Package UIDs
for field in fields_to_remove:
if field not in data:
Expand Down Expand Up @@ -300,7 +299,6 @@ def _remove_fields_from_results(self, data, fields_to_remove):
]

if type(data) in (dict, OrderedDict, ReturnDict):
normalized_data = {}
# Remove fields from results and normalize Package UIDs
for field in fields_to_remove:
if field not in data:
Expand Down
1 change: 0 additions & 1 deletion minecode/visitors/cran.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#



from bs4 import BeautifulSoup
from packageurl import PackageURL

Expand Down
2 changes: 1 addition & 1 deletion minecode/visitors/dockerhub.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def get_uris(self, content):
for result in results:
name = result.get("name")
# TODO: This will be used when new Package definition is merged.
star_count = result.get("star_count")
# star_count = result.get("star_count")
if name:
package_url = PackageURL(type="docker", name=name).to_string()
yield URI(
Expand Down
1 change: 0 additions & 1 deletion minecode/visitors/java_stream.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# The MIT License (MIT)
#
# Copyright (c) 2014 Gustav Arngården
Expand Down
Loading

0 comments on commit 887359e

Please sign in to comment.