-
Notifications
You must be signed in to change notification settings - Fork 26
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 ignore patterns #92
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.
Can we add some unit tests for glob_to_re
?
@@ -26,9 +28,15 @@ | |||
add_completion=False, | |||
) | |||
|
|||
entrypoint = functools.partial(app, windows_expand_args=False) |
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.
Why can't this be added to the app instead of using this partial?
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.
Neither Typer nor Click seem to have an option to pass this argument during initialization. The only way to pass it is during invocation of the app through the __call__()
or main()
methods.
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.
Do you have a reference for this?
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.
PR pallets/click#1918 added the parameter, only to the main
method.
The only mention of this parameter in Click's documentation is under the main
method here.
pallets/click#1918 (comment) explains how to use it in an entrypoint.
If windows_expand_args is True, command line option values like .venv/** will be turned into .venv\\
Co-authored-by: Marcelo Trylesinski <[email protected]>
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 @lemonyte :)
Allows the user to specify glob patterns to ignore when scanning for source files.
Example usage:
Note: on POSIX systems it may be necessary to escape patterns in the command line.
Implementation details and design decisions
This PR adds a function
glob_to_re()
which translates a glob pattern into a regular expression. The function is necessary because:glob
module does not provide a way to match a path against a pattern without traversing the file system, andfnmatch.fnmatch()
andpathlib.Path.match()
functions do not handle recursive wildcards (**
).This feature requires disabling automatic argument expansion on Windows in Click. If not disabled, option strings like
.venv/**
will be transformed into.venv\\
before bump-pydantic is able to apply its own interpretation of the string. The only way to pass this argument to Click is during the invocation of the app instance, therefore it was necessary to make the executable function afunctools.partial
.Extra: a list of default ignore patterns has been added, currently only containing
.venv/**
.Extra: if no files are left either because there are no source files in the given directory, or as a result of filtering with ignore patterns, the program now exits gracefully instead of having Mypy raise an error.