Skip to content

Commit

Permalink
feat: Export conda environment.yml (#2003)
Browse files Browse the repository at this point in the history
Co-authored-by: Joshua L. Adelman <joshua.adelman@gmail.com>
Co-authored-by: Ruben Arts <ruben@prefix.dev>
  • Loading branch information
3 people committed Sep 17, 2024
1 parent db022c7 commit dc9b79e
Show file tree
Hide file tree
Showing 13 changed files with 664 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,35 @@ jobs:
- build
uses: ./.github/workflows/test_downstream.yml

export-filter:
name: Only run example tests if relevant code or manifests have changed
runs-on: ubuntu-20.04
needs:
- build
outputs:
exports: ${{ steps.filter.outputs.exports }}

steps:
- name: checkout repo
uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
exports:
- src/cli/project/export/conda_environment.rs
- src/cli/project/export/test-data/testenv/*
- examples/pypi-source-deps/*
- examples/pypi-custom-registry/*
- examples/pypi-find-links/*
- examples/docker/*
export_tests:
name: "Export tests"
needs: export-filter
if: ${{ needs.export-filter.outputs.exports == 'true' }}
uses: ./.github/workflows/test_exports.yml

test_common_wheels:
name: "Test installation of common wheels"
needs:
Expand Down
74 changes: 74 additions & 0 deletions .github/workflows/test_exports.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: "Test exports"

on:
workflow_call:


jobs:
test-export:
name: ${{ matrix.arch.name }} - Export Tests
runs-on: ${{ matrix.arch.os }}
strategy:
fail-fast: false
matrix:
arch:
# Linux
- {
target: x86_64-unknown-linux-musl,
os: ubuntu-20.04,
name: "Linux",
}
# MacOS
- { target: x86_64-apple-darwin, os: macos-13, name: "MacOS-x86" }
- { target: aarch64-apple-darwin, os: macos-14, name: "MacOS-arm" } # macOS-14 is the ARM chipset
# # Windows
# - {
# target: x86_64-pc-windows-msvc,
# os: windows-latest,
# extension: .exe,
# name: "Windows",
# }
steps:
- name: checkout repo
uses: actions/checkout@v4
- name: setup micromamba
uses: mamba-org/setup-micromamba@v1.8.1
- name: Download binary from build
uses: actions/download-artifact@v4
with:
name: pixi-${{ matrix.arch.target }}${{ matrix.arch.extension }}
path: pixi_bin
- name: Debug
run: |
pwd
- name: Setup unix binary, add to github path
if: matrix.arch.name != 'Windows'
run: |
mv pixi_bin/pixi-${{ matrix.arch.target }} pixi_bin/pixi
chmod a+x pixi_bin/pixi
echo "$(pwd)/pixi_bin" >> $GITHUB_PATH
- name: Create Directory and Move Executable
if: matrix.arch.name == 'Windows' && matrix.arch.target == 'x86_64-pc-windows-msvc'
run: |
New-Item -ItemType Directory -Force -Path "D:\.pixi"
Move-Item -Path "pixi_bin/pixi-${{ matrix.arch.target }}${{ matrix.arch.extension }}" -Destination "D:\.pixi\pixi.exe"
shell: pwsh
- name: Add to PATH
if: matrix.arch.name == 'Windows' && matrix.arch.target == 'x86_64-pc-windows-msvc'
run: echo "D:\.pixi" | Out-File -Append -Encoding utf8 -FilePath $env:GITHUB_PATH
shell: pwsh
- name: Verify and Use Executable
if: matrix.arch.name == 'Windows' && matrix.arch.target == 'x86_64-pc-windows-msvc'
run: |
echo "Current PATH: $env:PATH"
pixi --version
shell: pwsh
- name: Help
run: pixi --help
- name: Info
run: pixi info
- name: Install pixi
run: pixi install -v
- name: Test export
shell: bash
run: bash tests/test_export.sh
23 changes: 23 additions & 0 deletions docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,29 @@ List the environments in the manifest file.
pixi project environment list
```

### `project export conda_environment`

Exports a conda [`environment.yml` file](https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-from-an-environment-yml-file). The file can be used to create a conda environment using conda/mamba:

```shell
pixi project export conda-environment environment.yml
mamba create --name <env> --file environment.yml
```

##### Arguments

1. `<OUTPUT_PATH>`: Optional path to render environment.yml to. Otherwise it will be printed to standard out.

##### Options

- `--environment <ENVIRONMENT> (-e)`: Environment to render.
- `--platform <PLATFORM> (-p)`: The platform to render.

```sh
pixi project export conda-environment --environment lint
pixi project export conda-environment --platform linux-64 environment.linux-64.yml
```

### `project export conda_explicit_spec`

Render a platform-specific conda [explicit specification file](https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#building-identical-conda-environments)
Expand Down
6 changes: 6 additions & 0 deletions docs/switching_from/conda.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ pixi init --import environment.yml
```
This will create a new project with the dependencies from the `environment.yml` file.

??? tip "Exporting your environment"
If you are working with Conda users or systems, you can [export your environment to a `environment.yml`](../reference/cli.md#project-export-conda_environment) file to share them.
```shell
pixi project export conda
```
Additionally you can export a [conda explicit specification](../reference/cli.md#project-export-conda_explicit_spec).

## Troubleshooting
Encountering issues? Here are solutions to some common problems when being used to the `conda` workflow:
Expand Down
Loading

0 comments on commit dc9b79e

Please sign in to comment.