Skip to content

Add new fingerprint plugin - #1576

Closed
arnav-mandal1234 wants to merge 224 commits into
aboutcode-org:developfrom
arnav-mandal1234:gsoc_fingerprint
Closed

Add new fingerprint plugin#1576
arnav-mandal1234 wants to merge 224 commits into
aboutcode-org:developfrom
arnav-mandal1234:gsoc_fingerprint

Conversation

@arnav-mandal1234

Copy link
Copy Markdown
Contributor

Signed-off-by: arnav-mandal1234 arnav.mandal1234@gmail.com

Li added 2 commits May 27, 2019 21:23
Signed-off-by: Li <li@nexb.com>
Signed-off-by: Li <li@nexb.com>
Comment thread src/commoncode/fingerprint.py Outdated
@codecov

codecov Bot commented May 31, 2019

Copy link
Copy Markdown

Codecov Report

Merging #1576 into develop will decrease coverage by 2.05%.
The diff coverage is 43.07%.

Impacted file tree graph

@@            Coverage Diff             @@
##           develop   #1576      +/-   ##
==========================================
- Coverage    84.35%   82.3%   -2.06%     
==========================================
  Files          124     126       +2     
  Lines        14594   14659      +65     
==========================================
- Hits         12311   12065     -246     
- Misses        2283    2594     +311
Impacted Files Coverage Δ
src/commoncode/fingerprint.py 19.51% <19.51%> (ø)
src/scancode/api.py 72.78% <50%> (-22.32%) ⬇️
src/cluecode/plugin_fingerprint.py 90% <90%> (ø)
src/scancode/extract_cli.py 32% <0%> (-56%) ⬇️
src/scancode/plugin_only_findings.py 52% <0%> (-48%) ⬇️
src/scancode/plugin_ignore.py 30.9% <0%> (-45.46%) ⬇️
src/scancode/plugin_mark_source.py 56.25% <0%> (-40.63%) ⬇️
src/scancode/interrupt.py 32.89% <0%> (-11.85%) ⬇️
src/scancode/resource.py 75.14% <0%> (-10.84%) ⬇️
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 40e7192...cfcd73f. Read the comment docs.

@codecov

codecov Bot commented May 31, 2019

Copy link
Copy Markdown

Codecov Report

Merging #1576 into develop will decrease coverage by 0.53%.
The diff coverage is 70.73%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1576      +/-   ##
===========================================
- Coverage     81.7%   81.16%   -0.54%     
===========================================
  Files          126      125       -1     
  Lines        15333    15478     +145     
===========================================
+ Hits         12528    12563      +35     
- Misses        2805     2915     +110
Impacted Files Coverage Δ
src/cluecode/copyrights.py 92.37% <ø> (-0.28%) ⬇️
src/formattedcode/output_spdx.py 89.67% <100%> (-4.25%) ⬇️
src/commoncode/command.py 81.1% <58.82%> (-5.34%) ⬇️
src/extractcode/sevenzip.py 82.64% <60%> (-0.23%) ⬇️
src/commoncode/fileutils.py 79.55% <73.07%> (-3.42%) ⬇️
src/commoncode/codec.py 74.35% <73.33%> (-21.8%) ⬇️
src/formattedcode/output_html.py 87.26% <0%> (-7.65%) ⬇️
src/licensedcode/match.py 79.15% <0%> (-4.85%) ⬇️
src/textcode/markup.py 93.47% <0%> (-4.35%) ⬇️
... and 17 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8b64c93...3ec7854. Read the comment docs.

Li added 5 commits June 2, 2019 03:54
Signed-off-by: Li <li@nexb.com>
Signed-off-by: Li <li@nexb.com>
Signed-off-by: Li <li@nexb.com>
Signed-off-by: Li <li@nexb.com>
Signed-off-by: Li <li@nexb.com>
Comment thread src/cluecode/plugin_fingerprint.py Outdated
options = [
CommandLineOption(('-f', '--fingerprint'),
is_flag=True, default=False,
help='Scan <input> to generate fingerprint.',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to be a bit more descriptive here and state why kind(s) of fingerprints the -f flag will generate.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaJuRG Okay. Since it is a very descriptive answer to your question, it would not be the right place to keep it IMHO. Can you please suggest me how should I frame it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. It does not have to be in-depth, but even just adding the name of the fingerprint or something like ... to generate simhash fingerprints for use in similarity matching. Something like that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. will change it.

Comment thread src/commoncode/fingerprint.py Outdated
import hashlib

hash_length = 128
shingle_length = 3

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Standard convention for constants like these should be all caps: HASH_LENGTH, SHINGLE_LENGTH to distinguish them from other variables.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Will change it.

{
"path": "factorial-test.java",
"type": "file",
"fingerprint": "00000001110011111011010000110111101011001110110100111111011111011000111001000001100001001111010011011000011001110011000100100111",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there another way to store this fingerprint, or does it have to be a binary string? The length of these fingerprints is unsightly IMO.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arnav-mandal1234 Store the fingerprint as a hex string instead of a binary string

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaJuRG @JonoYang We can keep the fingerprint in hex but then we have to shift most of the code to the delta code repo and do the computation there. Would it be the right thing to do it?

@steven-esser steven-esser Jun 11, 2019

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We just want to calcuate the fingerprints for each file in scancode-toolkit. When it comes to the actual comparison aspect, that will be handled in deltacode (calculating the hamming distance, etc). I do not think we have to move any code over, correct? The additions you made were simply to:

  1. create the fingerprint for each file
  2. add it to scan output

When we go to actually check two separate scan output files, deltacode will be doing those comparisons. Does this make sense?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaJuRG Yes. That is what in the back of my mind too.
Sorry I misunderstood @JonoYang 's comment. So, basically you want these fingerprints to be in hex. then after we get these hex string on the deltacode side, we again convert them to binary and calculate hamming distance. Right?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Comment thread tests/commoncode/test_fingerprint.py Outdated
def test_generate_fingerprint1(self):
test_file = self.get_test_loc('fingerprint/fingerprint-test1.java')
result = generate_fingerprint(test_file)
assert result == '01001110010000101101100011000000111011010110011010010011011001010100100001100110010000100101010001010001001000010000010000010111'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above. Is there another way to store this fingerprint?

@steven-esser

Copy link
Copy Markdown
Contributor

@pombredanne @JonoYang Your review would be welcome as well.

Comment thread src/commoncode/fingerprint.py Outdated
weighted_list = get_weightedlist(token_list)
fingerprint = process_weightedlist(weighted_list)

return "".join(str(bit) for bit in fingerprint)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style note: we use single quotes ' when declaring strings.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JonoYang sure will change this.

{
"path": "factorial-test.java",
"type": "file",
"fingerprint": "00000001110011111011010000110111101011001110110100111111011111011000111001000001100001001111010011011000011001110011000100100111",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arnav-mandal1234 Store the fingerprint as a hex string instead of a binary string

Signed-off-by: Li <li@nexb.com>
@pombredanne pombredanne changed the title Adds new fingerprint plugin Add new fingerprint plugin Jun 11, 2019

@pombredanne pombredanne left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few general questions: do we want this as a built-in plugin that is always available? or is this an external plugin?

Also I am sure that cluecode is not the right module for this: until now this was about copyrights and "greps" only.

I made several comments inline too.

Comment thread src/cluecode/plugin_fingerprint.py Outdated
@@ -0,0 +1,60 @@
#
# Copyright (c) 2018 nexB Inc. and others. All rights reserved.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are in 2019 alright. But having no year is probably best

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure will change this.

Comment thread src/cluecode/plugin_fingerprint.py Outdated
return fingerprint

def get_scanner(self, **kwargs):
from scancode.api import get_fingerprint

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The scancode.api module is a legacy wart. Avoid using this for this code. Instead put it all in this same module here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pombredanne should I shift it to the commoncode/fingerprint.py?

Comment thread src/commoncode/fingerprint.py Outdated

def generate_fingerprint(location):
"""
Return fingerprint of the file at `location`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theer 4 extra spaces to remove in from the Return

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure will change this.

Comment thread src/commoncode/fingerprint.py Outdated
"""
Return fingerprint of the file at `location`.
"""
token_list = get_tokenlist(location)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you qualify each variable and functions with a type?
You should have instead tokens = get_tokens(location) here and in other similar places below and elsewhere

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. will change all the similar variable and function names.

Comment thread src/commoncode/fingerprint.py Outdated

def get_tokenlist(location):
"""
Return a list of tokens for the file at `location`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove 4 extra spaces.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. Will do that.

Comment thread src/commoncode/fingerprint.py Outdated
Comment thread src/scancode/api.py Outdated

from commoncode.filetype import get_last_modified_date
from commoncode.hash import multi_checksums
from commoncode.fingerprint import generate_fingerprint

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import needs to be properly ordered

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In sorted order?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes sorted alphabetically

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. will change it.

Comment thread src/scancode/api.py Outdated
result['is_script'] = bool(collector.is_script)
return result

def get_fingerprint(location, **kwargs):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not put this code in this module. Keep it with your plugin instead

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure will keep this in commoncode/fingerprint.py

@@ -0,0 +1,15 @@
public class Factorial

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you include real code and text and data files as tests rather than only made up ones?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I didn't get you. Please explain. :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

He means you should use actual source found in the wild, like code from an open source repository.

This is a better representation of files scancode will actually come across in the wild.

There should also be a verity of these, differing in lines of code AND language.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I will change it then. :)

Comment thread tests/commoncode/test_fingerprint.py Outdated
@@ -0,0 +1,114 @@
#

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this under commoncode when your plugin is in cluecode?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, all the main functions are in commoncode i.e. fingerprint.py. And the plugin is in cluecode. what should be the structure? should I move everything to commoncode?

Li added 3 commits June 11, 2019 23:08
Signed-off-by: Li <li@nexb.com>
Signed-off-by: Li <li@nexb.com>
Comment thread src/cluecode/plugin_fingerprint.py
Comment thread src/commoncode/fingerprint.py Outdated
Comment thread src/scancode/fingerprint.py Outdated
Comment thread src/scancode/fingerprint.py Outdated
Comment thread src/scancode/fingerprint.py Outdated
Comment thread tests/scancode/data/plugin_fingerprint/fingerprints.expected.json Outdated
Comment thread src/scancode/fingerprint.py Outdated
Comment thread src/scancode/fingerprint.py Outdated
Abhishek-Dev09 and others added 4 commits June 20, 2019 13:00
Unicode string literals are simply converted into string literals, which
are always Unicode in Python 3.

Unicode raw strings (in which Python does not auto-escape backslashes)
are converted to raw strings. In Python 3, raw strings are always
Unicode.

Signed-off-by: Abhishek Kumar <abhishek.kasyap09@gmail.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
range() is now its own generator-like class in Python 3 and was a list
in Python2. We now handle what is a generator-like object properly
on both versions.

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
For now run only the commoncode tests on Python 2.7 to tune the setup

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
pombredanne and others added 25 commits July 11, 2019 16:15
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
These are in the form of:
First Last <email> (c) year

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Add new License rules and licenses
Signed-off-by: arnav-mandal1234 <arnav.mandal1234@gmail.com>
Signed-off-by: arnav-mandal1234 <arnav.mandal1234@gmail.com>
Signed-off-by: arnav-mandal1234 <arnav.mandal1234@gmail.com>
…rithm

Signed-off-by: arnav-mandal1234 <arnav.mandal1234@gmail.com>
Signed-off-by: arnav-mandal1234 <arnav.mandal1234@gmail.com>
Signed-off-by: arnav-mandal1234 <arnav.mandal1234@gmail.com>
Signed-off-by: arnav-mandal1234 <arnav.mandal1234@gmail.com>
Signed-off-by: arnav-mandal1234 <arnav.mandal1234@gmail.com>
Signed-off-by: arnav-mandal1234 <arnav.mandal1234@gmail.com>
Signed-off-by: arnav-mandal1234 <arnav.mandal1234@gmail.com>
Signed-off-by: arnav-mandal1234 <arnav.mandal1234@gmail.com>
Signed-off-by: arnav-mandal1234 <arnav.mandal1234@gmail.com>
Signed-off-by: arnav-mandal1234 <arnav.mandal1234@gmail.com>
Signed-off-by: arnav-mandal1234 <arnav.mandal1234@gmail.com>
Signed-off-by: arnav-mandal1234 <arnav.mandal1234@gmail.com>
Signed-off-by: arnav-mandal1234 <arnav.mandal1234@gmail.com>
Signed-off-by: arnav-mandal1234 <arnav.mandal1234@gmail.com>
@pombredanne

Copy link
Copy Markdown
Member

@arnav-mandal1234 there seems to be something rather wrong with this PR and its 6710 modified files! is there some issues with your rebasing?

@arnav-mandal1234

Copy link
Copy Markdown
Contributor Author

@arnav-mandal1234 there seems to be something rather wrong with this PR and its 6710 modified files! is there some issues with your rebasing?

@pombredanne Something went wrong. I had opened a new PR with the same changes and it got merged. :)
You can close this PR or if you want I can do that.

@steven-esser

Copy link
Copy Markdown
Contributor

@pombredanne This can be closed. #1651 was merged and was the replacement for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants