Skip to content
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

Merged
merged 36 commits into from
Aug 30, 2024
Merged

Conversation

SobhanMP
Copy link
Contributor

@SobhanMP SobhanMP commented Aug 22, 2024

Following 721a6c1, this commit will start adding the interface for python.

@SobhanMP SobhanMP changed the title start adding interface to override feat: start adding interface to override Aug 22, 2024
@SobhanMP
Copy link
Contributor Author

@baszalmstra Should VirtualPackageOverride be accessible from python?

@iamthebot
Copy link
Contributor

@baszalmstra Should VirtualPackageOverride be accessible from python?

@SobhanMP we'd use this-- can you include it?

@SobhanMP
Copy link
Contributor Author

@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?

@iamthebot
Copy link
Contributor

@SobhanMP

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 VirtualPackageOverride we can't control that override directly from Python side.

Comment on lines 186 to 187
static DETECTED_VIRTUAL_PACKAGES: OnceCell<Vec<VirtualPackage>> = OnceCell::new();
DETECTED_VIRTUAL_PACKAGES
Copy link
Collaborator

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.

Copy link
Contributor Author

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> {
Copy link
Collaborator

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?

Copy link
Contributor Author

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>,
Copy link
Collaborator

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.

Copy link
Collaborator

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:

  1. dont use any override
  2. use the default env var if it exists,
  3. use the environment variable with a specific name.

that way we can get rid of all the slightly different functions.

WDYT?

Copy link
Contributor Author

@SobhanMP SobhanMP Aug 27, 2024

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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please implement Default

Copy link
Contributor Author

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.

@SobhanMP
Copy link
Contributor Author

SobhanMP commented Aug 28, 2024

@baszalmstra where would be the right place to put the tests? and is this interface/impl ok?

❯ CONDA_OVERRIDE_CUDA=1984 pixi run rattler create jupyterlab
Pixi task (rattler in default): cargo run --bin rattler --release -- create jupyterlab
    Finished release [optimized] target(s) in 0.13s
     Running `.pixi/target/release/rattler create jupyterlab`
Target prefix: /home/psi/rattler/.prefix
Installing for platform: Linux64
Loaded 20237 records in 520.548978ms
Virtual packages:
  - __unix=0=0
  - __linux=6.6.45=0
  - __glibc=2.40=0
  - __cuda=1984=0
  - __archspec=1=x86_64_v4

 Already up to date

@baszalmstra
Copy link
Collaborator

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.

@SobhanMP
Copy link
Contributor Author

SobhanMP commented Aug 28, 2024

@baszalmstra I think this is done (minus minor ci failure), unless overrides should also override checks like platform.is_linux (i.e., should we move the conditionals inside the current function?)

@SobhanMP SobhanMP requested a review from baszalmstra August 28, 2024 16:31
Copy link
Collaborator

@baszalmstra baszalmstra left a 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!

crates/rattler_virtual_packages/src/lib.rs Outdated Show resolved Hide resolved
crates/rattler_virtual_packages/src/lib.rs Outdated Show resolved Hide resolved
crates/rattler_virtual_packages/src/lib.rs Outdated Show resolved Hide resolved
crates/rattler_virtual_packages/src/lib.rs Show resolved Hide resolved
crates/rattler_virtual_packages/src/lib.rs Outdated Show resolved Hide resolved
crates/rattler_virtual_packages/src/lib.rs Outdated Show resolved Hide resolved
py-rattler/rattler/virtual_package/virtual_package.py Outdated Show resolved Hide resolved
py-rattler/rattler/virtual_package/virtual_package.py Outdated Show resolved Hide resolved
crates/rattler_virtual_packages/src/lib.rs Outdated Show resolved Hide resolved
@SobhanMP
Copy link
Contributor Author

@baszalmstra, I did the renaming and the deprecation. I think that's everything. Apologies if I missed something.

right now:

  • current is the old current
  • detect is detect with defaults
  • VirtualPackageOverrides.__init__ replaces VirtualPackageOverrides.default
  • Some documentation on the python side
  • The functions are detect_with_overrides and detect_with_fallback.

@SobhanMP SobhanMP requested a review from baszalmstra August 29, 2024 15:24
}

/// Detect the virtual packages of the current system with the default overrides.
pub fn detect() -> Result<Vec<Self>, DetectVirtualPackageError> {
Copy link
Collaborator

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.

Copy link
Contributor Author

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 😅

Copy link
Collaborator

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.

Copy link
Contributor Author

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.

crates/rattler_virtual_packages/src/lib.rs Outdated Show resolved Hide resolved
py-rattler/tests/unit/test_override.py Outdated Show resolved Hide resolved
py-rattler/rattler/virtual_package/virtual_package.py Outdated Show resolved Hide resolved
py-rattler/rattler/virtual_package/virtual_package.py Outdated Show resolved Hide resolved
@SobhanMP SobhanMP requested a review from baszalmstra August 29, 2024 19:21
return VirtualPackage.detect_with_overrides(VirtualPackageOverrides.none())

@staticmethod
def detect_with_overrides(overrides: VirtualPackageOverrides | None = None) -> List[VirtualPackage]:
Copy link
Collaborator

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.

Copy link
Contributor Author

@SobhanMP SobhanMP Aug 29, 2024

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?

Copy link
Collaborator

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"
Copy link
Collaborator

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?

Copy link
Contributor Author

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 🤷

Copy link
Collaborator

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.

Copy link
Collaborator

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.

@SobhanMP SobhanMP requested a review from baszalmstra August 29, 2024 20:22
@baszalmstra
Copy link
Collaborator

Thanks! Sorry it took so long!

@SobhanMP
Copy link
Contributor Author

No worries, thanks for all the helpful comments!

@baszalmstra baszalmstra enabled auto-merge (squash) August 30, 2024 17:46
@baszalmstra baszalmstra merged commit 8a9fed3 into conda:main Aug 30, 2024
15 checks passed
@baszalmstra baszalmstra mentioned this pull request Aug 30, 2024
@SobhanMP SobhanMP deleted the env branch August 30, 2024 17:59
baszalmstra added a commit that referenced this pull request Sep 2, 2024
## 🤖 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/).
kelvinou01 pushed a commit to kelvinou01/rattler that referenced this pull request Sep 3, 2024
## 🤖 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/).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants