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: add support for dependencies in requirements.txt with environment.yml #2883

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

LiamConnors
Copy link
Contributor

@ruben-arts
Copy link
Contributor

Exciting addition!! Let us know when it's ready for review or if you need input!

@LiamConnors
Copy link
Contributor Author

Thanks @ruben-arts! I wasn't 100% sure at which stage would be best to handle the dependencies within the external requirements.txt. I'd love your feedback on this approach. Is there an issue with parsing the external dependencies as if they were directly in the environment.yml file? and if so, and what stage instead do you think those external dependencies should be handled? Also, I'd really appreciate some feedback on the error handling and if you think it's sufficient. Thanks for your help!

@LiamConnors LiamConnors marked this pull request as ready for review January 20, 2025 02:46
@@ -135,6 +144,26 @@ impl CondaEnvFile {
}
}

fn get_deps_from_requirements_txt(indentation: &str, file_path: PathBuf) -> miette::Result<String> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you be able to try to use: https://github.com/astral-sh/uv/blob/73cade13862c88bf2d5344759e9b1b7035b63743/crates/uv-requirements-txt/src/requirement.rs#L41

This might make the code more reliable and have better error messages in the long run.

let base_path = path.parent().unwrap_or_else(|| Path::new(""));
let requirements_file_path = base_path.join(line_parts[1]);
let requirements_txt_pip_deps =
get_deps_from_requirements_txt(line_parts[0], requirements_file_path);
Copy link
Contributor

Choose a reason for hiding this comment

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

In theory, the best place to do the deserialization is in the CondaEnvFile struct. By writing a custom deserializer.

You could impl Deserialize for CondaEnvFile. But this is not a 10 minute refactor.

Otherwise, this location is okay given the current state of the code.

Copy link

Choose a reason for hiding this comment

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

Hey, question from a random guy who's invested in this feature shipping (looking for conda alternatives for ML projects but many open source ml projects still use requirements.txt): When you say using a custom deserializer, would that involve moving the all of from_path into the Deserialize impl, or just the codepath required for the requirements.txt additions?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes indeed, on that implementation you could actually read the file and parse it.

@LiamConnors LiamConnors marked this pull request as draft January 20, 2025 15:58
@LiamConnors
Copy link
Contributor Author

Thanks for the feedback @ruben-arts! Will take a look at your suggestions and let you know once the PR is ready for another look.

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