-
Notifications
You must be signed in to change notification settings - Fork 65
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
feat: start adding interface to override #834
Conversation
@baszalmstra Should |
@SobhanMP we'd use this-- can you include it? |
@iamthebot (we'd have to ask @baszalmstra), but as things are, the overrides are enabled by default, so they work. Do you need to rename the overrides? |
Sorry, I think I misunderstood. We'd like to be able to specify the overrides for eg; CUDA directly without needing to use an env var for the override. If I'm reading this correctly-- as written, the overrides would work via env var directly but without exposing |
static DETECTED_VIRTUAL_PACKAGES: OnceCell<Vec<VirtualPackage>> = OnceCell::new(); | ||
DETECTED_VIRTUAL_PACKAGES |
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 caches the values but based on the input which means if you call it a second time with different input you get the same result as rhe first time. I think it would be better to not cache the values here and return a Vec.
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.
Good point.
@@ -136,6 +170,24 @@ impl VirtualPackage { | |||
.get_or_try_init(try_detect_virtual_packages) | |||
.map(Vec::as_slice) | |||
} | |||
|
|||
/// disable overrides | |||
pub fn current_no_overrides() -> Result<&'static [Self], DetectVirtualPackageError> { |
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.
Isnt this just the same as the current
method?
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.
I changed the default to match conda (i.e. use the default overrides)
/// Configure the overrides used in in this crate. | ||
|
||
pub struct VirtualPackageOverride<'a> { | ||
osx: Option<&'a str>, |
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.
Perhaps use an Option<String>
to remove the need for lifetimes.
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.
I wonder if maybe we should change this to a trie state:
- dont use any override
- use the default env var if it exists,
- use the environment variable with a specific name.
that way we can get rid of all the slightly different functions.
WDYT?
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.
I agree, but how about a 4th option that forces a specific version? (I think @iamthebot would like that), I'll give this a try, and if it doesn't work, we can revert to the last commit.
} | ||
|
||
/// Use the default overrides of Conda. | ||
fn default() -> Self { |
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 implement Default
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.
Default
as in the default trait? Will do, did not know it was a thing.
@baszalmstra where would be the right place to put the tests? and is this interface/impl ok?
|
I dont think we need an end-to-end test. I would place some unit tests in the lib.rs that test a few different overrides. Watch out with environment variables though because rust runs all tests in parallel. |
@baszalmstra I think this is done (minus minor ci failure), unless overrides should also override checks like |
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 is starting to shape up nicely!
@baszalmstra, I did the renaming and the deprecation. I think that's everything. Apologies if I missed something. right now:
|
} | ||
|
||
/// Detect the virtual packages of the current system with the default overrides. | ||
pub fn detect() -> Result<Vec<Self>, DetectVirtualPackageError> { |
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.
Lets just remove this function in favor of detect_with_overrides
. I dont think we need an overload without an argument.
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.
I think
let virtual_packages = rattler_virtual_packages::VirtualPackage::detect_with_overrides(&rattler_virtual_packages::VirtualPackageOverrides::default())?;
is not very concise 😅
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.
VirtualPackage::detect(&Default::default())
seems fine to me.
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.
hmm, yeah, that works. Somehow, Default
is more robust than what I imagined.
Co-authored-by: Bas Zalmstra <zalmstra.bas@gmail.com>
return VirtualPackage.detect_with_overrides(VirtualPackageOverrides.none()) | ||
|
||
@staticmethod | ||
def detect_with_overrides(overrides: VirtualPackageOverrides | None = None) -> List[VirtualPackage]: |
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.
Maybe we can rename to detect? With or without override is already defined by the argument.
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.
I think this is outdated, right?
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.
No I think we should just have one function called detect which you can pass an override or not. I think its superfluous to also add with_override to the name.
.map(Vec::as_slice) | ||
#[deprecated( | ||
since = "1.0.4", | ||
note = "Use `Self::detect(&Default::default)` instead" |
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.
mm I guess this should be none right?
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.
I'd argue no, because the expectation is to be conda compatible 🤷
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.
I disagree, rattler is also used in applications where this outside environment override behavior is unwanted. For an application this behavior makes sense but for a library I think reading from environment variables should be opt in.
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.
Furthermore, this suggestion changes the default current behavior of the function. I think the depreciation should tell people how to migrate to something which exhibits the same behavior.
Thanks! Sorry it took so long! |
No worries, thanks for all the helpful comments! |
## 🤖 New release * `rattler_conda_types`: 0.27.2 -> 0.27.3 * `rattler_package_streaming`: 0.22.3 -> 0.22.4 * `rattler_lock`: 0.22.20 -> 0.22.21 * `rattler_solve`: 1.0.3 -> 1.0.4 * `rattler_virtual_packages`: 1.0.4 -> 1.1.0 * `rattler_index`: 0.19.24 -> 0.19.25 * `rattler`: 0.27.6 -> 0.27.7 * `rattler_cache`: 0.1.8 -> 0.1.9 * `rattler_shell`: 0.21.6 -> 0.21.7 * `rattler_repodata_gateway`: 0.21.8 -> 0.21.9 <details><summary><i><b>Changelog</b></i></summary><p> ## `rattler_conda_types` <blockquote> ## [0.27.3](rattler_conda_types-v0.27.2...rattler_conda_types-v0.27.3) - 2024-09-02 ### Added - add edge case tests for `StringMatcher` ([#839](#839)) </blockquote> ## `rattler_package_streaming` <blockquote> ## [0.22.4](rattler_package_streaming-v0.22.3...rattler_package_streaming-v0.22.4) - 2024-09-02 ### Added - Add support for `CONDA_OVERRIDE_CUDA` ([#818](#818)) ### Fixed - zip large files compression ([#838](#838)) </blockquote> ## `rattler_lock` <blockquote> ## [0.22.21](rattler_lock-v0.22.20...rattler_lock-v0.22.21) - 2024-09-02 ### Added - Add support for `CONDA_OVERRIDE_CUDA` ([#818](#818)) </blockquote> ## `rattler_solve` <blockquote> ## [1.0.4](rattler_solve-v1.0.3...rattler_solve-v1.0.4) - 2024-09-02 ### Fixed - Redact spec channel before comparing it with repodata channel ([#831](#831)) ### Other - Remove note that only libsolv is supported ([#832](#832)) </blockquote> ## `rattler_virtual_packages` <blockquote> ## [1.1.0](rattler_virtual_packages-v1.0.4...rattler_virtual_packages-v1.1.0) - 2024-09-02 ### Added - start adding interface to override ([#834](#834)) - Add support for `CONDA_OVERRIDE_CUDA` ([#818](#818)) ### Other - make virtual package overrides none by default consistently ([#842](#842)) </blockquote> ## `rattler_index` <blockquote> ## [0.19.25](rattler_index-v0.19.24...rattler_index-v0.19.25) - 2024-09-02 ### Other - release ([#824](#824)) </blockquote> ## `rattler` <blockquote> ## [0.27.7](rattler-v0.27.6...rattler-v0.27.7) - 2024-09-02 ### Other - updated the following local packages: rattler_conda_types, rattler_package_streaming </blockquote> ## `rattler_cache` <blockquote> ## [0.1.9](rattler_cache-v0.1.8...rattler_cache-v0.1.9) - 2024-09-02 ### Other - updated the following local packages: rattler_conda_types, rattler_package_streaming </blockquote> ## `rattler_shell` <blockquote> ## [0.21.7](rattler_shell-v0.21.6...rattler_shell-v0.21.7) - 2024-09-02 ### Other - updated the following local packages: rattler_conda_types </blockquote> ## `rattler_repodata_gateway` <blockquote> ## [0.21.9](rattler_repodata_gateway-v0.21.8...rattler_repodata_gateway-v0.21.9) - 2024-09-02 ### Other - updated the following local packages: rattler_conda_types </blockquote> </p></details> --- This PR was generated with [release-plz](https://github.com/MarcoIeni/release-plz/).
## 🤖 New release * `rattler_conda_types`: 0.27.2 -> 0.27.3 * `rattler_package_streaming`: 0.22.3 -> 0.22.4 * `rattler_lock`: 0.22.20 -> 0.22.21 * `rattler_solve`: 1.0.3 -> 1.0.4 * `rattler_virtual_packages`: 1.0.4 -> 1.1.0 * `rattler_index`: 0.19.24 -> 0.19.25 * `rattler`: 0.27.6 -> 0.27.7 * `rattler_cache`: 0.1.8 -> 0.1.9 * `rattler_shell`: 0.21.6 -> 0.21.7 * `rattler_repodata_gateway`: 0.21.8 -> 0.21.9 <details><summary><i><b>Changelog</b></i></summary><p> ## `rattler_conda_types` <blockquote> ## [0.27.3](conda/rattler@rattler_conda_types-v0.27.2...rattler_conda_types-v0.27.3) - 2024-09-02 ### Added - add edge case tests for `StringMatcher` ([conda#839](conda#839)) </blockquote> ## `rattler_package_streaming` <blockquote> ## [0.22.4](conda/rattler@rattler_package_streaming-v0.22.3...rattler_package_streaming-v0.22.4) - 2024-09-02 ### Added - Add support for `CONDA_OVERRIDE_CUDA` ([conda#818](conda#818)) ### Fixed - zip large files compression ([conda#838](conda#838)) </blockquote> ## `rattler_lock` <blockquote> ## [0.22.21](conda/rattler@rattler_lock-v0.22.20...rattler_lock-v0.22.21) - 2024-09-02 ### Added - Add support for `CONDA_OVERRIDE_CUDA` ([conda#818](conda#818)) </blockquote> ## `rattler_solve` <blockquote> ## [1.0.4](conda/rattler@rattler_solve-v1.0.3...rattler_solve-v1.0.4) - 2024-09-02 ### Fixed - Redact spec channel before comparing it with repodata channel ([conda#831](conda#831)) ### Other - Remove note that only libsolv is supported ([conda#832](conda#832)) </blockquote> ## `rattler_virtual_packages` <blockquote> ## [1.1.0](conda/rattler@rattler_virtual_packages-v1.0.4...rattler_virtual_packages-v1.1.0) - 2024-09-02 ### Added - start adding interface to override ([conda#834](conda#834)) - Add support for `CONDA_OVERRIDE_CUDA` ([conda#818](conda#818)) ### Other - make virtual package overrides none by default consistently ([conda#842](conda#842)) </blockquote> ## `rattler_index` <blockquote> ## [0.19.25](conda/rattler@rattler_index-v0.19.24...rattler_index-v0.19.25) - 2024-09-02 ### Other - release ([conda#824](conda#824)) </blockquote> ## `rattler` <blockquote> ## [0.27.7](conda/rattler@rattler-v0.27.6...rattler-v0.27.7) - 2024-09-02 ### Other - updated the following local packages: rattler_conda_types, rattler_package_streaming </blockquote> ## `rattler_cache` <blockquote> ## [0.1.9](conda/rattler@rattler_cache-v0.1.8...rattler_cache-v0.1.9) - 2024-09-02 ### Other - updated the following local packages: rattler_conda_types, rattler_package_streaming </blockquote> ## `rattler_shell` <blockquote> ## [0.21.7](conda/rattler@rattler_shell-v0.21.6...rattler_shell-v0.21.7) - 2024-09-02 ### Other - updated the following local packages: rattler_conda_types </blockquote> ## `rattler_repodata_gateway` <blockquote> ## [0.21.9](conda/rattler@rattler_repodata_gateway-v0.21.8...rattler_repodata_gateway-v0.21.9) - 2024-09-02 ### Other - updated the following local packages: rattler_conda_types </blockquote> </p></details> --- This PR was generated with [release-plz](https://github.com/MarcoIeni/release-plz/).
Following 721a6c1, this commit will start adding the interface for python.