-
Notifications
You must be signed in to change notification settings - Fork 580
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
bears/general: Add LicenseCheckBear #1442
Conversation
423b324
to
2c226ae
Compare
@Makman2 Appveyor build failing. However the circle ci and travis builds have passed. I have added the dependencies in .travis.yml and deps.sh. What could be the reason ? |
bears/general/LicenseCheckBear.py
Outdated
""" | ||
args = () | ||
if licensecheck_lines != 60: | ||
args += ('--lines', str(licensecheck_lines)) |
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.
Just give this directly, there's no need for a conditional statement.
bears/general/LicenseCheckBear.py
Outdated
|
||
@staticmethod | ||
def create_arguments(filename, file, config_file, | ||
licensecheck_lines: int = 60, |
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.
No spaces around the =
(see also the other lines below)
@@ -0,0 +1,78 @@ | |||
from queue import Queue | |||
import os.path |
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.
We usually just do import os
:)
Any particular reasons for import os.path
?
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.
Idk why I imported os.path 😆
def test_license(self): | ||
file_contents = [load_testfile( | ||
get_testfile_path('apache_license_2.py'))] | ||
test_file_path = get_testfile_path('apache_license_2.py') |
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.
move this one line above and reuse test_file_path
self.uut, | ||
file_contents, | ||
[Result.from_values('LicenseCheckBear', | ||
test_file_path + ': Apache (v2.0)', |
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.
Wait, this will return a result all the time? I thought this bear is something like "Make sure all files have this particular license; if not, return a result" and that it'll be quiet if a file is okay?
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.
Or is this a helper bear for other bears?
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.
Unlike other bears that check validity,
This bear attempts to determine the license that applies to each file passed to
it, by searching the start of the file for text belonging to various
licenses.
It will return a result all the time to determine not just the license but also the type of license.
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 is then definitely suited for a dependency bear imo, and we should add a bear that uses that information. Like a LicenseConsistencyBear
or so^^
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.
I'd never enable a bear that always returns results - it'll just clutter the output window. This should definitely be a dependency bear. And in that case, you should use HiddenResult
s instead of Result
s.
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.
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.
@linter
currently doesn't support yielding HiddenResult
s currently, you maybe want to implement support for it^^
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.
So, till the time yielding HiddenResult is implemented for linter bears, what do we do with this ?
Done @adtac |
bears/general/LicenseCheckBear.py
Outdated
:param licensecheck_check: | ||
Specify a pattern indicating which files should be checked. | ||
:param licensecheck_copyright: | ||
Display the file's copyright |
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.
I don't see what this is good for or even what it does
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.
We were actually planning to write a bear that would check for copyright notices in source files as mentioned here. However we have wrapped this functionality in a tool called as licensecheck
which determines the license that applies to each file and checks for copyright notices too (displays it if present).
bears/general/LicenseCheckBear.py
Outdated
Specify that files/directories matching the regular expression | ||
should be ignored when checking files. | ||
:param licensecheck_check: | ||
Specify a pattern indicating which files should be checked. |
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.
can you add examples? Solely from this description I'd not know how to use it
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.
We can remove this parameter too IMO because the user can explicitly specify it either by the --files argument or in the .coafile with the help of globs
bears/general/LicenseCheckBear.py
Outdated
for license information. | ||
:param licensecheck_ignore: | ||
Specify that files/directories matching the regular expression | ||
should be ignored when checking files. |
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 shouldn't be given, coala does ignoring and we shouldn't repeat the functionality as a setting
bears/general/LicenseCheckBear.py
Outdated
args += ('--lines', str(licensecheck_lines)) | ||
if licensecheck_copyright: | ||
args += ('--copyright',) | ||
return args + (filename,) |
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.
W292 no newline at end of file'
PycodestyleBear (W292), severity NORMAL, section autopep8
.
bears/general/LicenseCheckBear.py
Outdated
args += ('--lines', str(licensecheck_lines)) | ||
if licensecheck_copyright: | ||
args += ('--copyright',) | ||
return args + (filename,) |
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.
The code does not comply to PEP8.
PEP8Bear, severity NORMAL, section autopep8
.
The issue can be fixed by applying the following patch:
--- a/bears/general/LicenseCheckBear.py
+++ b/bears/general/LicenseCheckBear.py
@@ -34,4 +34,4 @@
args += ('--lines', str(licensecheck_lines))
if licensecheck_copyright:
args += ('--copyright',)
- return args + (filename,)+ return args + (filename,)
bears/general/LicenseCheckBear.py
Outdated
|
||
@linter(executable='licensecheck', | ||
output_format='regex', | ||
output_regex=r'(?P<filename>.*): (?P<copyright>.*)UNKNOWN', |
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.
unknown capturing groups, please remove them as coala will otherwise raise a warning on execution^^
bears/general/LicenseCheckBear.py
Outdated
class LicenseCheckBear: | ||
""" | ||
Attempts to check the given file for a license, by searching the start | ||
of the file for text belonging to various licenses. For Ubuntu/Debian |
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.
Would layout the docs like this:
Attempts to check the given file for a license, by searching the start
of the file for text belonging to various licenses.
For Ubuntu/Debian ...
As the Ubuntu/Debian part is detailed :) Rule of thumb: The first line/sentence is the short description which shall describe the bear as short as possible, everything following an empty line is detailed description :)
bears/general/LicenseCheckBear.py
Outdated
Attempts to check the given file for a license, by searching the start | ||
of the file for text belonging to various licenses. For Ubuntu/Debian | ||
users, the licensecheck_lines option has to be used in accordance with the | ||
licensecheck_tail option. |
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.
Enclose licensecheck_lines
and licensecheck_tail
in double backticks :)
bears/general/LicenseCheckBear.py
Outdated
:param licensecheck_lines: | ||
Specify how many lines of the file header should be parsed | ||
for license information. Set to 0 to parse the whole | ||
file (and ignore licensecheck_tail). |
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.
Enclose licensecheck_tail
in double backticks
bears/general/LicenseCheckBear.py
Outdated
file (and ignore licensecheck_tail). | ||
:param licensecheck_tail: | ||
Specify how many bytes to parse at end of file. Set to 0 to | ||
avoid parsing from end of file. |
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.
Would rephrase to
Set to 0 to disable parsing from end of file.
bears/general/LicenseCheckBear.py
Outdated
avoid parsing from end of file. | ||
""" | ||
return '--lines', str(licensecheck_lines), '--tail', \ | ||
str(licensecheck_tail), filename |
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.
use braces instead of \
:
return ('--lines', ..., ...,
'folllowing-args', ...)
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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.
what about adding some code to these files?
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.
(to some of them)
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.
Added some code too and update the regex. :D
def add_two_numbers(a, b): | ||
return a + b | ||
|
||
print(add_two_numbers(4, 5)) |
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.
E305 expected 2 blank lines after class or function definition, found 1'
PycodestyleBear (E305), severity NORMAL, section autopep8
.
Done @Makman2 :) |
bears/general/LicenseCheckBear.py
Outdated
of the file for text belonging to various licenses. | ||
|
||
For Ubuntu/Debian users, the `licensecheck_lines` option has to be used in | ||
accordance with the `licensecheck_tail` option. |
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.
we use double backticks, and I'm not sure if RST handles single ones properly. Could you change that everywhere? :)
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.
I'm sorry. :(
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.
Fixed. :)
bears/general/LicenseCheckBear.py
Outdated
file (and ignore `licensecheck_tail`). | ||
:param licensecheck_tail: | ||
Specify how many bytes to parse at end of file. Set to 0 to disable | ||
parsing from end of file. |
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.
indentation off
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.
How did I forget that. 😕
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.
Fixed. :)
'No license found.', | ||
file=get_testfile_path('no_license.py'))], | ||
filename=get_testfile_path('no_license.py'), | ||
settings={'licensecheck_lines': 'int = 10'}) |
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.
int = 10
?
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.
I think you mean just '10'
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.
will check the first 10 lines and parse 5000 bytes from the bottom of the file. :)
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.
but the int
is invalid, isn't it? it's parsed as a string then^^
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.
Yes @Makman2 , you are absolutely correct, actually I had copied that statement from the docs and added quotes because of some error in haste. Have filed an issue for the same. :D
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.
:)
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.
Fixed*
a62fdf5
to
6f06fc4
Compare
bears/general/LicenseCheckBear.py
Outdated
|
||
@linter(executable='licensecheck', | ||
output_format='regex', | ||
output_regex=r'(^(.*/)*)([^/]*): .*UNKNOWN$', |
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.
for paths I would use .*
, as this may not work on windows ;)
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.
(we maybe need some regex composition library, where you could do something like regexes.path + r': .*UNKNOWN$'
)
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.
(just an idea, don't seach for one ;D)
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.
I had the same thought initially but we don't have support for windows so..
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.
So now our bear is future proof. :D
Done @Makman2 :D |
ack 01d4f24 |
@rultor merge |
|
||
@linter(executable='licensecheck', | ||
output_format='regex', | ||
output_regex=r'.*: .*UNKNOWN$', |
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.
sigh.
The first .*
should have been something like [^:]+
.
Closes #823
For short term contributors: we understand that getting your commits well
defined like we require is a hard task and takes some learning. If you
look to help without wanting to contribute long term there's no need
for you to learn this. Just drop us a message and we'll take care of brushing
up your stuff for merge!
Checklist
them.
individually. It is not sufficient to have "fixup commits" on your PR,
our bot will still report the issues for the previous commit.) You will
likely receive a lot of bot comments and build failures if coala does not
pass on every single commit!
After you submit your pull request, DO NOT click the 'Update Branch' button.
When asked for a rebase, consult coala.io/rebase
instead.
Please consider helping us by reviewing other peoples pull requests as well:
cobot mark wip <URL>
to get it outof the review queue.
The more you review, the more your score will grow at coala.io and we will
review your PRs faster!