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

Aspect: Create map_setting_to_aspect decorator #4662

Merged
merged 1 commit into from Aug 26, 2017

Conversation

@adhikasp
Copy link
Member

@adhikasp adhikasp commented Aug 24, 2017

@map_setting_to_aspect(
        remove_all_unused_imports=(get_aspect('UnusedImport')
                                   .remove_non_standard_import),
        remove_unused_variables=get_aspect('UnusedLocalVariable'))
def run(self, filename, file,
        remove_all_unused_imports: bool=True,
        remove_unused_variables: bool=True):
    pass

The run argument will be overrided by aspect's setting
(only if it present). This make bear's aspectization much more easy.

Closes #4661

@map_setting_to_aspect(
remove_unreachable_code=get_aspect('UnreachableCode'),
minimum_clone_tokens=(get_aspect('Clone')
.min_clone_tokens),
Copy link
Collaborator

@gitmate-bot gitmate-bot Aug 24, 2017

E128 continuation line under-indented for visual indent

Origin: PycodestyleBear (E128), Section: autopep8.

@map_setting_to_aspect(
remove_unreachable_code=get_aspect('UnreachableCode'),
minimum_clone_tokens=(get_aspect('Clone')
.min_clone_tokens),
Copy link
Collaborator

@gitmate-bot gitmate-bot Aug 24, 2017

The code does not comply to PEP8.

Origin: PEP8Bear, Section: autopep8.

The issue can be fixed by applying the following patch:

--- a/tests/bearlib/aspects/DecoratorsTest.py
+++ b/tests/bearlib/aspects/DecoratorsTest.py
@@ -18,7 +18,7 @@
     @map_setting_to_aspect(
         remove_unreachable_code=get_aspect('UnreachableCode'),
         minimum_clone_tokens=(get_aspect('Clone')
-                             .min_clone_tokens),
+                              .min_clone_tokens),
     )
     def run(self,
             remove_unreachable_code: bool=False,

@jayvdb
Copy link
Member

@jayvdb jayvdb commented Aug 24, 2017

Please dont put code fragments in the commit message.
Just describe the enhancements.
(and your code fragment in the commit body has incorrect indentation anyway.)

"""
Override function arguments value with coala's aspect and taste.

This decorators could be used by ``Bear.run()`` to automatically map and
Copy link
Member

@hemangsk hemangsk Aug 24, 2017

decorator* ?

Copy link
Member

@jayvdb jayvdb left a comment

decorator should use functools.wraps

@@ -21,7 +22,7 @@
__all__ = ['Root', 'Taste', 'TasteError',
'aspectclass', 'aspectbase', 'AspectTypeError',
'AspectNotFoundError', 'MultipleAspectFoundError',
'AspectList']
'AspectList', 'map_setting_to_aspect']
Copy link
Member

@jayvdb jayvdb Aug 24, 2017

add trailing comma's and put the final ] on a new line so it doesnt need updating all the time.


def map_setting_to_aspect(**aspectable_setting):
"""
Override function arguments value with coala's aspect and taste.
Copy link
Member

@jayvdb jayvdb Aug 26, 2017

'Override' ?

What happens if a setting is explicitly in .coafile, and is in an aspect? The aspect overrides the explicit setting? I hope not.

Copy link
Member Author

@adhikasp adhikasp Aug 26, 2017

Um yes it is. It will always override explicit or default setting with aspect/taste setting if coala is run under aspect, except for those setting that doesn't mapped here (could be used by a very specific linter setting like pep_ignore) . Do we want different behavior here?

Copy link
Member Author

@adhikasp adhikasp Aug 26, 2017

Priority: old-setting default -> explicit old-setting -> aspect taste default -> explicit aspect taste

Copy link
Member

@jayvdb jayvdb Aug 26, 2017

explicit user choices should never be overriden automatically.
I think it should be:

explicit setting -> explicit aspect taste (if aspects activated in Section) -> aspect taste default (if aspects activated in Section) -> setting default

(please stop calling them 'old-setting' - Setting is still a core component, and people will still keep using them at least until aspects are perfect for everyones needs, which wont be soon, and even then a Setting may still be used internally by the run method, until we also deprecate the run method. )

Copy link
Member Author

@adhikasp adhikasp Aug 26, 2017

Okay I agree, will change it.

Copy link
Member

@jayvdb jayvdb Aug 26, 2017

Then this function docstring needs to change.

def _func_decorator(func):
@wraps(func)
def _new_func(self, *args, **kwargs):
if hasattr(self, 'section') and self.section.aspects:
Copy link
Member

@jayvdb jayvdb Aug 26, 2017

Why hasattr(self, 'section') ; i think it should raise an exception if there is no .section?

Copy link
Member Author

@adhikasp adhikasp Aug 26, 2017

Yeah right hasattr(self, 'section') is not necessary here.

result = self.bear.execute()
self.assertEqual([False, 40], result)


Copy link
Collaborator

@gitmate-bot gitmate-bot Aug 26, 2017

The code does not comply to PEP8.

Origin: PEP8Bear, Section: autopep8.

The issue can be fixed by applying the following patch:

--- a/tests/bearlib/aspects/DecoratorsTest.py
+++ b/tests/bearlib/aspects/DecoratorsTest.py
@@ -53,7 +53,6 @@
         result = self.bear.execute()
         self.assertEqual([False, 40], result)
 
-
     def test_partial_mapping(self):
         self.section.aspects = AspectList([
             get_aspect('UnreachableCode')('py'),

@adhikasp adhikasp force-pushed the adhikasp/decor branch 2 times, most recently from f469f7e to afe94be Aug 26, 2017
The `run` argument will be overrided by aspect's setting
(only if it present). This make bear's aspectization much more easy.

The priority is:
- explicit setting
- explicit aspect taste (if aspects activated in Section)
- aspect taste default (if aspects activated in Section)
- setting default

Closes coala#4661
@jayvdb
Copy link
Member

@jayvdb jayvdb commented Aug 26, 2017

ack 76b1e99

@jayvdb
Copy link
Member

@jayvdb jayvdb commented Aug 26, 2017

@rultor merge

jayvdb
jayvdb approved these changes Aug 26, 2017
@rultor
Copy link
Contributor

@rultor rultor commented Aug 26, 2017

@rultor merge

@jayvdb OK, I'll try to merge now. You can check the progress of the merge here

@rultor rultor merged commit 76b1e99 into coala:master Aug 26, 2017
6 of 9 checks passed
6 of 9 checks passed
ci/circleci CircleCI is running your tests
Details
continuous-integration/appveyor/branch Waiting for AppVeyor build to complete
Details
continuous-integration/travis-ci/push The Travis CI build is in progress
Details
@codecov[bot]
codecov/project 100% (target 100%)
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
review/gitmate/commit This commit has no issues. :)
Details
review/gitmate/manual This commit was acknowledged.
Details
review/gitmate/pr This PR has no issues. :)
Details
@rultor
Copy link
Contributor

@rultor rultor commented Aug 26, 2017

@rultor merge

@jayvdb Done! FYI, the full log is here (took me 2min)

@adhikasp adhikasp deleted the adhikasp/decor branch Aug 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants