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
Remove repeated definitions of format_lines() #5215
base: master
Are you sure you want to change the base?
Conversation
@@ -32,6 +26,7 @@ def apply(self, | |||
FILE_DIFF_DICT_INDEX = 2 | |||
SECTION_INDEX = 3 | |||
|
|||
from coalib.output.ConsoleInteraction import format_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.
The import
statement had to be placed here instead of the usual - top of the file - because coala was encountering an error with circularly dependent import.
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.
Then put the function in a different module which doesnt cause a circular dependency
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's a circular dependency problem with ShowAppliedPatches.py
regardless of whether I put the function in ConsoleInteraction.py
or coala_main.py
. Now, the function format_lines()
is used only in these 3 modules-- ShowAppliedPatches.py
, ConsoleInteraction.py
and coala_main.py
.
Therefore, I IMHO I think that we need to put the function definition in one of these files only. Also, I don't think that it should be inside ShowAppliedPatches.py
.
Hence, the confusion. 😕
Please suggest a fix to it @jayvdb
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.
It is your task to find the solution.
I already know it.
And telling it to you doesn't help you learn.
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.
@nityeshaga LGTM 😄 . 👍 for mentioning the comment about the import statement.
@@ -32,6 +26,7 @@ def apply(self, | |||
FILE_DIFF_DICT_INDEX = 2 | |||
SECTION_INDEX = 3 | |||
|
|||
from coalib.output.ConsoleInteraction import format_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.
Then put the function in a different module which doesnt cause a circular dependency
3c475b8
to
0ce555b
Compare
0ce555b
to
453d807
Compare
I think that the I have also moved the definitions of @jayvdb What do you think? |
get a green build. then we talk |
453d807
to
1c4b7c9
Compare
tests/output/InteractionsTest.py
Outdated
@@ -2,7 +2,9 @@ | |||
|
|||
from pyprint.NullPrinter import NullPrinter | |||
|
|||
from coalib.output.Interactions import fail_acquire_settings | |||
from coala_utils.ContextManagers import retrieve_stdout | |||
from coalib.output.Interactions import (fail_acquire_settings, |
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.
Line contains following spacing inconsistencies:
- Trailing whitespaces.
Origin: SpaceConsistencyBear, Section: python
.
The issue can be fixed by applying the following patch:
--- a/tmp/tmp4c82t5xa/tests/output/InteractionsTest.py
+++ b/tmp/tmp4c82t5xa/tests/output/InteractionsTest.py
@@ -3,7 +3,7 @@
from pyprint.NullPrinter import NullPrinter
from coala_utils.ContextManagers import retrieve_stdout
-from coalib.output.Interactions import (fail_acquire_settings,
+from coalib.output.Interactions import (fail_acquire_settings,
highlight_text, color_letter, format_lines)
from coalib.output.printers.LogPrinter import LogPrinter
tests/output/InteractionsTest.py
Outdated
@@ -2,7 +2,9 @@ | |||
|
|||
from pyprint.NullPrinter import NullPrinter | |||
|
|||
from coalib.output.Interactions import fail_acquire_settings | |||
from coala_utils.ContextManagers import retrieve_stdout |
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 file contains unused source code.
Origin: PyUnusedCodeBear, Section: flakes
.
The issue can be fixed by applying the following patch:
--- a/tmp/tmp4c82t5xa/tests/output/InteractionsTest.py
+++ b/tmp/tmp4c82t5xa/tests/output/InteractionsTest.py
@@ -2,7 +2,6 @@
from pyprint.NullPrinter import NullPrinter
-from coala_utils.ContextManagers import retrieve_stdout
from coalib.output.Interactions import (fail_acquire_settings,
highlight_text, color_letter, format_lines)
from coalib.output.printers.LogPrinter import LogPrinter
tests/output/InteractionsTest.py
Outdated
@@ -2,7 +2,9 @@ | |||
|
|||
from pyprint.NullPrinter import NullPrinter | |||
|
|||
from coalib.output.Interactions import fail_acquire_settings | |||
from coala_utils.ContextManagers import retrieve_stdout | |||
from coalib.output.Interactions import (fail_acquire_settings, |
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.
Origin: PEP8Bear, Section: autopep8
.
The issue can be fixed by applying the following patch:
--- a/tmp/tmp4c82t5xa/tests/output/InteractionsTest.py
+++ b/tmp/tmp4c82t5xa/tests/output/InteractionsTest.py
@@ -3,8 +3,8 @@
from pyprint.NullPrinter import NullPrinter
from coala_utils.ContextManagers import retrieve_stdout
-from coalib.output.Interactions import (fail_acquire_settings,
- highlight_text, color_letter, format_lines)
+from coalib.output.Interactions import (fail_acquire_settings,
+ highlight_text, color_letter, format_lines)
from coalib.output.printers.LogPrinter import LogPrinter
tests/output/InteractionsTest.py
Outdated
def test_format_lines(self): | ||
prompt_msg = 'Enter a number: ' | ||
prompt_msg_formatted = '[ ] Enter a number: ' | ||
self.assertEqual(format_lines(prompt_msg, symbol='['), prompt_msg_formatted) |
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.
Origin: PEP8Bear, Section: autopep8
.
The issue can be fixed by applying the following patch:
--- a/tmp/tmp4c82t5xa/tests/output/InteractionsTest.py
+++ b/tmp/tmp4c82t5xa/tests/output/InteractionsTest.py
@@ -22,4 +22,5 @@
def test_format_lines(self):
prompt_msg = 'Enter a number: '
prompt_msg_formatted = '[ ] Enter a number: '
- self.assertEqual(format_lines(prompt_msg, symbol='['), prompt_msg_formatted)
+ self.assertEqual(format_lines(
+ prompt_msg, symbol='['), prompt_msg_formatted)
tests/output/InteractionsTest.py
Outdated
@@ -2,7 +2,9 @@ | |||
|
|||
from pyprint.NullPrinter import NullPrinter | |||
|
|||
from coalib.output.Interactions import fail_acquire_settings | |||
from coala_utils.ContextManagers import retrieve_stdout | |||
from coalib.output.Interactions import (fail_acquire_settings, |
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.
W291 trailing whitespace
Origin: PycodestyleBear (W291), Section: autopep8
.
tests/output/InteractionsTest.py
Outdated
from coalib.output.Interactions import fail_acquire_settings | ||
from coala_utils.ContextManagers import retrieve_stdout | ||
from coalib.output.Interactions import (fail_acquire_settings, | ||
highlight_text, color_letter, format_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.
E128 continuation line under-indented for visual indent
Origin: PycodestyleBear (E128), Section: autopep8
.
tests/output/InteractionsTest.py
Outdated
|
||
color_letter(self.console_printer, message) | ||
|
||
self.assertEqual(stdout.getvalue().strip(), first_part + |
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.
Line contains following spacing inconsistencies:
- Trailing whitespaces.
Origin: SpaceConsistencyBear, Section: python
.
The issue can be fixed by applying the following patch:
--- a/tmp/tmpz0nm9lb2/tests/output/InteractionsTest.py
+++ b/tmp/tmpz0nm9lb2/tests/output/InteractionsTest.py
@@ -44,7 +44,7 @@
color_letter(self.console_printer, message)
- self.assertEqual(stdout.getvalue().strip(), first_part +
+ self.assertEqual(stdout.getvalue().strip(), first_part +
colored(letter,
color='blue') +
second_part)
tests/output/InteractionsTest.py
Outdated
color_letter(self.console_printer, message) | ||
|
||
self.assertEqual(stdout.getvalue().strip(), first_part + | ||
colored(letter, |
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.
Line contains following spacing inconsistencies:
- Trailing whitespaces.
Origin: SpaceConsistencyBear, Section: python
.
The issue can be fixed by applying the following patch:
--- a/tmp/tmpz0nm9lb2/tests/output/InteractionsTest.py
+++ b/tmp/tmpz0nm9lb2/tests/output/InteractionsTest.py
@@ -45,7 +45,7 @@
color_letter(self.console_printer, message)
self.assertEqual(stdout.getvalue().strip(), first_part +
- colored(letter,
+ colored(letter,
color='blue') +
second_part)
tests/output/InteractionsTest.py
Outdated
text = 'Text to be highlighted' | ||
#formatter = TerminalTrueColorFormatter(style=NoColorStyle) | ||
#highlighted_text = highlight(text, TextLexer(), formatter)[:-1] | ||
self.assertEqual(highlight_text(self.no_color, text, NoColorStyle), |
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.
Line contains following spacing inconsistencies:
- Trailing whitespaces.
Origin: SpaceConsistencyBear, Section: python
.
The issue can be fixed by applying the following patch:
--- a/tmp/tmpz0nm9lb2/tests/output/InteractionsTest.py
+++ b/tmp/tmpz0nm9lb2/tests/output/InteractionsTest.py
@@ -53,5 +53,5 @@
text = 'Text to be highlighted'
#formatter = TerminalTrueColorFormatter(style=NoColorStyle)
#highlighted_text = highlight(text, TextLexer(), formatter)[:-1]
- self.assertEqual(highlight_text(self.no_color, text, NoColorStyle),
+ self.assertEqual(highlight_text(self.no_color, text, NoColorStyle),
text)
tests/output/InteractionsTest.py
Outdated
#formatter = TerminalTrueColorFormatter(style=NoColorStyle) | ||
#highlighted_text = highlight(text, TextLexer(), formatter)[:-1] | ||
self.assertEqual(highlight_text(self.no_color, text, NoColorStyle), | ||
text) |
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.
Line contains following spacing inconsistencies:
- Trailing whitespaces.
Origin: SpaceConsistencyBear, Section: python
.
The issue can be fixed by applying the following patch:
--- a/tmp/tmpz0nm9lb2/tests/output/InteractionsTest.py
+++ b/tmp/tmpz0nm9lb2/tests/output/InteractionsTest.py
@@ -54,4 +54,4 @@
#formatter = TerminalTrueColorFormatter(style=NoColorStyle)
#highlighted_text = highlight(text, TextLexer(), formatter)[:-1]
self.assertEqual(highlight_text(self.no_color, text, NoColorStyle),
- text)
+ text)
tests/output/InteractionsTest.py
Outdated
@@ -1,13 +1,25 @@ | |||
import unittest | |||
|
|||
from pyprint.NullPrinter import NullPrinter | |||
from pyprint.ConsolePrinter import ConsolePrinter | |||
from termcolor import colored | |||
from pygments.formatters import TerminalTrueColorFormatter |
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 file contains unused source code.
Origin: PyUnusedCodeBear, Section: flakes
.
The issue can be fixed by applying the following patch:
--- a/tmp/tmpz0nm9lb2/tests/output/InteractionsTest.py
+++ b/tmp/tmpz0nm9lb2/tests/output/InteractionsTest.py
@@ -3,7 +3,6 @@
from pyprint.NullPrinter import NullPrinter
from pyprint.ConsolePrinter import ConsolePrinter
from termcolor import colored
-from pygments.formatters import TerminalTrueColorFormatter
from coala_utils.ContextManagers import retrieve_stdout
from coalib.output.Interactions import (fail_acquire_settings,
b52e045
to
3e8556b
Compare
Please stop pushing until you have a version which passes the tests on your local machine. |
Extremely sorry for the mess. 😅
I'll keep this in mind |
3e8556b
to
eaca416
Compare
tests/output/InteractionsTest.py
Outdated
@@ -1,9 +1,18 @@ | |||
import unittest | |||
|
|||
from pyprint.NullPrinter import NullPrinter | |||
from pyprint.ConsolePrinter import ConsolePrinter | |||
from termcolor import colored | |||
from pygments.formatters import TerminalTrueColorFormatter |
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 file contains unused source code.
Origin: PyUnusedCodeBear, Section: flakes
.
The issue can be fixed by applying the following patch:
--- a/tmp/tmpx0fit6qr/tests/output/InteractionsTest.py
+++ b/tmp/tmpx0fit6qr/tests/output/InteractionsTest.py
@@ -3,7 +3,6 @@
from pyprint.NullPrinter import NullPrinter
from pyprint.ConsolePrinter import ConsolePrinter
from termcolor import colored
-from pygments.formatters import TerminalTrueColorFormatter
from coala_utils.ContextManagers import retrieve_stdout
from coalib.output.Interactions import (fail_acquire_settings,
baeca3e
to
0d0a9fb
Compare
@@ -28,3 +45,35 @@ def fail_acquire_settings(log_printer, settings_names_dict): | |||
|
|||
logging.error(msg) | |||
raise AssertionError(msg) | |||
|
|||
|
|||
def highlight_text(no_color, text, style, lexer=TextLexer()): |
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 instead of format_lines
being duplicated, coalib/output/ConsoleInteraction.py:highlight_text
is being duplicated here.
How is this better?
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.
Sorry, I've fixed it now.
No duplicates of highlight_text()
anymore :)
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, why the Interactions module?
This module now needs a docstring that would explain why fail_acquire_settings
and format_lines
are grouped together.
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 it be better if I created a new module Formatting.py
and moved format_lines()
, highlight_text()
and color_letter()
over there?
0d0a9fb
to
08dad88
Compare
Removes the different definitions of format_lines() in files- ConsoleInteraction.py, coala_main.py and ShowAppliedPatchAction.py and the definitions of highlight_text() and color_letter() from ConsoleInteraction.py and moves them to Interactions.py. Closes coala#5205
08dad88
to
8dd4da5
Compare
def sym(x): return ']' if x is '[' else x | ||
return '\n'.join('{}{:>5}{} {}'.format(symbol, sym(symbol), line_nr, line) | ||
for line in lines.rstrip('\n').split('\n')) | ||
from coalib.output.Interactions import format_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.
why do we even need to use format_lines in this module?
And are you sure that padding of 5 is not intentional, and 4 is good enough?
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.
And are you sure that padding of 5 is not intentional, and 4 is good enough?
In ShowAppliedPatchesAction, format_lines()
is used when printing the Severity
of the patch.
Here's how it looked (before this PR):
Notice the line ! ![Severity: NORMAL]
And here's how it looks now (after this PR):
So, the version of format_lines()
in this PR works like it was expected to IMO.
why do we even need to use format_lines in this module?
Yes I agree, that was a bad decision on my part. 😅
I wasn't sure if creating a new file to solve a difficulty/low issue was allowed or not. Now I think it would be better if I create a new file (Formatting.py
maybe?) and put format_lines()
, color_letter()
and highlight_text()
inside it. What do you think @jayvdb ?
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 you missing my point. what does format_lines
do? Why is that functionality needed in ShowAppliedPatchesAction.py
?
Is it the right tool for the job?
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 does format_lines do?
format_lines
returns a formatted version of the string passed to it as a parameter. It formats the string to make it look elegantly in coala's CLI by adding a little prefix to it.
Why is that functionality needed in ShowAppliedPatchesAction.py?
ShowAppliedPatchesAction
already uses it to format the line which displays the Severity of any applied action.
So, unless you are suggesting that we change how ShowAppliedPatchesAction
shows its messages, I think that format_lines
is the right tool for the job.
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.
You still have not read format_lines
and its usages carefully.
It is gobbledy-gook that people have copied and pasted without thinking.
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.
You still have not read format_lines and its usages carefully.
😅 I'm sorry, I didn't find anything else to read about it except the 4 line definition which was present in all 3 of the above mentioned files.
So, are you suggesting that we modify the definition of format_lines()
? maybe make pass the amount of padding as a parameter? Or are you suggesting that we remove the function altogether?
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.
Read those four lines very carefully. Understand exactly what happens when it is called each time.
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.
Here's what I understand format_lines()
is doing:
Each time the function is called with a string (lines
), it splits that string at \n
s, prefixes each split string with the symbol
(passed to it as a parameter), adds line_nr
with a padding of 4, adds the sym()
version of symbol
, and finally joins them using \n
and returns this joined version.
Also, sym()
is a local function inside format_lines()
which is just responsible to return the closing ]
in case the symbol
that is passed is [
. Otherwise, it returns the passed character itself.
Isn't that all? 😅
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 I dont want you to tell me what it does in theory. I already know the answers.
You need to see why in practise , in some of the real world scenarios where it is used, it isnt particularly useful.
Replaces the definitions of format_lines() in files- coala_main.py
and ShowAppliedPatchAction.py with import statements that import the
function from ConsoleInteraction.py.
Closes #5205
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!