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

Implement basic functions to generate recipes for R and Python #594

Merged
merged 2 commits into from Feb 13, 2024

Conversation

wolfv
Copy link
Member

@wolfv wolfv commented Feb 5, 2024

cc @nichmor @tdejager and @marcelotrevisani :)

This is just using rip to extract source dist & wheel informations for a given package name. Doesn't write a recipe at all yet, but this could be a good starting point. One more thing we'd have to do is use the conda mapping that pixi & grayskull use to get the conda-forge package name based on the PyPI package name. Do we have a good API for that, @baszalmstra?

@marcelotrevisani
Copy link

Hey, I have been doing something similar. But it is only on my computer. Due to some personal and work obligations I'm a bit slow on that 😅

@baszalmstra
Copy link
Contributor

The entire "API" can be found here: https://github.com/prefix-dev/pixi/blob/main/src/lock_file/pypi_name_mapping.rs

It's pretty straightforward.

@wolfv
Copy link
Member Author

wolfv commented Feb 7, 2024

@marcelotrevisani I also just implemented a good chunk of PyPI recipe generation :) Would love your feedback.

E.g. I don't know how to decide wether a package can be noarch...

@wolfv wolfv marked this pull request as ready for review February 9, 2024 08:05
@wolfv wolfv changed the title WIP: start implementation of generate recipe functions using rip Implement basic functions to generate recipes for R and Python Feb 9, 2024
@wolfv
Copy link
Member Author

wolfv commented Feb 9, 2024

I started some implementation for evaluating & transforming the marker tree, but I am postponing that for now:

fn rhs_to_string(marker_value: &MarkerValue) -> &str {
    match marker_value {
        MarkerValue::MarkerEnvVersion(_) => "",
        MarkerValue::MarkerEnvString(_) => "",
        MarkerValue::Extra => "",
        MarkerValue::QuotedString(s) => s,
    }
}

fn translate_marker(marker: &MarkerTree, out: &mut String) {
    match marker {
        MarkerTree::Expression(expr) => {
            if expr.l_value == MarkerValue::MarkerEnvVersion(MarkerValueVersion::PythonVersion) {
                out.push_str(&format!("cmp(python, \"{}{}\")", expr.operator, rhs_to_string(&expr.r_value)));
            } else {
                out.push_str(&expr.l_value.to_string());
            }
        }
        MarkerTree::And(exprs) => {
            out.push_str("(");
            for (i, expr) in exprs.iter().enumerate() {
                translate_marker(expr, out);
                if i != exprs.len() - 1 {
                    out.push_str(", ");
                }
            }
            out.push_str(")");
        }
        MarkerTree::Or(exprs) => {
            out.push_str("(");
            for (i, expr) in exprs.iter().enumerate() {
                translate_marker(expr, out);
                if i != exprs.len() - 1 {
                    out.push_str(" || ");
                }
            }
            out.push_str(")");
        }
    }
}

@wolfv wolfv merged commit 9390849 into prefix-dev:main Feb 13, 2024
11 checks passed
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.

None yet

3 participants