-
-
Notifications
You must be signed in to change notification settings - Fork 56
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
Use cross-platform regexes for some State.looks_like*
functions
#286
Use cross-platform regexes for some State.looks_like*
functions
#286
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.
Thanks this is looking good.
Please add a changelog note in HISTORY.rst
following the existing style (whenever you make an open source contribution.
src/django_upgrade/data.py
Outdated
migrations_re = re.compile(r"(^|[\\/])migrations([\\/])") | ||
commands_re = re.compile(r"(^|[\\/])management[\\/]commands[\\/]") |
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.
please sort the regexes alphabetically, the same order that the methods are in
The commands method did deliberately check the current file lives within commands
, which the regex currently doesn’t. I think we could modify it like so to capture this:
commands_re = re.compile(r"(^|[\\/])management[\\/]commands[\\/][^\\/]+$")
Since you’re adjusting commands_re
, please ensure it is tested with both \
and /
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 one fails on myapp/subapp/management/commands/test/subcommand.py
as it has a subfolder and thus an additional path separator. expanding it to
(^|[\\/])management[\\/]commands[\\/][^\\/]+[\\/]*[^\\/]*$
captures one subfolder. Pushing it further to 0 or more subfolders brings:
(^|[\\/])(management[\\/]commands[\\/])([^\\/]+[\\/]+)*([^\\/]+)$
--> regexr.com/71kmn
Commands tests are also updated for windows paths.
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, that was a deliberate suggestion - subdirectories won't be picked up as management commands by Django, so we can ignore certain fixers there.
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.
Ah actually my bad, I didn't realize subcommand
was in the existing tests. We can keep support for subcommand
. Reverting to your original easier regex since the 0+ folders search is verbose and doesn’t help much.
State.looks_like*
functions
f90753c
to
140e35c
Compare
Thank you! |
Thanks for the guidance! It was a nice way to see the full issue to merge cycle! |
Fixes #283
looks_like_migrations_file
andlooks_like_command_file
are converted to regex based filename checks.looks_like_migrations_file
added