Skip to content

Add support for reading from stdin #2746

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

Merged
merged 4 commits into from
Mar 2, 2019
Merged

Conversation

twmr
Copy link
Contributor

@twmr twmr commented Feb 13, 2019

First of all thx @cpitclaudel for starting with the first draft (#1189) of the Read-from-stdin feature.

This PR is based on the inital PR by @cpitclaudel and tries to incorporate the comment by @PCManticore from #1189. I would like to know from @PCManticore if this PR now goes into the right direction.

I tested this PR by using the following command:

cat examples/custom_raw.py | ./bin/pylint --from-stdin custom_raw.py 

Closes: #1187

Steps

  • Add yourself to CONTRIBUTORS if you are a new contributor.
  • Add a ChangeLog entry describing what your PR does.
  • If it's a new feature or an important bug fix, add a What's New entry in doc/whatsnew/<current release.rst>.
  • Write a good description on what the PR does.

Description

Type of Changes

Type
🐛 Bug fix
✨ New feature
🔨 Refactoring
📜 Docs

Related Issue

@coveralls
Copy link

coveralls commented Feb 13, 2019

Coverage Status

Coverage decreased (-0.002%) to 89.65% when pulling 0e37eaa on thisch:readstdin into 946657c on PyCQA:master.

@twmr twmr changed the title Add support for reading from stdin WIP Add support for reading from stdin Feb 15, 2019
@PCManticore
Copy link
Contributor

@Thisch This is very cool, thanks for working on it! Can you add some tests as well?

@twmr twmr force-pushed the readstdin branch 2 times, most recently from d414dc4 to e96d49d Compare February 18, 2019 17:01
pylint/lint.py Outdated
def _read_stdin():
# https://mail.python.org/pipermail/python-list/2012-November/634424.html
# FIXME should this try to check the file's declared encoding?
sys.stdin = TextIOWrapper(sys.stdin.detach(), newline=None)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't yet understand why we need this line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@twmr twmr changed the title WIP Add support for reading from stdin Add support for reading from stdin Feb 18, 2019
@twmr twmr force-pushed the readstdin branch 3 times, most recently from 580a862 to 7a967be Compare February 18, 2019 21:13
@twmr
Copy link
Contributor Author

twmr commented Feb 19, 2019

I need a bit your help with fixing the unit tests:

Here are the errors reported by travis ci:

3.4:
AssertionError: assert '************* Module mymodule\nmymodule.py:1:0: W0611: Unused import os (unused-import)' in
                       '************* Module mymodule\nmymodule.py:1:0: C0304: Final newline missing (missing-final-newline)\n************* M...0611: Unused import os (unused-import)\n\n-------------------------------------\nYour code has been rated at -20.00/10'
3.5-dev:
	
AssertionError: assert '************* Module mymodule\nmymodule.py:1:0: W0611: Unused import os (unused-import)' in 
                       '************* Module mymodule\nmymodule.py:1:0: C0304: Final newline missing (missing-final-newline)\n************* M...0611: Unused import os (unused-import)\n\n-------------------------------------\nYour code has been rated at -20.00/10'

3.6:
AssertionError: assert '************* Module mymodule\nmymodule.py:1:0: W0611: Unused import os (unused-import)' in 
                       '************* Module mymodule\nmymodule.py:1:0: C0304: Final newline missing (missing-final-newline)\n************* M...0611: Unused import os (unused-import)\n\n-------------------------------------\nYour code has been rated at -20.00/10'

3.7:
AssertionError: assert '************* Module mymodule\nmymodule.py:1:0: W0611: Unused import os (unused-import)' in 
                       '************* Module mymodule\nmymodule.py:1:0: C0304: Final newline missing (missing-final-newline)\n************* M...0611: Unused import os (unused-import)\n\n-------------------------------------\nYour code has been rated at -20.00/10'

Where does this "M...0611" output come from? When I run pylint on a file with the contents "import os" locally, pylint reports

************* Module mymodule
mymodule.py:1:0: C0111: Missing module docstring (missing-docstring)
mymodule.py:1:0: W0611: Unused import os (unused-import)

----------------------------------------------------------------------
Your code has been rated at -10.00/10 (previous run: -10.00/10, +0.00)

I don't understand why the travis-ci output contains "M...0611" whereas locally I get "W0611".

@@ -269,3 +269,5 @@ contributors:
* Svetoslav Neykov: contributor

* Federico Bond: contributor

* Thomas Hisch: contributor
Copy link
Contributor

Choose a reason for hiding this comment

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

If you patch is based on the one in #1189, please acknowledge that here too :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Thx for pointing that out.

@cpitclaudel
Copy link
Contributor

Thanks for working on this! I don't have time to review the patch, but I'm excited to see that this feature will be coming soon ^^

Copy link
Contributor

@PCManticore PCManticore left a comment

Choose a reason for hiding this comment

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

Hey @Thisch Took a first look and this is going in the right direction, thanks for the work! I'm not sure yet why it fails on Travis, as I didn't get a chance to see the failure itself. Once the new job fails again, I'll check again.

@twmr twmr force-pushed the readstdin branch 5 times, most recently from 4890940 to 564105d Compare February 21, 2019 10:27
@twmr
Copy link
Contributor Author

twmr commented Feb 21, 2019

I need a bit your help with fixing the unit tests:

Here are the errors reported by travis ci:

3.4:
AssertionError: assert '************* Module mymodule\nmymodule.py:1:0: W0611: Unused import os (unused-import)' in
                       '************* Module mymodule\nmymodule.py:1:0: C0304: Final newline missing (missing-final-newline)\n************* M...0611: Unused import os (unused-import)\n\n-------------------------------------\nYour code has been rated at -20.00/10'
3.5-dev:
	
AssertionError: assert '************* Module mymodule\nmymodule.py:1:0: W0611: Unused import os (unused-import)' in 
                       '************* Module mymodule\nmymodule.py:1:0: C0304: Final newline missing (missing-final-newline)\n************* M...0611: Unused import os (unused-import)\n\n-------------------------------------\nYour code has been rated at -20.00/10'

3.6:
AssertionError: assert '************* Module mymodule\nmymodule.py:1:0: W0611: Unused import os (unused-import)' in 
                       '************* Module mymodule\nmymodule.py:1:0: C0304: Final newline missing (missing-final-newline)\n************* M...0611: Unused import os (unused-import)\n\n-------------------------------------\nYour code has been rated at -20.00/10'

3.7:
AssertionError: assert '************* Module mymodule\nmymodule.py:1:0: W0611: Unused import os (unused-import)' in 
                       '************* Module mymodule\nmymodule.py:1:0: C0304: Final newline missing (missing-final-newline)\n************* M...0611: Unused import os (unused-import)\n\n-------------------------------------\nYour code has been rated at -20.00/10'

Where does this "M...0611" output come from? When I run pylint on a file with the contents "import os" locally, pylint reports

************* Module mymodule
mymodule.py:1:0: C0111: Missing module docstring (missing-docstring)
mymodule.py:1:0: W0611: Unused import os (unused-import)

----------------------------------------------------------------------
Your code has been rated at -10.00/10 (previous run: -10.00/10, +0.00)

I don't understand why the travis-ci output contains "M...0611" whereas locally I get "W0611".

The "M...0611" output is generated by the pytest, so it is not related to an issue in pylint.

@twmr twmr force-pushed the readstdin branch 4 times, most recently from ae1a11e to 718843f Compare February 22, 2019 19:29
@twmr
Copy link
Contributor Author

twmr commented Feb 22, 2019

@PCManticore when you have time, please take again a look at this PR. I think that it is ready now.

In the course of adding the testcase a related bug in the --from-stdin
code was fixed.
Copy link
Contributor

@PCManticore PCManticore left a comment

Choose a reason for hiding this comment

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

Hey @Thisch Great stuff! Left a final round of comments, once these are addresses we can merge the PR.

if ast_node is not None:
self.file_state = utils.FileState(filepath)
self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers)
# warn about spurious inline messages handling
Copy link
Contributor

Choose a reason for hiding this comment

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

This block seems duplicated with the normal flow, maybe move it after the whole if branch?

Copy link
Contributor Author

@twmr twmr Feb 27, 2019

Choose a reason for hiding this comment

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

Moving it after the whole if self.config.from_stdin branch does not work IMO. I think it is not worth the effort to avoid this code duplication, especially since only a couple of lines of code are duplicated.

@twmr
Copy link
Contributor Author

twmr commented Feb 27, 2019

the failure on travis-ci is unrelated to my change.

@PCManticore PCManticore merged commit fb5a2a6 into pylint-dev:master Mar 2, 2019
@PCManticore
Copy link
Contributor

Thank you @Thisch for your contribution! 🎉 This will be part of pylint 2.4. when it gets released.

@twmr
Copy link
Contributor Author

twmr commented Jun 19, 2019

@PCManticore Any estimates when we can expect a 2.4 release? What are the open issues that need to be fixed before 2.4 can be relased?

@PCManticore
Copy link
Contributor

@Thisch It's going to happen most likely in July. A main blocker is having Python 3.8 support. A separate one is that I'd like to have #2036 in time for 2.4 release, but if that won't happen in due time, we can release without it.

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

Successfully merging this pull request may close these issues.

Feature request: linting from stdin
4 participants