Skip to content

Commit d188899

Browse files
Fix linter checks
Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>
1 parent d672650 commit d188899

File tree

7 files changed

+44
-43
lines changed

7 files changed

+44
-43
lines changed

scanpipe/api/serializers.py

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2727,14 +2727,10 @@ def with_resources_count(self):
27272727
return self.annotate(resources_count=count_subquery)
27282728

27292729
def has_license_detections(self):
2730-
return self.filter(
2731-
~Q(license_detections=[]) | ~Q(other_license_detections=[])
2732-
)
2730+
return self.filter(~Q(license_detections=[]) | ~Q(other_license_detections=[]))
27332731

27342732
def has_no_license_detections(self):
2735-
return self.filter(
2736-
Q(license_detections=[]) & Q(other_license_detections=[])
2737-
)
2733+
return self.filter(Q(license_detections=[]) & Q(other_license_detections=[]))
27382734

27392735

27402736
class AbstractPackage(models.Model):
@@ -3504,39 +3500,39 @@ class AbstractLicenseDetection(models.Model):
35043500
license_expression = models.TextField(
35053501
blank=True,
35063502
help_text=_(
3507-
'A license expression string using the SPDX license expression'
3508-
' syntax and ScanCode license keys, the effective license expression'
3509-
' for this license detection.'
3503+
"A license expression string using the SPDX license expression"
3504+
" syntax and ScanCode license keys, the effective license expression"
3505+
" for this license detection."
35103506
),
35113507
)
35123508

35133509
license_expression_spdx = models.TextField(
35143510
blank=True,
3515-
help_text=_('SPDX license expression string with SPDX ids.'),
3511+
help_text=_("SPDX license expression string with SPDX ids."),
35163512
)
35173513

35183514
matches = models.JSONField(
35193515
_("Reference Matches"),
35203516
default=list,
35213517
blank=True,
3522-
help_text=_('List of license matches combined in this detection.'),
3518+
help_text=_("List of license matches combined in this detection."),
35233519
)
35243520

35253521
detection_log = models.JSONField(
35263522
default=list,
35273523
blank=True,
35283524
help_text=_(
3529-
'A list of detection DetectionRule explaining how '
3530-
'this detection was created.'
3525+
"A list of detection DetectionRule explaining how "
3526+
"this detection was created."
35313527
),
35323528
)
35333529

35343530
identifier = models.CharField(
35353531
max_length=1024,
35363532
blank=True,
35373533
help_text=_(
3538-
'An identifier unique for a license detection, containing the license '
3539-
'expression and a UUID crafted from the match contents.'
3534+
"An identifier unique for a license detection, containing the license "
3535+
"expression and a UUID crafted from the match contents."
35403536
),
35413537
)
35423538

@@ -3552,10 +3548,11 @@ class DiscoveredLicense(
35523548
AbstractLicenseDetection,
35533549
):
35543550
"""
3555-
A project's Discovered Licenses are the unique License Detection objects
3551+
A project's Discovered Licenses are the unique License Detection objects
35563552
discovered in the code under analysis.
35573553
35583554
"""
3555+
35593556
license_expression_field = "license_expression"
35603557

35613558
# If this license was discovered in a extracted license statement
@@ -3573,10 +3570,10 @@ class DiscoveredLicense(
35733570
default=list,
35743571
blank=True,
35753572
help_text=_(
3576-
'A list of file regions with resource path, start and end line '
3577-
'details for each place this license detection was discovered at. '
3578-
'Also contains whether this license was discovered from a file or '
3579-
'from package metadata.'
3573+
"A list of file regions with resource path, start and end line "
3574+
"details for each place this license detection was discovered at. "
3575+
"Also contains whether this license was discovered from a file or "
3576+
"from package metadata."
35803577
),
35813578
)
35823579

@@ -3604,9 +3601,10 @@ def __str__(self):
36043601
@classmethod
36053602
def create_from_data(cls, project, detection_data):
36063603
"""
3607-
Create and returns a DiscoveredLicense for a `project` from the `detection_data`.
3608-
If one of the values of the required fields is not available, a "ProjectMessage"
3609-
is created instead of a new DiscoveredLicense instance.
3604+
Create and returns a DiscoveredLicense for a `project` from the
3605+
`detection_data`. If one of the values of the required fields is not
3606+
available, a "ProjectMessage" is created instead of a new
3607+
DiscoveredLicense instance.
36103608
"""
36113609
detection_data = detection_data.copy()
36123610
required_fields = ["license_expression", "identifier", "matches"]
@@ -3622,7 +3620,11 @@ def create_from_data(cls, project, detection_data):
36223620
f"{', '.join(missing_values)}"
36233621
)
36243622

3625-
project.add_warning(description=message, model=cls, details=detection_data)
3623+
project.add_warning(
3624+
description=message,
3625+
model=cls,
3626+
details=detection_data,
3627+
)
36263628
return
36273629

36283630
cleaned_data = {
@@ -3633,8 +3635,8 @@ def create_from_data(cls, project, detection_data):
36333635

36343636
discovered_license = cls(project=project, **cleaned_data)
36353637
# Using save_error=False to not capture potential errors at this level but
3636-
# rather in the CodebaseResource.create_and_add_license_data method so resource data
3637-
# can be injected in the ProjectMessage record.
3638+
# rather in the CodebaseResource.create_and_add_license_data method so
3639+
# resource data can be injected in the ProjectMessage record.
36383640
discovered_license.save(save_error=False, capture_exception=False)
36393641
return discovered_license
36403642

@@ -3644,7 +3646,7 @@ def update_with_file_region(self, file_region):
36443646
`file_regions` list and increase the `detection_count` by 1.
36453647
"""
36463648
file_region_data = file_region.to_dict()
3647-
if not file_region_data in self.file_regions:
3649+
if file_region_data not in self.file_regions:
36483650
self.file_regions.append(file_region_data)
36493651
if not self.detection_count:
36503652
self.detection_count = 1

scanpipe/pipes/__init__.py

Lines changed: 5 additions & 2 deletions
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")
@@ -247,7 +247,10 @@ def update_or_create_dependency(
247247

248248

249249
def update_or_create_license_detection(
250-
project, detection_data, resource_path, from_package=False,
250+
project,
251+
detection_data,
252+
resource_path,
253+
from_package=False,
251254
):
252255
"""
253256
Get, update or create a DiscoveredLicense object then return it.

scanpipe/pipes/input.py

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 8 deletions
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
@@ -460,12 +460,8 @@ def get_file_region(detection_data, resource_path):
460460
object containing information about where this license was detected
461461
exactly in a codebase, with `resource_path`, with start and end lines.
462462
"""
463-
start_line = min(
464-
[match['start_line'] for match in detection_data["matches"]]
465-
)
466-
end_line = max(
467-
[match['end_line'] for match in detection_data["matches"]]
468-
)
463+
start_line = min([match["start_line"] for match in detection_data["matches"]])
464+
end_line = max([match["end_line"] for match in detection_data["matches"]])
469465
return FileRegion(
470466
path=resource_path,
471467
start_line=start_line,
@@ -694,7 +690,7 @@ def create_discovered_licenses(project, scanned_codebase):
694690
"""
695691
Save the license detections of a ScanCode `scanned_codebase`
696692
scancode.resource.Codebase object to the database as a DiscoveredLicense of
697-
`project`.
693+
`project`.
698694
"""
699695
if hasattr(scanned_codebase.attributes, "license_detections"):
700696
for detection_data in scanned_codebase.attributes.license_detections:

scanpipe/views.py

Lines changed: 3 additions & 3 deletions
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
@@ -2009,7 +2009,7 @@ def get_context_data(self, **kwargs):
20092009
context = super().get_context_data(**kwargs)
20102010
context["dependency_data"] = DiscoveredDependencySerializer(self.object).data
20112011
return context
2012-
2012+
20132013

20142014
class DiscoveredLicenseDetailsView(
20152015
ConditionalLoginRequired,

0 commit comments

Comments
 (0)