-
-
Notifications
You must be signed in to change notification settings - Fork 785
♻️ Refactor the handling of shellingham
#1347
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: master
Are you sure you want to change the base?
♻️ Refactor the handling of shellingham
#1347
Conversation
…b.com/nathanjmcdougall/typer into config/lazy-load-shellingham-via-ruff
…b.com/nathanjmcdougall/typer into config/lazy-load-shellingham-via-ruff
This comment was marked as outdated.
This comment was marked as outdated.
…b.com/nathanjmcdougall/typer into config/lazy-load-shellingham-via-ruff
📝 Docs preview for commit 81a8134 at: https://6eec02b4.typertiangolo.pages.dev |
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 motivation to lazy-load rich_utils
was because of performance reasons, as laid out in #1128. Do you see similar performance hits for loading shellingham
?
Fair question, I think probably I'm being loose with my terminology and write-ups. Since The next thing the PR does is introduce a unified method A side effect of having a What about the lazy loading? To answer your question regarding performance, I don't think performance is a concern here. However, I think it's the least confusing approach in light of the above, and it now only occurs in a single file (except the test suite, perhaps we should disable the lazy-loading Ruff rules in the test suite since it adds little value there). |
shellingham
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 for the PR @nathanjmcdougall!
I like the idea of having a HAS_SHELLINGHAM
var declared in core.py
just once, and importing it from there. And using find_spec
instead of the try import
setup we had before.
The new _get_shell_name
also looks good and simplifies various other checks in the code base.
I also agree with putting shellingham.detect_shell
under import ban to ensure we always use the new _get_shell_name
and avoid re-raising the ShellDetectionFailure
.
The only thing I don't necessarily agree with, is enforcing the "lazy loading" of shellingham
in the pyproject.toml
. It feels a bit unnecessarily rigid, especially if we have to rewrite the test files because of it. shellingham
is specified in our requirements-tests.txt
and I personally find the code less clean if the imports aren't all at the top - so I'm not in favour of those edits in the 3 test modules.
Alternatively, if we really do want to enforce using shellingham
only from within functions, it would be nice if we could exclude the test suite.
… specificcally `shellingham.detect_shell`
📝 Docs previewLast commit 88295c1 at: https://e3d99413.typertiangolo.pages.dev |
…b.com/nathanjmcdougall/typer into config/lazy-load-shellingham-via-ruff
Alright, that makes sense to me. I've removed the lazy-loading aspects from the PR. |
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 looks good to me - I'll defer to Tiangolo for a final review though.
See #1297 for motivation.
There's a few places where a conditional check can be simplified but the logic is somewhat subtle. Basically the key thing to bear in mind is that the new
_get_shell_name
method handles the case whereHAS_SHELLINGHAM
is false by returning None.There were a couple calls to
shellingham.detect_shell
that potentially could have raisedShellDetectionFailure
, so I've put this under API ban in favour of the_get_shell_name
method.