-
Notifications
You must be signed in to change notification settings - Fork 20
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
support user specified language only installation #97
Conversation
#88 |
It seems we should update init in metrics first. langcheck init all language at once but not check which language was installed. |
Yeah, I had the exact same conclusion. I'm wondering if we should lazy load the language sub-packages so they're still visible at the package level, but won't actually import any dependencies until a function is called. I'll explore this a bit more tomorrow |
Okay, I've implemented lazy loading of language-specific packages in Without lazy loading, the user is required to explicitly load each language, such as
With lazy loading, the user will see the exact same behavior as current LangCheck:
If the user didn't install Japanese dependencies with
I think this is the best UX, but it also adds some complexity to Also, since this is a non-trivial change, I think we should merge this PR after cutting the 0.5.0 release so we have extra time to test it. |
FYI @kennysong SPEC1 mentioned about lazy loading and the latent risk by using lazy_loader library. |
Ah nice find, I hadn't heard of SPEC1 before! The SPEC1 lazy_loader highlights an important difference with the standard library's LazyLoader (which I used). The stdlib LazyLoader doesn't import the actual contents of the package, so while This means that code completion doesn't work: And more importantly, type checking doesn't work: Note that type checks do work if you import the full path: Given this, I think that the current implementation with LazyLoader isn't a good solution. We have two alternatives:
However, option 2 is fairly complex, not under active development (only 96 stars, last release in July 2023), and IMO beyond our team's current bandwidth to properly understand and maintain. I think we should proceed with option 1. This will require users to explicitly import the full path like Let me know what you think! |
I upload my experiment (it can support type checking/ static check). I think through the example below, it can show that the lazy loader used in SPEC1 is quite flexible. they can mix eager import with lazy import, just eager import the ja subpackage but make func under ja package lazy import...so if abused, when times goes on... no one would know which one is lazy import and which one is eager.
As PEP690 was rejected, it seems python would not have a standard way to do lazy import in recent future. |
Thanks for the analysis! I agree that @Vela-zz could you then remove all of the LazyLoader code and fix tests if needed? I can work on updating all of the documentation to reflect the new explicit imports. |
Thanks @Vela-zz! I think this PR is good to go. I was playing around with a bunch of tweaks, and was able to get |
@yosukehigashi or @liwii – Since this is a big change, could one of you could test this PR before merging? The key workflow should look like:
Also, test in VSCode. Install only one language in a venv. Enable that venv in VSCode. Then create a |
Thanks, learn a lot. |
Confirmed that
|
Thanks for testing! I'll merge this now. The only test that's failing is because the HanLP server is down and is unrelated. |
split the dependices into several optional dependencies accroding to which language use it.
now user can install like
TODOs (added by Kenny):
[optional]
optional
pytestsAdd custom error message(not possible)