Skip to content

Commit

Permalink
Merge pull request #11317 from quarto-dev/tests/python-env/use-uv
Browse files Browse the repository at this point in the history
  • Loading branch information
cderv authored Nov 6, 2024
2 parents 952196e + 4a58848 commit f8a4e35
Show file tree
Hide file tree
Showing 14 changed files with 2,619 additions and 2,295 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/actions/quarto-dev/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ runs:
# Convert the list to an array
$modifiedFilesArray = $modifiedFiles -split "`n" | ForEach-Object { $_.Trim() }
If ($modifiedFilesArray -contains "tests/Pipfile.lock") {
Write-Output "::warning::test/Pipfile.lock has been modified."
$modifiedFilesArray = $modifiedFilesArray | Where-Object { $_ -notmatch "Pipfile.lock" }
If ($modifiedFilesArray -contains "tests/uv.lock") {
Write-Output "::warning::test/uv.lock has been modified."
$modifiedFilesArray = $modifiedFilesArray | Where-Object { $_ -notmatch "uv.lock" }
}
# Count the number of modified files
Expand Down
19 changes: 9 additions & 10 deletions .github/workflows/test-ff-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,17 @@ jobs:
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Python
uses: actions/setup-python@v4
- name: Install uv for Python
uses: astral-sh/setup-uv@v3
with:
python-version: "3.12"
cache: "pipenv"
cache-dependency-path: "./tests/Pipfile.lock"
version: "0.4.30"
enable-cache: true
cache-dependency-glob: "tests/uv.lock"

- name: Restore Python Dependencies
- name: Install Python and Dependencies
working-directory: tests
run: |
python -m pip install pipenv
pipenv install
uv sync --frozen
- uses: ./.github/workflows/actions/quarto-dev

Expand Down Expand Up @@ -157,8 +156,8 @@ jobs:
run: |
# Setup IJulia with the jupyter from the Python environment
# https://julialang.github.io/IJulia.jl/stable/manual/installation/
export JUPYTER=$(find $(dirname $(pipenv run which jupyter))/ -type f -name "jupyter.exe" -o -name "jupyter")
pipenv run julia --color=yes --project=. -e "import Pkg; Pkg.instantiate(); Pkg.build(\"IJulia\"); Pkg.precompile()"
export JUPYTER=$(find $(dirname $(uv run --frozen which jupyter))/ -type f -name "jupyter.exe" -o -name "jupyter")
uv run --frozen julia --color=yes --project=. -e "import Pkg; Pkg.instantiate(); Pkg.build(\"IJulia\"); Pkg.precompile()"
echo "Julia Jupyter:"
julia --project=. -e "import IJulia;println(IJulia.JUPYTER);println(IJulia.find_jupyter_subcommand(\"notebook\"))"
Expand Down
19 changes: 9 additions & 10 deletions .github/workflows/test-smokes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,17 @@ jobs:
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Python
uses: actions/setup-python@v5
- name: Install uv for Python
uses: astral-sh/setup-uv@v3
with:
python-version: "3.12"
cache: "pipenv"
cache-dependency-path: "./tests/Pipfile.lock"
version: "0.4.30"
enable-cache: true
cache-dependency-glob: "tests/uv.lock"

- name: Restore Python Dependencies
- name: Install Python and Dependencies
working-directory: tests
run: |
python -m pip install pipenv==2024.3.0
pipenv install
uv sync --frozen
- uses: ./.github/workflows/actions/quarto-dev

Expand Down Expand Up @@ -181,8 +180,8 @@ jobs:
run: |
# Setup IJulia with the jupyter from the Python environment
# https://julialang.github.io/IJulia.jl/stable/manual/installation/
export JUPYTER=$(find $(dirname $(pipenv run which jupyter))/ -type f -name "jupyter.exe" -o -name "jupyter")
pipenv run julia --color=yes --project=. -e "import Pkg; Pkg.instantiate(); Pkg.build(\"IJulia\"); Pkg.precompile()"
export JUPYTER=$(find $(dirname $(uv run --frozen which jupyter))/ -type f -name "jupyter.exe" -o -name "jupyter")
uv run --frozen julia --color=yes --project=. -e "import Pkg; Pkg.instantiate(); Pkg.build(\"IJulia\"); Pkg.precompile()"
echo "Julia Jupyter:"
julia --project=. -e "import IJulia;println(IJulia.JUPYTER);println(IJulia.find_jupyter_subcommand(\"notebook\"))"
Expand Down
47 changes: 41 additions & 6 deletions dev-docs/configuring-test-deps.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,20 @@

## Python

- Install `pyenv`
- Install a specic version e.g `pyenv install 3.12.1`
- Configure `tests` to use a specific version
- Install `uv`

About uv: https://docs.astral.sh/uv/

`uv` will handle the python versions and virtual environments based on the `.python-version` we have in `tests/` folder.

To set the version to use to

```
cd tests
pyenv local 3.12.1
echo '3.12.7' > .python-version
```

This way when calling `python` in `tests` folder it will always be Python 3.12.1 version
This `uv run` and `uv sync` will create the right virtual environment and use it.

## R

Expand All @@ -43,4 +47,35 @@

# Installing the dependencies in each languages packages

- From `tests` folder, run `configure-test-env` scripts to restore dependencies for each tools
- From `tests` folder, run `configure-test-env.sh` or `configure-test-env.ps1` scripts to restore dependencies for each tools

# Adding some tests dependencies

## Python

- Use `uv add` to add the deps to `pyproject.toml`, install related dependencies in the virtual environment and lock the versions in `uv.lock`.
Example:
```
cd tests
uv add jupyter
```

## R

- Add the dependencies in `DESCRIPTION` file
- Run `renv::install(<package>)` to install the dependencies
- Run `renv::snapshot()` to lock the versions in `renv.lock`

## Julia

- Run Julia in the `tests/` project and add the dependencies
Example:
```bash
cd tests
julia --project=.
```
then in Julia console
```julia
using Pkg
Pkg.add("DataFrames")
```
2 changes: 1 addition & 1 deletion tests/.python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.12.1
3.12.7
23 changes: 0 additions & 23 deletions tests/Pipfile

This file was deleted.

Loading

0 comments on commit f8a4e35

Please sign in to comment.