Skip to content
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

WIP ImageDimensionBear: Add ImageDimensionBear to coala-bears #1288

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rhemon
Copy link
Contributor

@rhemon rhemon commented Jan 10, 2017

Closes #1260

I have made the bear and written unittest for the bear as well. I am doing this PR to confirm what I have done till now is fine.
Another reason for making this WIP is because I still have to handle files for the bear. This is a GlobalBear and doesnt need any file, however I am unable to run the bear without a file. Presently .coafile has to look something like this to run ImageDimensionBear:

[default]
bears = ImageDimensionBear
files = .coafile
img_config = src/*.png 240 240, img/*.jpg 400 400

now here I think files is unnecessary and want to remove this but not sure how to.

Herer's how the it looks when I run the bear: http://pastebin.com/UebXyuiE
& the Test:

(venv) MBPs-MacBook-Pro:coala-bears rhemon$  /Users/mbp13inch/Documents/Workspace/venv/bin/py.test tests/general/ImageDimensionBearTest.py
================================================== test session starts ===================================================
platform darwin -- Python 3.5.2, pytest-3.0.5, py-1.4.32, pluggy-0.4.0
rootdir: /Users/mbp13inch/Documents/Workspace/coala-bears, inifile: setup.cfg
plugins: cov-2.4.0, env-0.6.0, timeout-1.2.0, xdist-1.15.0
timeout: 35.0s method: signal
collected 4 items 

tests/general/ImageDimensionBearTest.py ....

=============================================== 4 passed in 29.30 seconds ================================================

@gitmate-bot
Copy link
Collaborator

Thanks for your contribution!

Reviewing pull requests take really a lot of time and we're all volunteers. Please make sure you go through the following check list and complete them all before pinging someone for a review.

As you learn things over your Pull Request please help others on the chat and on PRs to get their stuff right as well!

@gitmate-bot
Copy link
Collaborator

Comment on 0498502.

Shortlog of the HEAD commit contains 57 character(s). This is 7 character(s) longer than the limit (57 > 50).

GitCommitBear, severity NORMAL, section commit.

@rhemon rhemon force-pushed the img-dimension-bear branch from 0498502 to d6c7738 Compare January 11, 2017 01:34
@jayvdb
Copy link
Member

jayvdb commented Jan 11, 2017

Regarding your general problem of files, we still do want to use files here.
Currently you have one .coafile setting image_config, which include multiple pieces of information, including filenames.

So the first step is splitting image_config into multiple settings.

-    def run(self, image_config):
+    def run(self, files, image_width, image_height):

The benefit is that the user only needs to set files and two numerical values. nice and simple to configure.
(Of course this means your job is harder, as you need to convert files into the linters yaml, but .. that is the job of a bear -- making linting easy)

This approach has one weakness compared to your image_config strategy, which is that each .coafile section can only have one width & height.

The result is that the user needs to create multiple .coafile sections for different sets of images.
The 'cost' is multiple invocations of the ruby interpreter; one for each section.

@jayvdb jayvdb mentioned this pull request Jan 11, 2017
@rhemon rhemon force-pushed the img-dimension-bear branch from d6c7738 to 31d4c0e Compare January 11, 2017 01:48
@rhemon rhemon force-pushed the img-dimension-bear branch 5 times, most recently from 459f081 to 40e5886 Compare January 11, 2017 02:47
Gemfile Outdated
@@ -7,3 +7,5 @@ gem 'scss_lint', require: false# require flag is necessary https://github.com/br
gem "reek"
gem "puppet-lint"
gem "csvlint"
gem "img_checker"
gem "fastimage"
Copy link
Member

Choose a reason for hiding this comment

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

why do we need this? doesnt img_checker declare a dependency on fastimage?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure, but I was having problem in running it, so I added it, and then it started working

Choose a reason for hiding this comment

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

You don't need to add fast_image.

'height': int(each[2])}]
yaml.dump(config, yaml_file, default_flow_style=False)

cmd = 'ruby -r "img_checker.rb" -e '
Copy link
Member

Choose a reason for hiding this comment

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

no need for double quotes, as there are no space characters in the filename.


AUTHORS = {'The coala developers'}
AUTHORS_EMAILS = {'[email protected]'}
REQUIREMENTS = {GemRequirement(' img_checker'),
Copy link
Member

Choose a reason for hiding this comment

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

This workaround is OK for a WIP, but you need to solve the bug in GemRequirement before this bear will be merge-able.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@robbyoconnor
Copy link

FYI I made changes in abishekvashok/img_checker#22 -- soon as @Abhi2424shek merges and it deploys.

It added an executable. so you type img_checker and it will just work(tm).

Copy link

@robbyoconnor robbyoconnor left a comment

Choose a reason for hiding this comment

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

Good work -- a few things not needed. See comments.

Gemfile Outdated
@@ -7,3 +7,5 @@ gem 'scss_lint', require: false# require flag is necessary https://github.com/br
gem "reek"
gem "puppet-lint"
gem "csvlint"
gem "img_checker"
gem "fastimage"

Choose a reason for hiding this comment

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

You don't need to add fast_image.

yaml.dump(config, yaml_file, default_flow_style=False)

cmd = 'ruby -r "img_checker.rb" -e '
cmd += '"ImgChecker.new.initialize img_config.yml"'

Choose a reason for hiding this comment

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

Not needed since soon as abishekvashok/img_checker#22 is merged -- it should "just work"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

is that also updated in the gem? it would be easier if so. will do the changes once its merged. thanks for informing :)

Choose a reason for hiding this comment

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

I didn't up the version number, that's for them to decide. I just cleaned things up.

@rhemon rhemon force-pushed the img-dimension-bear branch from 40e5886 to e0d6747 Compare January 12, 2017 01:06

with open('img_config.yml', 'w') as yaml_file:
config = [{'directory': image_file,
'width': width,
Copy link
Collaborator

Choose a reason for hiding this comment

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

E127 continuation line over-indented for visual indent'

PycodestyleBear (E127), severity NORMAL, section autopep8.


with open('img_config.yml', 'w') as yaml_file:
config = [{'directory': image_file,
'width': width,
Copy link
Collaborator

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/ImageDimensionBear.py
+++ b/bears/general/ImageDimensionBear.py
@@ -30,8 +30,8 @@
 
         with open('img_config.yml', 'w') as yaml_file:
             config = [{'directory': image_file,
-                           'width': width,
-                           'height': height}]
+                       'width': width,
+                       'height': height}]
             yaml.dump(config, yaml_file, default_flow_style=False)
         cmd = 'img_checker'
         output = run(cmd, stdout=Capture(), stderr=Capture())

@rhemon rhemon force-pushed the img-dimension-bear branch 2 times, most recently from e94a8ad to 7e42486 Compare January 12, 2017 03:30
shutil.which = lambda *args, **kwargs: 'path/to/git'
self.assertTrue(ImageDimensionBear.check_prerequisites())
finally:
shutil.which = _shutil_which
Copy link
Collaborator

Choose a reason for hiding this comment

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

W291 trailing whitespace'

PycodestyleBear (W291), severity NORMAL, section autopep8.

shutil.which = lambda *args, **kwargs: 'path/to/git'
self.assertTrue(ImageDimensionBear.check_prerequisites())
finally:
shutil.which = _shutil_which
Copy link
Collaborator

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/tests/general/ImageDimensionBearTest.py
+++ b/tests/general/ImageDimensionBearTest.py
@@ -27,7 +27,7 @@
             shutil.which = lambda *args, **kwargs: 'path/to/git'
             self.assertTrue(ImageDimensionBear.check_prerequisites())
         finally:
-            shutil.which = _shutil_which    
+            shutil.which = _shutil_which
 
     def test_run_with_png(self):
         message = "message='The image ./test-img/img.png is larger"

shutil.which = lambda *args, **kwargs: 'path/to/git'
self.assertTrue(ImageDimensionBear.check_prerequisites())
finally:
shutil.which = _shutil_which
Copy link
Collaborator

Choose a reason for hiding this comment

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

Line contains following spacing inconsistencies:

  • Trailing whitespaces.

SpaceConsistencyBear, severity NORMAL, section python.

The issue can be fixed by applying the following patch:

--- a/tests/general/ImageDimensionBearTest.py
+++ b/tests/general/ImageDimensionBearTest.py
@@ -27,7 +27,7 @@
             shutil.which = lambda *args, **kwargs: 'path/to/git'
             self.assertTrue(ImageDimensionBear.check_prerequisites())
         finally:
-            shutil.which = _shutil_which    
+            shutil.which = _shutil_which
 
     def test_run_with_png(self):
         message = "message='The image ./test-img/img.png is larger"

@rhemon rhemon force-pushed the img-dimension-bear branch from 7e42486 to 06c6fc5 Compare January 12, 2017 03:34
@rhemon
Copy link
Contributor Author

rhemon commented Jan 12, 2017

@sils @jayvdb all test except the appveyor one (test in windows) didn't pass. my guess is that this is happening because of the space that was missing in GemRequirement in dependency_management, but the fix is done and the PR was merged https://gitlab.com/coala/package_manager/merge_requests/10/diffs . now it only needs to have a release. I hope that will have that test pass as well.

Copy link

@robbyoconnor robbyoconnor left a comment

Choose a reason for hiding this comment

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

Why not document it as well?

@rhemon
Copy link
Contributor Author

rhemon commented Jan 12, 2017

the documentation goes to bear-docs right? or did you mean to document in the code, how other bears had for params and returns? @robbyoconnor , if its to document code ok I am doing it now, and if its the first one, can I do it once this PR gets merged? since more changes might be requrested it gets merged.

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

4 similar comments
@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

3 similar comments
@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@jayvdb
Copy link
Member

jayvdb commented Jun 13, 2017

coala/coala#3560 is merged. This bear can now proceed.

@yukiisbored
Copy link
Member

yukiisbored commented Jun 14, 2017

Please make sure the images used for testing aren't copyrighted. I recommend creating your own images, I think a blank image is enough for this bear.

@rhemon rhemon force-pushed the img-dimension-bear branch from 5a06853 to 8fa3242 Compare June 14, 2017 11:54
import shutil

from bears.general.ImageDimensionBear import *
from coalib.output.printers.LOG_LEVEL import LOG_LEVEL
Copy link
Collaborator

Choose a reason for hiding this comment

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

This file contains unused source code.

PyUnusedCodeBear, severity NORMAL, section flakes.

The issue can be fixed by applying the following patch:

--- a/tests/general/ImageDimensionBearTest.py
+++ b/tests/general/ImageDimensionBearTest.py
@@ -4,9 +4,7 @@
 import shutil
 
 from bears.general.ImageDimensionBear import *
-from coalib.output.printers.LOG_LEVEL import LOG_LEVEL
 from coalib.settings.Section import Section
-from coalib.settings.Setting import Setting
 from coalib.testing.BearTestHelper import generate_skip_decorator
 
 

@@ -0,0 +1,91 @@
import unittest
from unittest.case import skip, skipIf
Copy link
Collaborator

Choose a reason for hiding this comment

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

This file contains unused source code.

PyUnusedCodeBear, severity NORMAL, section flakes.

The issue can be fixed by applying the following patch:

--- a/tests/general/ImageDimensionBearTest.py
+++ b/tests/general/ImageDimensionBearTest.py
@@ -1,5 +1,4 @@
 import unittest
-from unittest.case import skip, skipIf
 from queue import Queue
 import shutil
 

@rhemon rhemon force-pushed the img-dimension-bear branch 3 times, most recently from 192e032 to a7bf6c3 Compare June 15, 2017 17:21
Added ImageDimensionBear.py in bears/general, that runs
the gem img_checker to check if images follow given
dimensions by the user.
Also added unittest for the bear, ImageDimensionBearTest.py
in tests/general

Closes coala#1260
@rhemon rhemon force-pushed the img-dimension-bear branch from a7bf6c3 to 3123b7f Compare June 16, 2017 05:19
@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

2 similar comments
@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

2 similar comments
@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

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

Successfully merging this pull request may close these issues.

7 participants