-
Notifications
You must be signed in to change notification settings - Fork 76
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
RequirementsInfoExtractor.py: Extract Project Dependency Info #159
Open
Wert1996
wants to merge
1
commit into
coala:master
Choose a base branch
from
Wert1996:extractRequirements
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
coala_quickstart/info_extractors/RequirementsInfoExtractor.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from requirements import parse | ||
|
||
from coala_quickstart.info_extraction.InfoExtractor import InfoExtractor | ||
from coala_quickstart.info_extraction.Information import ( | ||
ProjectDependencyInfo, VersionInfo) | ||
|
||
|
||
class RequirementsInfoExtractor(InfoExtractor): | ||
supported_file_globs = ("requirements.txt",) | ||
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. You do not use the preferred quotation marks. Origin: QuotesBear, Section: The issue can be fixed by applying the following patch: --- a/tmp/tmpcl3_n9ei/coala_quickstart/info_extractors/RequirementsInfoExtractor.py
+++ b/tmp/tmpcl3_n9ei/coala_quickstart/info_extractors/RequirementsInfoExtractor.py
@@ -6,7 +6,7 @@
class RequirementsInfoExtractor(InfoExtractor):
- supported_file_globs = ("requirements.txt",)
+ supported_file_globs = ('requirements.txt',)
supported_information_kinds = (
ProjectDependencyInfo, VersionInfo) |
||
|
||
supported_information_kinds = ( | ||
ProjectDependencyInfo, VersionInfo) | ||
|
||
def parse_file(self, fname, file_content): | ||
parsed_file = [] | ||
with open(fname, 'r') as f: | ||
parsed_file = parse(f) | ||
return parsed_file | ||
|
||
def find_information(self, fname, parsed_file): | ||
results = [] | ||
for dependency in parsed_file: | ||
results.append( | ||
ProjectDependencyInfo( | ||
fname, | ||
dependency.name, | ||
# FIXME: VersionInfo is a string, that stores only the | ||
# first version. | ||
version=VersionInfo(fname, | ||
''.join(''.join(dependency.specs[0]))) | ||
) | ||
) | ||
|
||
return results |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import os | ||
import unittest | ||
|
||
from coala_quickstart.info_extractors.RequirementsInfoExtractor import ( | ||
RequirementsInfoExtractor) | ||
from coala_quickstart.info_extraction.Information import ( | ||
ProjectDependencyInfo, VersionInfo) | ||
from tests.TestUtilities import generate_files | ||
|
||
|
||
test_file = """ | ||
# This is the file to test requirements extractor. | ||
# It should not parse this line. | ||
Babel<=2.3.4 | ||
Flask==0.11.1 # Everything after # must be ignored. | ||
Django>=1.5 # This is a comment. | ||
Django<1.4 | ||
Jinja~2.9.6 | ||
# Neither this. | ||
""" | ||
|
||
|
||
class RequirementsInfoExtractorTest(unittest.TestCase): | ||
This comment was marked as outdated.
Sorry, something went wrong. |
||
|
||
def setUp(self): | ||
self.current_dir = os.getcwd() | ||
|
||
def test_extracted_information(self): | ||
|
||
with generate_files( | ||
['requirements'], | ||
[test_file], | ||
self.current_dir) as gen_file: | ||
|
||
self.uut = RequirementsInfoExtractor( | ||
['requirements'], | ||
self.current_dir) | ||
extracted_info = self.uut.extract_information() | ||
extracted_info = extracted_info[ | ||
os.path.normcase('requirements') | ||
] | ||
|
||
information_types = extracted_info.keys() | ||
self.assertIn("ProjectDependencyInfo", information_types) | ||
dep_info = extracted_info['ProjectDependencyInfo'] | ||
self.assertEqual(len(dep_info), 4) | ||
|
||
requirements_list = [('Babel', '<=2.3.4'), | ||
('Flask', '==0.11.1'), | ||
('Django', '>=1.5'), | ||
('Jinja', '~2.9.6'), ] | ||
|
||
deps = [(dep.value, dep.version.value) for dep in dep_info] | ||
self.assertNotIn(('ignore_this', '<=2.4'), deps) | ||
|
||
for requirement in requirements_list: | ||
self.assertIn(requirement, deps) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as resolved.
Sorry, something went wrong.