Skip to content

[WIP]integrated with Virtualcodebase of scancode(First Approach) - #151

Closed
pratik0316 wants to merge 18 commits into
aboutcode-org:developfrom
pratik0316:VirtualCodebase
Closed

[WIP]integrated with Virtualcodebase of scancode(First Approach)#151
pratik0316 wants to merge 18 commits into
aboutcode-org:developfrom
pratik0316:VirtualCodebase

Conversation

@pratik0316

Copy link
Copy Markdown
Collaborator

In this PR I integrated the virtualcodebases of Scancode to the Deltacode.

Signed-off-by: Pratikrocks <pratikrocks.dey11@gmail.com>
…re_no_lic_change and test_Delta_one_None

Signed-off-by: Pratikrocks <pratikrocks.dey11@gmail.com>
Signed-off-by: Pratikrocks <pratikrocks.dey11@gmail.com>
Signed-off-by: Pratikrocks <pratikrocks.dey11@gmail.com>
Comment thread src/deltacode/__init__.py Outdated
Comment on lines +55 to +56
except :
pass

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 want to handle the exception properly

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@MaJuRG okay.
The exceptions were raised when we are getting some invalid sacn paths , and when we counter some some attributes like "fiingerprint" which VirtualCodebase is not supporting

Comment thread src/deltacode/__init__.py Outdated
Comment on lines +57 to +62
self.new_files_count = 0 #keeps the count of the new file
self.old_files_count = 0 #keeps the count of old files
self.new_files = [] # a list of [[new file1:Original path],[new file2:Original Path],...]
self.old_files = [] # a list of [[old file1:Original path],[old file2:Original Path],...]
self.new_files_fingerprint = dict() # map of { {new_file1:fingerprint},{new_file2:fingerprint},...} it will be needed when we need the fingerprints
self.old_files_fingerprint = dict() # map of { {old_file1:fingerprint},{old_file2: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.

What is all this stuff and why is it needed?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

self.new_files_count and self.old_files_count is to keep the track of the new files ,and old files.
I have added this to make the computation of the statistics easier,otherwise we would have to enumerate the virtual codebase objects to get the cont every time.
self.new_files_fingerprint and self.old_files_fingerprint it keeps a mapping of Resource objects files path from codebase1 and codebase2 with respect to the fingerprints which would be used in similarity comparisons.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@MaJuRG self.new_files and self.old_files it is list of lists comprising of [Resource objects,with their original path] ,Now we need to keep the track of the original path in the align_scans for alignment of the files.

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.

Its fine to enumerate on the Virtualcodebase. Stats should be calculated in the end anyway, and optionally for the user. I hate having carrying around all these unneeded fields.

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.

Also, codebase objects have counts already that we can use. There is no need to track this twice.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@MaJuRG , yes we can get rid of this self.new_files_count and self.old_files_count as they are already present in codebase objects as it is present in the headers of the codebase objects, but for the old files and new files and the fingerprint, I think it is better to have the enumeration done one time and cache those files in an array, else we will again need to enumerate it whenever required.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@MaJuRG used the counts from the codebase , removed the additional variables for the files_count

…and non similarity matching

Signed-off-by: Pratikrocks <pratikrocks.dey11@gmail.com>
@pratik0316

Copy link
Copy Markdown
Collaborator Author

@MaJuRG the test cases like (similarity matching1 and similarity matching2 ,non similarity matching1 ) are passing, the output in json file is appearing as expected.
However the code for this kinda test cases can not be modified

    def test_Delta_create_object_removed(self):
        new = None
        old = models.File({'path': 'path/removed.txt'})

        delta = deltacode.Delta(0, new, old)
        delta.factors.append('removed')

        assert type(delta.new_file) == type(None)
        assert delta.old_file.path == 'path/removed.txt'
        assert 'removed' in delta.factors
        assert delta.score == 0

as they are treating the old and new file as File objects and we are using the ScannedResources object for the old and the file.So should I modify test case like this?

Signed-off-by: Pratikrocks <pratikrocks.dey11@gmail.com>
Signed-off-by: Pratikrocks <pratikrocks.dey11@gmail.com>
Signed-off-by: Pratikrocks <pratikrocks.dey11@gmail.com>
@pratik0316

Copy link
Copy Markdown
Collaborator Author

@MaJuRG , I replaced some of the json files which were scanned with ScanCode version 2 with approximately similar files scanned with Scancode Version 3 link , and modified some of the test cases.
This resulted in passing the pytests for test_cli.py.
Kindly review the changes once :)

@steven-esser steven-esser left a comment

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.

There is a lot to be done here before it can be considered for merging.

Comment thread src/deltacode/__init__.py Outdated
Comment on lines +58 to +59
except Exception as exception:
click.secho(exception.message ,fg = "red")

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.

What exact exceptions can occur here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@MaJuRG , the error faced here are following two types:
1.When the paths of the json files for the are not valid.
2.When the VirtualCode base gets an unnecessary fields during the scanning .
However the 2nd error could be resolved if we use scancode versionn3 during the scanning of the json files.

Comment thread src/deltacode/__init__.py Outdated
Comment on lines +57 to +62
self.new_files_count = 0 #keeps the count of the new file
self.old_files_count = 0 #keeps the count of old files
self.new_files = [] # a list of [[new file1:Original path],[new file2:Original Path],...]
self.old_files = [] # a list of [[old file1:Original path],[old file2:Original Path],...]
self.new_files_fingerprint = dict() # map of { {new_file1:fingerprint},{new_file2:fingerprint},...} it will be needed when we need the fingerprints
self.old_files_fingerprint = dict() # map of { {old_file1:fingerprint},{old_file2: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.

Its fine to enumerate on the Virtualcodebase. Stats should be calculated in the end anyway, and optionally for the user. I hate having carrying around all these unneeded fields.

Comment thread src/deltacode/__init__.py Outdated

if self.new.path != '' and self.old.path != '':

if self.codebase1 != None and self.codebase2 != None:

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.

Can we just have a check for the inverse of this so we dont write everything under an unneeded indentation?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@MaJuRG yeah , trying for it , I think it would be a better approach

Comment thread src/deltacode/__init__.py Outdated
Comment on lines +102 to +108
try :
self.new_files_fingerprint[obj.path] = obj.fingerprint
except AttributeError:
self.new_files_fingerprint[obj.path] = None
if obj.is_file:
# increment the new files count
self.new_files_count += 1

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.

Why not use dict.get() method instead of catching exception?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@MaJuRG it would be nice , changing it

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@MaJuRG , the dict.get() method can not be used here as obj is not a dictionary it is a Virtualcodebase object.

Comment thread src/deltacode/__init__.py Outdated
Comment on lines +122 to +127
def enumerate_files_from_codebases(self):
"""
An method which call the utility function get_files for generating the codebase
"""
self.get_files(self.codebase1,is_new = True)
self.get_files(self.codebase2,is_new = False)

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.

This function's name is unrelated to what it actually does.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@MaJuRG , I think interchanging the function names get_files and enumerate_files_from_codebases would better match with the situation

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

changed the function name

Comment thread src/deltacode/__init__.py Outdated
Comment on lines +57 to +62
self.new_files_count = 0 #keeps the count of the new file
self.old_files_count = 0 #keeps the count of old files
self.new_files = [] # a list of [[new file1:Original path],[new file2:Original Path],...]
self.old_files = [] # a list of [[old file1:Original path],[old file2:Original Path],...]
self.new_files_fingerprint = dict() # map of { {new_file1:fingerprint},{new_file2:fingerprint},...} it will be needed when we need the fingerprints
self.old_files_fingerprint = dict() # map of { {old_file1:fingerprint},{old_file2: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.

Also, codebase objects have counts already that we can use. There is no need to track this twice.

Comment thread src/deltacode/__init__.py Outdated
all_licenses.append(d)
return all_licenses

def new_file_to_dict(self,deltacode):

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.

Why is this not a method of the File class?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@MaJuRG , I will be moving all these methods(license and copyright) to the file class

Comment thread src/deltacode/__init__.py Outdated
])


def old_file_to_dict(self,deltacode):

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.

Why are we repeating this function?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@MaJuRG , I will be truncating this unnecessary functions.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

combined redundant functions def old_file_to_dict(self,deltacode) and def new_file_to_dict(self,deltacode) , to a single function.

@pratik0316

Copy link
Copy Markdown
Collaborator Author

Thanks @MaJuRG for the review , I will be making the suggested changes ASAP :)

@pratik0316 pratik0316 changed the title integrated with Virtualcodebase of scancode(First Approach) [WIP]integrated with Virtualcodebase of scancode(First Approach) Apr 23, 2020
Signed-off-by: Pratikrocks <pratikrocks.dey11@gmail.com>
Signed-off-by: Pratikrocks <pratikrocks.dey11@gmail.com>
Signed-off-by: Pratikrocks <pratikrocks.dey11@gmail.com>
Signed-off-by: Pratikrocks <pratikrocks.dey11@gmail.com>
Signed-off-by: Pratikrocks <pratikrocks.dey11@gmail.com>


def fetch_files(location):
codebase = VirtualCodebase(location)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This function has been extensively added to test_utils so as to prevent the creation of deltacode object for the test cases when only the Resource files are required

Signed-off-by: Pratikrocks <pratikrocks.dey11@gmail.com>
…te one

Signed-off-by: Pratikrocks <pratikrocks.dey11@gmail.com>
Signed-off-by: Pratikrocks <pratikrocks.dey11@gmail.com>
Signed-off-by: Pratikrocks <pratikrocks.dey11@gmail.com>
Signed-off-by: Pratikrocks <pratikrocks.dey11@gmail.com>
@steven-esser

Copy link
Copy Markdown
Contributor

Closing for now due to stagnation.

@pratik0316

Copy link
Copy Markdown
Collaborator Author

I was willing to continue this , due to lack of input I discontinued for a moment , anyway if it's anymore required I will work on it :)

@steven-esser

Copy link
Copy Markdown
Contributor

@Pratikrocks Yes this may have fallen through the cracks, sorry about this lack of feedback.

The deltacode repo has been updated since this PR was made with a number of configuration changes. If you can, please rebase your branch, or add your changes to a new branch off of the current develop HEAD. I will make sure to leave prompt feedback if you do!

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.

2 participants