Skip to content

It is safer to pylint on Python 3 than Python 2#5727

Closed
cclauss wants to merge 1 commit intocertbot:masterfrom
cclauss:patch-2
Closed

It is safer to pylint on Python 3 than Python 2#5727
cclauss wants to merge 1 commit intocertbot:masterfrom
cclauss:patch-2

Conversation

@cclauss
Copy link
Copy Markdown

@cclauss cclauss commented Mar 14, 2018

Syntax Errors will be caught by pylint running on Python 3 but not when running on Python 2:

  • print "Hello"
  • 0L
  • 0755
  • except Exception, e
    etc...

Copy link
Copy Markdown
Contributor

@ohemorange ohemorange left a comment

Choose a reason for hiding this comment

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

Hey @cclauss, it would be absolutely fantastic if you could work on getting our pylint tests running in python 3! It's going to take some work though, because they don't currently pass when run with python 3.

Here's what's up: changing .travis.yml has travis set up a virtual env with the python specified (what you just changed to 3.6). But our tox.ini file specifies which python to actually run the tests with. That's currently set to python2.7, and should be changed to python3 to get it to actually use a version of python3 to run tests (it will be 3.6 in travis as specified, and whatever version of 3 people have locally when run not on travis).

The lint tests should work with any version of python 3 we support. Not sure about others, but they're definitely failing on python3.5.

Based on my own brief investigation, there's a bug in the version of pylint we use that makes it fail on some set of versions of python including 3.5. This could be fixed by upgrading pylint, but it's currently pinned to an older version because of reasoning you can find here: #289

I would love it if you could investigate this issue so we could resolve it properly, but if it's more work than you thought you'd be getting into let me know and I'll close the PR. Thanks!

@cclauss
Copy link
Copy Markdown
Author

cclauss commented Apr 18, 2018

The really strange case of python3 -m pylint import_os.py...

$ git clone https://github.com/certbot/certbot
$ cd certbot
$ cat > import_os.py

import os
<Ctrl-D>

$ python3 -m pylint import_os.py

internal error with sending report for module ['import_os.py']
The concept of slots is undefined for old-style classes.

$ cp import_os.py ..
$ cd ..
$ python3 -m pylint import_os.py

Pylint works as expected

Conclusion: There is not a problem with your Python files, there is a problem with your error reporting system. If you try the same trick with import_sys.py things work so there is really something about "os" like perhaps there is a file named os.py lurking around somewhere or something.

@cclauss cclauss force-pushed the patch-2 branch 2 times, most recently from ad297dd to f7b1d1a Compare April 18, 2018 19:10
@cclauss
Copy link
Copy Markdown
Author

cclauss commented Apr 18, 2018

@ohemorange This is ready for your review. There were several head scratchers in this one...

  • .travis.yml: Just upgrade to Python 3.6 with allow_failures so the pylint issues can be fixed
  • linter_plugin.py:
    • The file was missing a pass statement so it was not valid Python
    • The pylint plugin API has changed so nodes are not longer required
    • Comment out the cls.slots() code as they no longer exists
  • setup.py: Remove an unused import (Remove unneeded sys import #5873) and unpeg the imports
  • tox.ini:
    • Upgrade to Python 3
    • Reinstall astroid and pylint -- without this re-installation, bad things happen :-(
      • This was the hardest issue to find and it is counter-intuitive but essential
    • Temporarily end the pytest line with ; true so that Travis does not rerun failing tests
      • Once all pytest issues have been fixed, the trailing ; true should be removed.

@cclauss cclauss force-pushed the patch-2 branch 9 times, most recently from bc0aaf6 to 85ac3af Compare April 18, 2018 22:27
Copy link
Copy Markdown
Contributor

@ohemorange ohemorange left a comment

Choose a reason for hiding this comment

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

Nice sleuthing, cclauss! Thanks for investigating this.

Looks like with later versions of things, we can go ahead and remove linter_plugin.py entirely by deleting that file and changing load-plugins=linter_plugin to load-plugins= in .pylintrc, and removing include linter_plugin.py from MANIFEST.in.

Since we rely on clean lint results for new code, I'm not comfortable merging a change into master that allows lint to fail. How do you feel about attacking the (quite lengthy but probably straightforward) list of lint failures that now show up in travis? Those can be done in separate PRs, and we can merge this PR (minus allow_failures) once we're back to a clean lint.

@cclauss cclauss force-pushed the patch-2 branch 6 times, most recently from 32a0220 to aca4bf5 Compare April 19, 2018 06:56
@cclauss
Copy link
Copy Markdown
Author

cclauss commented Apr 19, 2018

we rely on clean lint results for new code

Not really. Pylint dirt is currently being swept under the rug.

This PR demonstrates that for a while now Pylint has been running improperly both locally or on Travis because of linter_plugin.py. Once that is fixed, then Pylint errors are properly reported.

The PR has now reverted to running Pylint on Python 2 and the repo currently contains 90+ Python files that generate Pylint errors. I am not inclined to fix all those files but it might make a nice set of tasks for first time contributors.

When linter_plugin.py is deleted then the apache_compat and nginx_compat test runs fail. So linter_plugin.py is fixed to be valid Python and the cls.slots() bit commented out. .pylintrc is modified to no longer load the plugin.

Copy link
Copy Markdown
Contributor

@ohemorange ohemorange left a comment

Choose a reason for hiding this comment

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

Sounds like you might not have the time to clean the lint errors. We have a hackathon coming up, so maybe we can address many of those issues and get the new way of doing things merged afterwards. Thanks again for your hard work here!

# continue, but tox return code will reflect previous error
commands =
{[base]install_packages}
pip install --upgrade astroid pylint # required!
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This shouldn't actually be required; developers might just have to remove and reinstall the venv.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Try taking it out and see what breaks.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

tools/dev_constraints.txt should also be updated

jepayne1138 added a commit to jepayne1138/certbot that referenced this pull request May 14, 2018
Verify no conficts when working on old PR certbot#5727
@bmw
Copy link
Copy Markdown
Member

bmw commented May 30, 2018

@ohemorange, are you happy with this PR besides fixing the new linting failures?

@bmw bmw mentioned this pull request May 30, 2018
@ohemorange
Copy link
Copy Markdown
Contributor

@bmw no, there's still an unaddressed review comment that I'd like to see cleared up.

@bmw
Copy link
Copy Markdown
Member

bmw commented Jun 1, 2018

OK. The fix here is to remove the line commented on at #5727 (comment) and update the pinned versions in tools/dev_constraints.txt.

@sydneyli, perhaps @jepayne1138 can do this in #6008?

@ohemorange
Copy link
Copy Markdown
Contributor

Closing this in favor of #6008. @cclauss if you can make the change described at #5727 (comment), then we'll reopen to finish it up here. Thanks for all the great work you've done so far!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants