-
-
Notifications
You must be signed in to change notification settings - Fork 27
Add Copyright class and copyright_diff() #82 #83 #85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
00b6e7a
f8f5861
f1c9f4d
59b502d
d2cb79d
195eb00
4199bcd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -199,21 +199,18 @@ def license_diff(self): | |
| old_licenses = delta.old_file.licenses or [] | ||
|
|
||
| if len(delta.new_file.licenses) > 0 and delta.old_file.licenses == []: | ||
| delta.factors.append('license info added') | ||
| delta.score += 20 | ||
| delta.add_score(20, 'license info added') | ||
| return | ||
|
|
||
| if delta.new_file.licenses == [] and len(delta.old_file.licenses) > 0: | ||
| delta.factors.append('license info removed') | ||
| delta.score += 15 | ||
| delta.add_score(15, 'license info removed') | ||
| return | ||
|
|
||
| new_keys = set(license.key for license in new_licenses) | ||
| old_keys = set(license.key for license in old_licenses) | ||
|
|
||
| if new_keys != old_keys: | ||
| delta.factors.append('license change') | ||
| delta.score += 10 | ||
| delta.add_score(10, 'license change') | ||
|
|
||
| def copyright_diff(self): | ||
| """ | ||
|
|
@@ -231,13 +228,10 @@ def copyright_diff(self): | |
| old_copyrights = delta.old_file.copyrights or [] | ||
|
|
||
| if len(delta.new_file.copyrights) > 0 and delta.old_file.copyrights == []: | ||
| delta.factors.append('copyright info added') | ||
| delta.score += 15 | ||
| delta.add_score(10, 'copyright info added') | ||
| return | ||
|
|
||
| if delta.new_file.copyrights == [] and len(delta.old_file.copyrights) > 0: | ||
| delta.factors.append('copyright info removed') | ||
| delta.score += 10 | ||
| elif delta.new_file.copyrights == [] and len(delta.old_file.copyrights) > 0: | ||
| delta.add_score(10, 'copyright info removed') | ||
| return | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably best that we score these the same. This will also allow for you to combine the logic into a single if statement |
||
|
|
||
| new_statements = set(statement for copyright in new_copyrights for statement in copyright.statements) | ||
|
|
@@ -246,14 +240,9 @@ def copyright_diff(self): | |
| new_holders = set(holder for copyright in new_copyrights for holder in copyright.holders) | ||
| old_holders = set(holder for copyright in old_copyrights for holder in copyright.holders) | ||
|
|
||
| new_authors = set(author for copyright in new_copyrights for author in copyright.authors) | ||
| old_authors = set(author for copyright in old_copyrights for author in copyright.authors) | ||
|
|
||
| if ((new_statements != old_statements) or | ||
| (new_holders != old_holders) or | ||
| (new_authors != old_authors)): | ||
| delta.factors.append('copyright change') | ||
| delta.score += 5 | ||
| (new_holders != old_holders)): | ||
| delta.add_score(5, 'copyright change') | ||
|
|
||
| def index_deltas(self, index_key='path', delta_list=[]): | ||
| """ | ||
|
|
@@ -291,6 +280,16 @@ def __init__(self, score=0, new_file=None, old_file=None): | |
| self.factors = [] | ||
| self.score = score | ||
|
|
||
| def add_score(self, score=0, factor=''): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. like stated above, this needs to be renamed to update. |
||
| """ | ||
| For each Delta object identified in DeltaCode.license_diff() or | ||
| DeltaCode.copyright_diff(), add the score to the object's 'score' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do not need ot mention these funtions here. Simply tell me what this update function does. |
||
| attribute and add a string, summarizing the factor associated with the | ||
| score, to the object's 'factors' attribute (a list). | ||
| """ | ||
| self.factors.append(factor) | ||
| self.score += score | ||
|
|
||
| def to_dict(self): | ||
| """ | ||
| Return an OrderedDict comprising the 'factors', 'score' and new and old | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -254,7 +254,6 @@ class Copyright(object): | |
| def __init__(self, dictionary={}): | ||
| self.statements = dictionary.get('statements') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you haven’t already, you should add tests cases where a files have large numbers of copyrights holders and statements to see if we choke somewhere, espically in the output
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also tests where there are strange characters or accent marks in the copyright statements/holders. All of these additional test cases I mentioned should probably come from scancode generated output directly as opposed to crafting the test object by hand.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @MaJuRG Since we want to use ScanCode-generated output, do you have any codebases in mind that satisfy the characteristics you describe? I've started to work my way through the codebases we've worked with (openssl, zlib et al.) but I've not yet seen large numbers of copyright holders/statements or unusual characters.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @johnmhoran You will probably just have to hand-create a file or files that contain a bunch of copyright statements
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK. Thanks, @MaJuRG .
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @MaJuRG I'm finding that an error is thrown when I include a French accent character in the copyright
While PEP 263 gives some suggestions, it's not clear to me how we can apply these to handle our input. I've done some searching in the ScanCode repo -- surely ScanCode must be able to handle such characters -- but have not yet found how ScanCode addresses this.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like this issue might be addressed in scancode-toolkit/src/commoncode/text.py?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @johnmhoran where is this "statements" located?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @MaJuRG Would it be easier for you if I commit and push? Except for this one failing test, it's ready for your review. |
||
| self.holders = dictionary.get('holders') | ||
| self.authors = dictionary.get('authors') | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like I mentioned above, lets remove authors. |
||
| def to_dict(self): | ||
| """ | ||
|
|
@@ -263,8 +262,7 @@ def to_dict(self): | |
| """ | ||
| d = OrderedDict([ | ||
| ('statements', self.statements), | ||
| ('holders', self.holders), | ||
| ('authors', self.authors) | ||
| ('holders', self.holders) | ||
| ]) | ||
|
|
||
| return d | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| Factors,Score,Path,Name,Type,Size,Old Path | ||
| modified license info added copyright info added,55,path.txt,path.txt,file,300, | ||
| modified license info added copyright info added,50,path.txt,path.txt,file,300, |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| Factors,Score,Path,Name,Type,Size,Old Path | ||
| modified copyright info added,35,path.txt,path.txt,file,300, | ||
| modified copyright info added,30,path.txt,path.txt,file,300, |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| Factors,Score,Path,Name,Type,Size,Old Path | ||
| modified license info removed copyright info added,50,path.txt,path.txt,file,300, | ||
| modified license info removed copyright info added,45,path.txt,path.txt,file,300, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be renamed to something like
delta.update.We are not only adding to the score, we are also adding to factors etc and possibly more in the future.