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
Add whitelist of folders that must remain Python 2 compatible #7941
Add whitelist of folders that must remain Python 2 compatible #7941
Conversation
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.
Each commit may be reviewed independently.
# We grab an extra line in case there is a shebang. | ||
lines = [f.readline() for _ in range(0, EXPECTED_NUM_LINES + 1)] | ||
except IOError as e: | ||
raise HeaderCheckFailure(f"{filename}: error while reading input ({e})") | ||
except OSError as e: |
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.
Python 3 unified IOError
into OSError
: https://docs.python.org/3/library/exceptions.html#OSError.
# Copyright 2018 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
# NB: This file must keep Python 2 support because it is a resource that may be ran with Python 2. |
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 PR description has this usage as well and it seems off. I think 'may be run' is what's needed.
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.
I think I agree. No matter how many times I read grammar girls, I will still be eternally confused by 'run' vs 'ran' :/
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.
I don't know grammar, but it just struck me as mixing time zones. The 'may be' bit implies future. The 'ran' bit is past tense.
CURRENT_YEAR = str(datetime.datetime.now().year) | ||
CURRENT_CENTURY_REGEX = re.compile(r'20\d\d') | ||
|
||
PY2_DIRECTORIES = { |
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 all looks good but if I haven't pointed it out already, we already have a rule that does all this introduced in #7515. It already has enough flexibility to apply header checks to subsets of paths although it uses whitelists and could stand support for blacklists to make path specification more concise and less brittle for cases like these. We use the rule in the toolchain codebase; so I've filed #7942 to add blacklists and circling back to replace this hand-rolled check with use of the rule.
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.
Ack. Always a fan of less code.
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.
Going to fix comments to use proper grammar and merge without another CI run.
CURRENT_YEAR = str(datetime.datetime.now().year) | ||
CURRENT_CENTURY_REGEX = re.compile(r'20\d\d') | ||
|
||
PY2_DIRECTORIES = { |
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.
Ack. Always a fan of less code.
# Copyright 2018 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
# NB: This file must keep Python 2 support because it is a resource that may be ran with Python 2. |
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.
I think I agree. No matter how many times I read grammar girls, I will still be eternally confused by 'run' vs 'ran' :/
Three of our folders may be run with Python 2, so they must keep their compatibility, e.g.
from __future__
imports.If this impacted more code, we would want to create (restore) formal linters to enforce the compatibility. However, because the code is so small and CI will fail upon dropping Py2 support, we simply add comments to the files explaining this expectation and modify
check_headers.py
to allow these files to not use Py3 headers.In the process, we refactor
check_headers.py
to use thepathlib
module for much nicer path handling.