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

Command to create new Pixi environments from requirements.txt or environment.yml files #1410

Open
jacobj45 opened this issue May 18, 2024 · 12 comments
Labels
✨ enhancement Feature request

Comments

@jacobj45
Copy link

jacobj45 commented May 18, 2024

Description

It would be great to have a command that can create new Pixi environments from existing requirements.txt (pip) or environment.yml (conda) files.

Motivation

Having such a command would make it easier for existing projects that use these files for dependency management to migrate to Pixi.

@jacobj45 jacobj45 added the ✨ enhancement Feature request label May 18, 2024
@olivier-lacroix
Copy link
Contributor

You can already import an environment.yml during init via pixi init —import

@jacobj45
Copy link
Author

Thanks, could not find any references to this while going through the docs.

Does this command also work with requirements.txt?

@olivier-lacroix
Copy link
Contributor

Nope, it does not sorry.

@ruben-arts
Copy link
Contributor

Linking this to a discord chat: https://discord.com/channels/1082332781146800168/1261794228460195910

For those reading this, we would also like to support requirements.txt like we do with environment.yml.

Which means reading requirements.txt files during the pixi init --import requirements.txt. This being PyPI dependencies this should automatically add a python dependency as well and move all the requirements to [pypi-dependencies]. This could be extended in the future with smarter conda-pypi mapping logic. But lets keep the initial pr simple with the inclusion of the requirements.txt reading.

@Kaweees mentioned in Discord he wanted to give this a go, please do!

@roaldarbol
Copy link

In case pixi init --import fails due to the strict channel priority, it would be great if it falls back to disabling the strict channel priority. The ability to disable the strict channel priority has already been implemented in rattler (conda/rattler#598), but not yet exposed in pixi (#1254), so when it gets implemented it could be added to --import as well.

@ctrueden
Copy link

ctrueden commented Aug 15, 2024

@jacobj45 Could you clarify the intended scope of this issue? I'm new to pixi, but from what I understand so far, pixi init --import creates a new pixi project with one new default environment matching the given environment.yml. But even if that environment.yml defines the name with, say, name: spiffy, the resultant environment in the newly formed pixi project will always be named default.

So my questions are:

  • Is there currently a way to import an environment.yml as a new environment within an existing project? My impression so far is no.
  • If not: the phrasing of this issue suggests the desire to have such a feature, no?

I ask because all the discussion above is focused on creating new pixi projects from requirements.txt files, but no discussion of multiple environments for a particular pixi project.

@ruben-arts
Copy link
Contributor

Hi @ctrueden, good question. This issue was indeed always looked at from the project idea. But I agree it would be awesome to have an import command on an existing project! I haven't giving this much though yet but I could imagine we support --import on pixi add.

@olivier-lacroix what do you think of that?

@ctrueden
Copy link

I could imagine we support --import on pixi add.

What about a new toplevel command pixi import with optional --environment flag to set/override the destination environment name? And the existing pixi init --import ... could keep the current behavior, which would be essentially a shorthand for pixi init; pixi import --environment default ...?

@olivier-lacroix
Copy link
Contributor

@ctrueden I like that option :-)

@maresb
Copy link
Contributor

maresb commented Sep 15, 2024

I just used conda-lock's source parsing capabilities to create a pixi.toml generator that works for environment.yml, pyproject.toml, and multiple combinations thereof. I'm planning to release it soon as part of conda-lock, but for now it's only available on the main branch.

You can get it with:

pipx install --force git+https://github.com/conda/conda-lock@main

You can generate a pixi.toml by running a command like the following:

conda-lock render-lock-spec --kind=pixi.toml --stdout \
  --file=environments/dev-environment.yaml \
  --file=pyproject.toml \
  --pixi-project-name=conda-lock \
  --editable conda-lock=. \
  > pixi.toml

You can view the result here.

This should hopefully work in general with almost any pyproject.toml or environment.yml. Just run a command similar to the above and pixi should be ready to go. You don't need to be a previous conda-lock user to migrate projects with it.

@maresb
Copy link
Contributor

maresb commented Sep 16, 2024

I threw together a quick draft of a migration guide in conda/conda-lock#708: preview link.

I'm hoping to use this technique to migrate a bunch of projects to pixi. I hope it can help others do the same!

I'm very eager to get feedback 😁

@aegroto
Copy link

aegroto commented Nov 11, 2024

Looks like pixi add --pypi $(cat requirements.txt) does the trick, although having specific support for requirements.txt files would be better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement Feature request
Projects
None yet
Development

No branches or pull requests

7 participants