Skip to content

Commit 07cc4ce

Browse files
Fix linter checks
Signed-off-by: Ayan Sinha Mahapatra <[email protected]>
1 parent 8491f06 commit 07cc4ce

File tree

7 files changed

+44
-43
lines changed

7 files changed

+44
-43
lines changed

scanpipe/api/serializers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
from scanpipe.models import CodebaseRelation
3131
from scanpipe.models import CodebaseResource
3232
from scanpipe.models import DiscoveredDependency
33-
from scanpipe.models import DiscoveredPackage
3433
from scanpipe.models import DiscoveredLicense
34+
from scanpipe.models import DiscoveredPackage
3535
from scanpipe.models import InputSource
3636
from scanpipe.models import Project
3737
from scanpipe.models import ProjectMessage

scanpipe/filters.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
from scanpipe.models import CodebaseRelation
3939
from scanpipe.models import CodebaseResource
4040
from scanpipe.models import DiscoveredDependency
41-
from scanpipe.models import DiscoveredPackage
4241
from scanpipe.models import DiscoveredLicense
42+
from scanpipe.models import DiscoveredPackage
4343
from scanpipe.models import Project
4444
from scanpipe.models import ProjectMessage
4545
from scanpipe.models import Run

scanpipe/models.py

+29-27
Original file line numberDiff line numberDiff line change
@@ -2685,14 +2685,10 @@ def with_resources_count(self):
26852685
return self.annotate(resources_count=count_subquery)
26862686

26872687
def has_license_detections(self):
2688-
return self.filter(
2689-
~Q(license_detections=[]) | ~Q(other_license_detections=[])
2690-
)
2688+
return self.filter(~Q(license_detections=[]) | ~Q(other_license_detections=[]))
26912689

26922690
def has_no_license_detections(self):
2693-
return self.filter(
2694-
Q(license_detections=[]) & Q(other_license_detections=[])
2695-
)
2691+
return self.filter(Q(license_detections=[]) & Q(other_license_detections=[]))
26962692

26972693

26982694
class AbstractPackage(models.Model):
@@ -3454,39 +3450,39 @@ class AbstractLicenseDetection(models.Model):
34543450
license_expression = models.TextField(
34553451
blank=True,
34563452
help_text=_(
3457-
'A license expression string using the SPDX license expression'
3458-
' syntax and ScanCode license keys, the effective license expression'
3459-
' for this license detection.'
3453+
"A license expression string using the SPDX license expression"
3454+
" syntax and ScanCode license keys, the effective license expression"
3455+
" for this license detection."
34603456
),
34613457
)
34623458

34633459
license_expression_spdx = models.TextField(
34643460
blank=True,
3465-
help_text=_('SPDX license expression string with SPDX ids.'),
3461+
help_text=_("SPDX license expression string with SPDX ids."),
34663462
)
34673463

34683464
matches = models.JSONField(
34693465
_("Reference Matches"),
34703466
default=list,
34713467
blank=True,
3472-
help_text=_('List of license matches combined in this detection.'),
3468+
help_text=_("List of license matches combined in this detection."),
34733469
)
34743470

34753471
detection_log = models.JSONField(
34763472
default=list,
34773473
blank=True,
34783474
help_text=_(
3479-
'A list of detection DetectionRule explaining how '
3480-
'this detection was created.'
3475+
"A list of detection DetectionRule explaining how "
3476+
"this detection was created."
34813477
),
34823478
)
34833479

34843480
identifier = models.CharField(
34853481
max_length=1024,
34863482
blank=True,
34873483
help_text=_(
3488-
'An identifier unique for a license detection, containing the license '
3489-
'expression and a UUID crafted from the match contents.'
3484+
"An identifier unique for a license detection, containing the license "
3485+
"expression and a UUID crafted from the match contents."
34903486
),
34913487
)
34923488

@@ -3502,10 +3498,11 @@ class DiscoveredLicense(
35023498
AbstractLicenseDetection,
35033499
):
35043500
"""
3505-
A project's Discovered Licenses are the unique License Detection objects
3501+
A project's Discovered Licenses are the unique License Detection objects
35063502
discovered in the code under analysis.
35073503
35083504
"""
3505+
35093506
license_expression_field = "license_expression"
35103507

35113508
# If this license was discovered in a extracted license statement
@@ -3523,10 +3520,10 @@ class DiscoveredLicense(
35233520
default=list,
35243521
blank=True,
35253522
help_text=_(
3526-
'A list of file regions with resource path, start and end line '
3527-
'details for each place this license detection was discovered at. '
3528-
'Also contains whether this license was discovered from a file or '
3529-
'from package metadata.'
3523+
"A list of file regions with resource path, start and end line "
3524+
"details for each place this license detection was discovered at. "
3525+
"Also contains whether this license was discovered from a file or "
3526+
"from package metadata."
35303527
),
35313528
)
35323529

@@ -3554,9 +3551,10 @@ def __str__(self):
35543551
@classmethod
35553552
def create_from_data(cls, project, detection_data):
35563553
"""
3557-
Create and returns a DiscoveredLicense for a `project` from the `detection_data`.
3558-
If one of the values of the required fields is not available, a "ProjectMessage"
3559-
is created instead of a new DiscoveredLicense instance.
3554+
Create and returns a DiscoveredLicense for a `project` from the
3555+
`detection_data`. If one of the values of the required fields is not
3556+
available, a "ProjectMessage" is created instead of a new
3557+
DiscoveredLicense instance.
35603558
"""
35613559
detection_data = detection_data.copy()
35623560
required_fields = ["license_expression", "identifier", "matches"]
@@ -3572,7 +3570,11 @@ def create_from_data(cls, project, detection_data):
35723570
f"{', '.join(missing_values)}"
35733571
)
35743572

3575-
project.add_warning(description=message, model=cls, details=detection_data)
3573+
project.add_warning(
3574+
description=message,
3575+
model=cls,
3576+
details=detection_data,
3577+
)
35763578
return
35773579

35783580
cleaned_data = {
@@ -3583,8 +3585,8 @@ def create_from_data(cls, project, detection_data):
35833585

35843586
discovered_license = cls(project=project, **cleaned_data)
35853587
# Using save_error=False to not capture potential errors at this level but
3586-
# rather in the CodebaseResource.create_and_add_license_data method so resource data
3587-
# can be injected in the ProjectMessage record.
3588+
# rather in the CodebaseResource.create_and_add_license_data method so
3589+
# resource data can be injected in the ProjectMessage record.
35883590
discovered_license.save(save_error=False, capture_exception=False)
35893591
return discovered_license
35903592

@@ -3594,7 +3596,7 @@ def update_with_file_region(self, file_region):
35943596
`file_regions` list and increase the `detection_count` by 1.
35953597
"""
35963598
file_region_data = file_region.to_dict()
3597-
if not file_region_data in self.file_regions:
3599+
if file_region_data not in self.file_regions:
35983600
self.file_regions.append(file_region_data)
35993601
if not self.detection_count:
36003602
self.detection_count = 1

scanpipe/pipes/__init__.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
from scanpipe.models import CodebaseRelation
3737
from scanpipe.models import CodebaseResource
3838
from scanpipe.models import DiscoveredDependency
39-
from scanpipe.models import DiscoveredPackage
4039
from scanpipe.models import DiscoveredLicense
40+
from scanpipe.models import DiscoveredPackage
4141
from scanpipe.pipes import scancode
4242

4343
logger = logging.getLogger("scanpipe.pipes")
@@ -239,7 +239,10 @@ def update_or_create_dependency(
239239

240240

241241
def update_or_create_license_detection(
242-
project, detection_data, resource_path, from_package=False,
242+
project,
243+
detection_data,
244+
resource_path,
245+
from_package=False,
243246
):
244247
"""
245248
Get, update or create a DiscoveredLicense object then return it.

scanpipe/pipes/input.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
from scanpipe.models import CodebaseRelation
3535
from scanpipe.models import CodebaseResource
3636
from scanpipe.models import DiscoveredDependency
37-
from scanpipe.models import DiscoveredPackage
3837
from scanpipe.models import DiscoveredLicense
38+
from scanpipe.models import DiscoveredPackage
3939
from scanpipe.pipes import scancode
4040
from scanpipe.pipes.output import mappings_key_by_fieldname
4141

scanpipe/pipes/scancode.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
from commoncode import fileutils
3838
from commoncode.resource import VirtualCodebase
3939
from extractcode import api as extractcode_api
40+
from licensedcode.detection import FileRegion
4041
from packagedcode import get_package_handler
4142
from packagedcode import models as packagedcode_models
42-
from licensedcode.detection import FileRegion
4343
from scancode import Scanner
4444
from scancode import api as scancode_api
4545
from scancode import cli as scancode_cli
@@ -450,12 +450,8 @@ def get_file_region(detection_data, resource_path):
450450
object containing information about where this license was detected
451451
exactly in a codebase, with `resource_path`, with start and end lines.
452452
"""
453-
start_line = min(
454-
[match['start_line'] for match in detection_data["matches"]]
455-
)
456-
end_line = max(
457-
[match['end_line'] for match in detection_data["matches"]]
458-
)
453+
start_line = min([match["start_line"] for match in detection_data["matches"]])
454+
end_line = max([match["end_line"] for match in detection_data["matches"]])
459455
return FileRegion(
460456
path=resource_path,
461457
start_line=start_line,
@@ -680,7 +676,7 @@ def create_discovered_licenses(project, scanned_codebase):
680676
"""
681677
Save the license detections of a ScanCode `scanned_codebase`
682678
scancode.resource.Codebase object to the database as a DiscoveredLicense of
683-
`project`.
679+
`project`.
684680
"""
685681
if hasattr(scanned_codebase.attributes, "license_detections"):
686682
for detection_data in scanned_codebase.attributes.license_detections:

scanpipe/views.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@
6464
from scanpipe.api.serializers import DiscoveredDependencySerializer
6565
from scanpipe.filters import PAGE_VAR
6666
from scanpipe.filters import DependencyFilterSet
67-
from scanpipe.filters import PackageFilterSet
6867
from scanpipe.filters import LicenseFilterSet
68+
from scanpipe.filters import PackageFilterSet
6969
from scanpipe.filters import ProjectFilterSet
7070
from scanpipe.filters import ProjectMessageFilterSet
7171
from scanpipe.filters import RelationFilterSet
@@ -82,8 +82,8 @@
8282
from scanpipe.models import CodebaseRelation
8383
from scanpipe.models import CodebaseResource
8484
from scanpipe.models import DiscoveredDependency
85-
from scanpipe.models import DiscoveredPackage
8685
from scanpipe.models import DiscoveredLicense
86+
from scanpipe.models import DiscoveredPackage
8787
from scanpipe.models import InputSource
8888
from scanpipe.models import Project
8989
from scanpipe.models import ProjectMessage
@@ -1999,7 +1999,7 @@ def get_context_data(self, **kwargs):
19991999
context = super().get_context_data(**kwargs)
20002000
context["dependency_data"] = DiscoveredDependencySerializer(self.object).data
20012001
return context
2002-
2002+
20032003

20042004
class DiscoveredLicenseDetailsView(
20052005
ConditionalLoginRequired,

0 commit comments

Comments
 (0)