-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add ruff rules PIE #5033
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
base: main
Are you sure you want to change the base?
Add ruff rules PIE #5033
Conversation
684fac1
to
dc47791
Compare
Just a test to understand why tests are failing on: * pypa#5033
dc6bf05
to
3bac7c8
Compare
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.
PIE is indeed a pretty good rule group to enable unconditionally.
There is probably some recent update in Ruff causing the CI to fail in an unchanged portion of the code: > raise RuffError(stdout.decode())
E pytest_ruff.RuffError: setuptools/tests/test_build_py.py:168:5: PT031 `pytest.warns()` block should contain a single simple statement
E |
E 167 | msg = r"Python recognizes 'mypkg\.tests' as an importable package"
E 168 | / with pytest.warns(SetuptoolsDeprecationWarning, match=msg):
E 169 | | # TODO: To fix #3260 we need some transition period to deprecate the
E 170 | | # existing behavior of `include_package_data`. After the transition, we
E 171 | | # should remove the warning and fix the behavior.
E 172 | |
E 173 | | if os.getenv("SETUPTOOLS_USE_DISTUTILS") == "stdlib":
E 174 | | # pytest.warns reset the warning filter temporarily
E 175 | | # https://github.com/pytest-dev/pytest/issues/4011#issuecomment-423494810
E 176 | | warnings.filterwarnings(
E 177 | | "ignore",
E 178 | | "'encoding' argument not specified",
E 179 | | module="distutils.text_file",
E 180 | | # This warning is already fixed in pypa/distutils but not in stdlib
E 181 | | )
E 182 | |
E 183 | | build_py.finalize_options()
E 184 | | build_py.run()
E | |______________________^ PT031
E 185 |
E 186 | build_dir = Path(dist.get_command_obj("build_py").build_lib) |
We can probably (temporarily) pin Ruff < 0.12.0 to avoid problems with new rules being enforced. |
Could Or |
I don't know in this case because of the warnings filter bespoke modification inside the context, may be fragile... Let's see if the CI fails in #5042. |
You can pin ruff temporarily as to not expand this PR's scope if you want. |
@abravalheri Your review, please. |
Window test errors caused by
Summary of changes
https://docs.astral.sh/ruff/rules/#flake8-pie-pie
Fix three instances of:
%
ruff rule PIE810
str.startswith
str.endswith
These transformations to reduce unnecessary repetitive function calls have been recommended since 2006 when they were introduced in Python 2.5
Pull Request Checklist
newsfragments/
.(See documentation for details)