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

[WIP] Pruebas con pixi #54

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# GitHub syntax highlighting
pixi.lock linguist-language=YAML linguist-generated=true
11 changes: 7 additions & 4 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
- package-ecosystem: github-actions
directory: /
schedule:
interval: "weekly"
interval: monthly
groups:
dependencies:
patterns:
- "*"
28 changes: 11 additions & 17 deletions .github/workflows/pre-commit-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: prefix-dev/[email protected]
with:
# required to grab the history of the PR
fetch-depth: 0
# Not needed since uv installs python automatically
# - uses: actions/setup-python@v5
# with:
# python-version-file: ".python-version"
- name: Set up uv
run: curl -LsSf https://astral.sh/uv/0.4.3/install.sh | sh
# Needed for mypy, since the pre-commit hook is run in "system" mode
- name: Install dependencies
run: |
uv sync --dev --frozen
# Workaround to allow pre-commit to find the venv where dependencies are installed
- run: |
echo "$PWD/.venv/bin" >> $GITHUB_PATH
uv pip install pip
- uses: pre-commit/[email protected]
pixi-version: v0.29.0
cache: true
environments: dev
activate-environment: true
- uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: pre-commit-3|${{ hashFiles('.pre-commit-config.yaml') }}
- run: pre-commit run --show-diff-on-failure --color=always --all-files
shell: bash
27 changes: 11 additions & 16 deletions .github/workflows/pre-commit-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,15 @@ jobs:
with:
# required to grab the history of the PR
fetch-depth: 0
# Not needed since uv installs python automatically
# - uses: actions/setup-python@v5
# with:
# python-version-file: ".python-version"
- name: Set up uv
run: curl -LsSf https://astral.sh/uv/0.4.3/install.sh | sh
# Needed for mypy, since the pre-commit hook is run in "system" mode
- name: Install dependencies
run: uv sync --dev --frozen
# Workaround to allow pre-commit to find the venv where dependencies are installed
- run: |
echo "$PWD/.venv/bin" >> $GITHUB_PATH
uv pip install pip
- uses: pre-commit/[email protected]
- uses: prefix-dev/[email protected]
with:
# Ejecutar solo en ficheros que hayan cambiado https://github.com/pre-commit/action/issues/7
extra_args: --color=always --from-ref ${{ github.event.pull_request.base.sha }} --to-ref ${{ github.event.pull_request.head.sha }}
pixi-version: v0.29.0
cache: true
environments: dev
activate-environment: true
- uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: pre-commit-3|${{ hashFiles('.pre-commit-config.yaml') }}
- run: pre-commit run --show-diff-on-failure --color=always --from-ref ${{ github.event.pull_request.base.sha }} --to-ref ${{ github.event.pull_request.head.sha }}
shell: bash
15 changes: 7 additions & 8 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ jobs:
runs-on: "ubuntu-latest"
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
environment: [py39, py310, py311, py312]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: prefix-dev/setup-[email protected]
with:
python-version: ${{ matrix.python-version }}
- name: Set up uv
run: curl -LsSf https://astral.sh/uv/0.4.3/install.sh | sh
pixi-version: v0.29.0
cache: true
environments: ${{ matrix.environment }}
activate-environment: true
- name: Test with pytest
run: |
uv sync --dev --frozen
uv run pytest
run: pytest
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,6 @@ Icon
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
.apdisk# pixi environments
.pixi
*.egg-info
1 change: 0 additions & 1 deletion .python-version

This file was deleted.

25 changes: 11 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,28 @@ DOCKER_CONTAINER=template
GH_USER=GITHUB_USERNAME
GH_TOKEN_FILE=GITHUB_TOKEN_PATH

# Install uv, pre-commit hooks and dependencies
# Note that `uv run` has an implicit `uv sync`, since it will (if necessary):
# - Download an install Python
# - Create a virtual environment
# - Update `uv.lock`
# - Sync the virtual env, installing and removing dependencies as required
# Install pixi, dependencies and pre-commit hooks
install:
curl -LsSf https://astral.sh/uv/install.sh | sh
uv run pre-commit install
curl -fsSL https://pixi.sh/install.sh | bash
pixi install
pixi install -e dev
pixi run -e dev pre-commit install

hooks:
uv run pre-commit run --all-files
pixi run -e dev pre-commit run --all-files

hooks-update:
uv run pre-commit autoupdate
pixi run -e dev pre-commit autoupdate

ruff:
uv run ruff format .
uv run ruff check --fix --show-fixes .
pixi run -e dev ruff format .
pixi run -e dev ruff check --fix --show-fixes .

test:
uv run pytest
pixi run -e dev pytest

mypy:
uv run mypy --install-types --non-interactive
pixi run -e dev mypy --install-types --non-interactive

docker: build run

Expand Down
69 changes: 46 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Conveniently, a set of workflows via Github Actions are already installed:

Tools:

- [uv](https://docs.astral.sh/uv/): manage dependencies, Python versions and virtual environments
- [pixi](https://pixi.sh/latest/): manage dependencies, Python versions and virtual environments
- [ruff](https://docs.astral.sh/ruff/): lint and format Python code
- [mypy](https://mypy.readthedocs.io/): check types
- [pytest](https://docs.pytest.org/en/): run unit tests
Expand All @@ -33,82 +33,103 @@ Tools:

### Application

Install package and pinned dependencies with the [`uv`](https://docs.astral.sh/uv/) package manager:
Install package and pinned dependencies with the [`pixi`](https://pixi.sh/latest/) package manager:

1. Install `uv`. See instructions for Windows, Linux or MacOS [here](https://docs.astral.sh/uv/getting-started/installation/).
1. Install `pixi`. See instructions for Windows, Linux or MacOS [here](https://pixi.sh/latest/).

2. Clone repository

3. Install package and dependencies in a virtual environment:

```{bash}
uv sync
pixi install
```

4. Run any command or Python script with `uv run`, for instance:
4. Run any command or Python script with `pixi run`, for instance:

```{bash}
uv run template/main.py
pixi run template/main.py
```

Alternatively, you can also activate the virtual env and run the scripts normally:

```{bash}
source .venv/bin/activate
pixi shell
```

### Library

Install a specific version of the package with `pip` or `uv pip`:
Install a specific version of the package with `pip`:

```{bash}
pip install git+ssh://[email protected]/Komorebi-AI/[email protected]
```

## Setup development environment (Unix)

Install [`uv`](https://docs.astral.sh/uv/getting-started/installation/) and pre-commit hooks:
Install [`pixi`](https://pixi.sh/dev/) and pre-commit hooks:

```{bash}
make install
```

`uv` will automatically create a virtual environment with the specified Python version in `.python-version` and install the dependencies from `uv.lock` (both standard and dev dependencies). It will also install the package in editable mode.
`pixi` will automatically create a virtual environment with the specified Python version in `.python-version` and install the dependencies from `pixi.lock`. It will create two environments, `default` and `dev` with the standard and dev dependencies respectively. It will also install the package in editable mode.

The packages installed in each environment can be listed with `pixi list` or `pixi tree`:

```{bash}
pixi list
pixi list -e dev
```

To run commands in the default environment use `pixi run` and to run commands in the `dev` environment use `pixi run -e dev`. You can also activate the environments with `pixi shell` or `pixi shell -e dev`.

More information can be found in the [official documentation](https://pixi.sh/dev/tutorials/python/).

### Adding new dependencies

Add dependencies with:

```{bash}
uv add <PACKAGE>
pixi add <PACKAGE>
```

Add dev dependencies with:

```{bash}
uv add --dev <PACKAGE>
pixi add --feature dev <PACKAGE>
```

Remove dependencies with:

```{bash}
pixi remove <PACKAGE>
```

Remove dependency with:
If the dependency is not available in conda, we can install the pypi version with:

```{bash}
uv remove <PACKAGE>
pixi add --pypi <PACKAGE>
```

In all cases `uv` will automatically update the `uv.lock` file and sync the virtual environment. This can also be done manually with:
In all cases `pixi` will automatically update the `pixi.lock` file and sync the virtual environment. This can also be done manually with:

```{bash}
uv sync
pixi install
```

### Tools

#### Run pre-commit hooks
Tools are set both in the `Makefile` and also as `pixi` tasks. They can be run using either `make <ALIAS>` or `pixi run -e dev <ALIAS>`, for example:

Hooks are run on modified files before any commit. To run them manually on all files use:
```{bash}
pixi run -e dev test
```

#### Run tests

```{bash}
make hooks
make test
```

#### Run linter and formatter
Expand All @@ -117,14 +138,16 @@ make hooks
make ruff
```

#### Run tests
#### Run type checker

```{bash}
make test
make mypy
```

#### Run type checker
#### Run pre-commit hooks

Hooks are run on modified files before any commit. To run them manually on all files use:

```{bash}
make mypy
make hooks
```
Loading