-
Notifications
You must be signed in to change notification settings - Fork 63
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: Add to_path() method to ExplicitEnvironmentSpec #781
feat: Add to_path() method to ExplicitEnvironmentSpec #781
Conversation
let mut out = String::new(); | ||
out.push_str("# This file may be used to create an environment using:\n"); | ||
out.push_str("# $ conda create --name <env> --file <this file>\n"); | ||
out.push_str(&format!("# platform: {plat}\n")); |
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 only write this part if the platform is specified.
E.g.
out.push_str(&format!("# platform: {plat}\n")); | |
if let Some(platf) = &self.platform { | |
out.push_str(&format!("# platform: {plat}\n")); | |
} |
out.push_str("# This file may be used to create an environment using:\n"); | ||
out.push_str("# $ conda create --name <env> --file <this file>\n"); |
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.
Im not sure if this part should be included by default. E.g. you could also use (micro)mamba for instance.
out.push_str(&format!("# platform: {plat}\n")); | ||
out.push_str("@EXPLICIT\n"); | ||
|
||
for p in self.packages.iter() { |
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.
for p in self.packages.iter() { | |
for p in &self.packages { |
.collect::<Vec<_>>() | ||
); | ||
|
||
tmp_dir.close().unwrap() |
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 need, this happens on drop.
tmp_dir.close().unwrap() |
let tmp_dir = tempfile::tempdir().unwrap(); | ||
let file_path = tmp_dir.path().join("temp_explicit_env.txt"); | ||
|
||
assert_matches!(env.to_path(file_path.clone()), Ok(())); |
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.
assert_matches!(env.to_path(file_path.clone()), Ok(())); | |
env.to_path(file_path.clone()).expect("failed to write to path!") |
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 just realized I missed this one suggestion in the tests. Do you want me to open another 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.
Its fine, dont worry about it! 👍
Thanks again for contributing!
Might also be interesting to implement this (still draft) spec completely: conda/ceps#79 |
@baszalmstra -- Thank you for the quick review. I'll make the code changes later today. I did have a few questions:
I read through the CEP and was trying to figure out what was needed to implement this completely. The only ideas that I had were arguments to the proposed The other requirements in the CEP were:
Please let me know what in the CEP is missing in your mind and I'll try to implement it. |
I hadnt really checked what needed to happen to implement the CEP. 😅 I think most of it is related to how we parse the file not so much how we write it. In that sense I think your implementation already contains everything required. I dont think it makes sense to add a |
@baszalmstra -- So it sounds like what you think is the best approach is:
if
|
Indeed. And I would indeed forgo the |
@baszalmstra -- I made the requested changes. I just wanted to note that
So maybe an alternative name? Ignore the warning? Or implement |
If you can think of a better name be my guest. I would also be fine with suppressing this particular lint. Even though to_path does little its a nice little utlity function. 👍 |
The best alternatives I could think of at this point are |
I think to_path is still fine and to_spec_string also sounds great! |
…onflict with rust inherent method
@baszalmstra I've renamed the method so everything should be in order now. |
## 🤖 New release * `rattler_conda_types`: 0.26.1 -> 0.26.2 * `rattler`: 0.27.0 -> 0.27.1 * `rattler_cache`: 0.1.2 -> 0.1.3 * `rattler_package_streaming`: 0.21.5 -> 0.21.6 * `rattler_shell`: 0.21.1 -> 0.21.2 * `rattler_lock`: 0.22.14 -> 0.22.15 * `rattler_repodata_gateway`: 0.21.1 -> 0.21.2 * `rattler_solve`: 0.25.1 -> 0.25.2 * `rattler_virtual_packages`: 0.19.18 -> 0.19.19 * `rattler_index`: 0.19.19 -> 0.19.20 <details><summary><i><b>Changelog</b></i></summary><p> ## `rattler_conda_types` <blockquote> ## [0.26.2](rattler_conda_types-v0.26.1...rattler_conda_types-v0.26.2) - 2024-07-23 ### Added - `environment.yaml` type ([#786](#786)) - Add to_path() method to ExplicitEnvironmentSpec ([#781](#781)) - expose `HasPrefixEntry` for public use ([#784](#784)) </blockquote> ## `rattler` <blockquote> ## [0.27.1](rattler-v0.27.0...rattler-v0.27.1) - 2024-07-23 ### Other - updated the following local packages: rattler_conda_types </blockquote> ## `rattler_cache` <blockquote> ## [0.1.3](rattler_cache-v0.1.2...rattler_cache-v0.1.3) - 2024-07-23 ### Other - updated the following local packages: rattler_conda_types </blockquote> ## `rattler_package_streaming` <blockquote> ## [0.21.6](rattler_package_streaming-v0.21.5...rattler_package_streaming-v0.21.6) - 2024-07-23 ### Other - updated the following local packages: rattler_conda_types </blockquote> ## `rattler_shell` <blockquote> ## [0.21.2](rattler_shell-v0.21.1...rattler_shell-v0.21.2) - 2024-07-23 ### Other - updated the following local packages: rattler_conda_types </blockquote> ## `rattler_lock` <blockquote> ## [0.22.15](rattler_lock-v0.22.14...rattler_lock-v0.22.15) - 2024-07-23 ### Other - updated the following local packages: rattler_conda_types </blockquote> ## `rattler_repodata_gateway` <blockquote> ## [0.21.2](rattler_repodata_gateway-v0.21.1...rattler_repodata_gateway-v0.21.2) - 2024-07-23 ### Other - updated the following local packages: rattler_conda_types </blockquote> ## `rattler_solve` <blockquote> ## [0.25.2](rattler_solve-v0.25.1...rattler_solve-v0.25.2) - 2024-07-23 ### Other - updated the following local packages: rattler_conda_types </blockquote> ## `rattler_virtual_packages` <blockquote> ## [0.19.19](rattler_virtual_packages-v0.19.18...rattler_virtual_packages-v0.19.19) - 2024-07-23 ### Other - updated the following local packages: rattler_conda_types </blockquote> ## `rattler_index` <blockquote> ## [0.19.20](rattler_index-v0.19.19...rattler_index-v0.19.20) - 2024-07-23 ### 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/).
Based on feedback from @baszalmstra on discord, I added a
to_path
method to theExplicitEnvironmentSpec
struct so that it could be dumped to file. This would be a first step in apixi export
PR to be submitted later.This is my first rust-based PR to a project (although I've fooled around with it a bit on my own), so feedback is very welcome. For testing,
ExplicitEnvironmentSpec
andExplicitEnvironmentEntry
didn't implementPartialEq
, so I just unrolled the content. This isn't ideal, but I didn't want to start poking around on the main struct definitions, but I can if that's preferred.