-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Upgrade all code to be Python3 only #5065
Conversation
pyupgrade --py3-plus --py3-only (*.py)
This file is generated by our code and can be used by Python2 when building the documentation, so we need to keep the `u` before the definition of the string.
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.
Just one test got changed incorrectly, but the rest looks good. Not sure why the search tests are failing
readthedocs/config/validation.py
Outdated
|
||
|
||
def validate_list(value): | ||
"""Check if ``value`` is an iterable.""" | ||
if isinstance(value, (dict, string_types)): | ||
if isinstance(value, (dict, (str,))): |
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 should be (dict, str)
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.
Yeah, I suppose it was a mistake in the original code, and it should have been string_type
(in singular).
Maybe we have a dependency in the search code that only runs on python2? |
I don't think so, otherwise the search wouldn't be working: we are running python3 in our production servers. |
We discussed about this and we decided that we want to do it "all at once". |
What about doing the autoformat in a separated PR? This was really large to review |
Yes. I don't expect that nobody review what I will create a PR with all the manual changes that I had to do, branching from this PR. |
Or... at least, I will make commits that make sense separating what are automatic tools from manually touching the files. |
$ pre-commit run python-import-sorter --files `find readthedocs -name '*.py'` It was ran with this configuration: readthedocs/common#28
f293a58
to
796d09b
Compare
This is ready for review: all tests and linting are passing.
We still have a problem with In the end, running
I would be happy if we merge this sooner than later because otherwise we will be dealing with many of merge conflicts with the other PRs. |
Another note. I just tried Also, I found some of these in our entire repo:
|
…/deprecate-python2
Removes `from __future__ import ...`
All checks are passing locally. Although, Travis is doing something wrong with search tests and they are failing on connection :/ |
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.
Let's do it. gulp
🙏 |
This PR drops Python 2 support and upgrade the code to be Python3 only:
tox
pyupgrade
that usesuper()
,f-string
and more (see official docs)from __future__ import etc
import six
mentionsreadthedocs/analytics/vendor/ipaddress.py
and replaces it by https://docs.python.org/3/library/ipaddress.htmlfullmatch
custom function (see this PR)six
andfuture
from requirements filefrom django.utils import six
@pytest.mark.skipif(not six.PY2...
pre-commit
over all the filespyupgrade
andpre-commit
over the conflict filesurlparse
on Added a link to open new issue with prefilled details #3683 once mergedThis PR touches a lot of files. We should probably want to define what's the process we want to follow here but I wanted to have the PR done so we can see a diff and list all the things we need to do here.
pyupgrade
has a way to be used as a pre-commit command so it will have effect only over the modified files in the PR. We are doing this already withyapf
and we are still not covering all the code and complicating the review process. Although, we should consider this and discuss what's the path we want to follow.IMPORTANT NOTE: this is huge PR that touches so many files. So, it's hard to review taking a look at the diff as a whole. You can click on the first commit and review one by one by clicking on "Next" excluding the ones that are script passes:
Closes #4543