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

Use uv #1451

Merged
merged 2 commits into from
Sep 27, 2024
Merged

Use uv #1451

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .codespellignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
keypair
astroid
uvloop
142 changes: 20 additions & 122 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,45 +46,18 @@ jobs:
needs.paths-filter.outputs.kakarot_scripts == 'true'
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10.14
uses: actions/setup-python@v5
with:
python-version: 3.10.14
- name: Load cached Poetry installation
id: cached-poetry
uses: actions/cache@v4
- uses: astral-sh/setup-uv@v2
with:
path: ~/.local
key: poetry-${{ runner.os }}
- name: Install Poetry
if: steps.cached-poetry.outputs.cache-hit != 'true'
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
virtualenvs-path: .venv
installer-parallel: true
- name: Enforce poetry config
run: |
poetry config virtualenvs.in-project true
poetry config virtualenvs.create true
poetry config virtualenvs.path .venv
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
enable-cache: true
cache-dependency-glob: uv.lock
- uses: actions/setup-python@v5
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: make setup
python-version-file: .python-version
- uses: asdf-vm/actions/install@v3
- run: asdf install
# Build artifacts
- name: Compile all the cairo files
run: make build

# Upload artifacts
- name: Uploads Kakarot build artifacts
uses: actions/upload-artifact@v3
with:
Expand All @@ -101,38 +74,13 @@ jobs:
needs.paths-filter.outputs.tests == 'true'
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10.14
uses: actions/setup-python@v5
with:
python-version: 3.10.14
- name: Load cached Poetry installation
id: cached-poetry
uses: actions/cache@v4
- uses: astral-sh/setup-uv@v2
with:
path: ~/.local
key: poetry-${{ runner.os }}
- name: Install Poetry
if: steps.cached-poetry.outputs.cache-hit != 'true'
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
virtualenvs-path: .venv
installer-parallel: true
- name: Enforce poetry config
run: |
poetry config virtualenvs.in-project true
poetry config virtualenvs.create true
poetry config virtualenvs.path .venv
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
enable-cache: true
cache-dependency-glob: uv.lock
- uses: actions/setup-python@v5
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: make setup
python-version-file: .python-version
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
Expand Down Expand Up @@ -165,38 +113,13 @@ jobs:
run: |
KATANA_VERSION=$(grep -oP '^KATANA_VERSION = \K.*' Makefile)
echo "katana_version=$KATANA_VERSION" >> "$GITHUB_OUTPUT"
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: 3.10.14
- name: Load cached Poetry installation
id: cached-poetry
uses: actions/cache@v4
- uses: astral-sh/setup-uv@v2
with:
path: ~/.local
key: poetry-${{ runner.os }}
- name: Install Poetry
if: steps.cached-poetry.outputs.cache-hit != 'true'
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
virtualenvs-path: .venv
installer-parallel: true
- name: Enforce poetry config
run: |
poetry config virtualenvs.in-project true
poetry config virtualenvs.create true
poetry config virtualenvs.path .venv
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
enable-cache: true
cache-dependency-glob: uv.lock
- uses: actions/setup-python@v5
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: make setup
python-version-file: .python-version
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
Expand Down Expand Up @@ -294,38 +217,13 @@ jobs:
if: needs.paths-filter.outputs.src == 'true'
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10.14
uses: actions/setup-python@v5
with:
python-version: 3.10.14
- name: Load cached Poetry installation
id: cached-poetry
uses: actions/cache@v4
- uses: astral-sh/setup-uv@v2
with:
path: ~/.local
key: poetry-${{ runner.os }}
- name: Install Poetry
if: steps.cached-poetry.outputs.cache-hit != 'true'
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
virtualenvs-path: .venv
installer-parallel: true
- name: Enforce poetry config
run: |
poetry config virtualenvs.in-project true
poetry config virtualenvs.create true
poetry config virtualenvs.path .venv
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
enable-cache: true
cache-dependency-glob: uv.lock
- uses: actions/setup-python@v5
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: make setup
python-version-file: .python-version
- name: Load performance artifacts
uses: actions/download-artifact@v3
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ tests/ef_tests/test_data
!tests/ef_tests/test_data/.gitkeep

bin/
dist

# test data
*.pb.gz
Expand Down
2 changes: 1 addition & 1 deletion .trunk/trunk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ lint:
- linters: [bandit]
paths: [tests, docker]
- linters: [codespell]
paths: [poetry.lock]
paths: [uv.lock]
- linters: [ALL]
paths:
- cairo1_contracts
Expand Down
23 changes: 10 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ BUILD_DIR = build
SSJ_DIR = $(BUILD_DIR)/ssj
SSJ_ZIP = dev-artifacts.zip

build: $(SSJ_DIR) check
poetry run python ./kakarot_scripts/compile_kakarot.py
build: $(SSJ_DIR)
uv run compile

check:
poetry check --lock
deploy: build build-sol
uv run deploy

$(SSJ_DIR): $(SSJ_ZIP)
rm -rf $(SSJ_DIR)
Expand All @@ -36,20 +36,17 @@ fetch-ef-tests:
poetry run python ./kakarot_scripts/ef_tests/fetch.py

setup:
poetry install
uv sync --all-extras --dev

test: deploy
poetry run pytest tests/src -m "not NoCI" --log-cli-level=INFO -n logical --seed 42
poetry run pytest tests/end_to_end --seed 42
uv run pytest tests/src -m "not NoCI" --log-cli-level=INFO -n logical --seed 42
uv run pytest tests/end_to_end --seed 42

test-unit: build-sol
poetry run pytest tests/src -m "not NoCI" -n logical --seed 42
uv run pytest tests/src -m "not NoCI" -n logical --seed 42

test-end-to-end: deploy
poetry run pytest tests/end_to_end --seed 42

deploy: build build-sol
poetry run python ./kakarot_scripts/deploy_kakarot.py
uv run pytest tests/end_to_end --seed 42

format:
trunk check --fix
Expand All @@ -64,7 +61,7 @@ clean:
mkdir -p $(BUILD_DIR)

check-resources:
poetry run python kakarot_scripts/check_resources.py
uv run python kakarot_scripts/check_resources.py

build-sol:
git submodule update --init --recursive
Expand Down
17 changes: 6 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,14 @@ The set of Cairo programs in this repository are represented below:
To contribute, please check out
[the contribution guide](./docs/CONTRIBUTING.md).

The easiest way to get started is to use
[`devcontainers`](https://containers.dev/):

- either directly from GitHub to have an online VSCode with everything ready
![Codespaces](./docs/img/codespaces.png)
- or from VSCode, open the project and use "Dev Containers: Rebuild container"
(requires Docker on your host machine)
## Build

Otherwise, you can proceed with a regular installation on your host. The
environment setup instructions are available in the
[contribution guide](./docs/CONTRIBUTING.md).
The project uses [uv](https://github.com/astral-sh/uv) to manage python
dependencies and run commands. To install uv:

## Build
```bash
curl -L https://install.astral.sh | bash
```

To build the CairoZero files:

Expand Down
26 changes: 8 additions & 18 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@ However, we ask that you follow these guidelines when contributing:
To get started on Kakarot, you'll need python3.10, as well as Starknet-related
libraries, e.g. `cairo-lang`.

- Install [pyenv](https://github.com/pyenv/pyenv) to manage your Python versions
(and don't forget to
[setup your shell](https://github.com/pyenv/pyenv?tab=readme-ov-file#set-up-your-shell-environment-for-pyenv))
- Download the Python version used for Kakarot using pyenv: `pyenv install 3.10`
- Install [poetry](https://python-poetry.org/docs/)
- Install [uv](https://github.com/astral-sh/uv) to manage python dependencies
and run commands
- Install
[cargo](https://doc.rust-lang.org/cargo/getting-started/installation.html) to
manage our Rust dependencies
Expand Down Expand Up @@ -71,40 +68,37 @@ To set up a development environment, please follow these steps:
git clone https://github.com/kkrt-labs/kakarot && cd kakarot
```

2. Create and activate a virtual environment specifically for your Python
project by running `poetry shell`.

3. Install dependencies
2. Install dependencies

```sh
make setup
```

4. Install katana
3. Install katana

```sh
make install-katana
```

5. Build the Solidity contracts
4. Build the Solidity contracts

```sh
make build-sol
```

6. Copy the default environment variables
5. Copy the default environment variables

```sh
cp .env.example .env
```

7. Start a local katana instance
6. Start a local katana instance

```sh
make run-katana
```

8. Run tests
7. Run tests

```sh
make test
Expand All @@ -121,10 +115,6 @@ Common caveats:
# example: ln -s /Users/eliastazartes/code/kakarot/.venv/bin/starknet-compile-deprecated /usr/local/bin/starknet-compile
```

If you followed the instructions above, you can run
`poetry show cairo-lang -v` to find the path to your cairo-lang dependency,
and the binaries should be in the `bin` directory.

- Mac M1 chips are subject to some quirks/bugs with regards to some
cryptographic libraries used by `cairo-lang`.
- you may need to run `brew install gmp`.
Expand Down
1 change: 0 additions & 1 deletion kakarot_scripts/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ class NetworkType(Enum):
"type": NetworkType.DEV,
"check_interval": 0.01,
"max_wait": 3,
"class_hash": 0x6153CCF69FD20F832C794DF36E19135F0070D0576144F0B47F75A226E4BE530,
"relayers": [
{
"address": 0xB3FF441A68610B30FD5E2ABBF3A1548EB6BA6F3559F2862BF2DC757E5828CA,
Expand Down
9 changes: 7 additions & 2 deletions kakarot_scripts/deploy_kakarot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# %% Imports
import logging
from asyncio import run

from uvloop import run

from kakarot_scripts.constants import (
ARACHNID_PROXY_DEPLOYER,
Expand Down Expand Up @@ -185,5 +186,9 @@ async def main():


# %% Run
if __name__ == "__main__":
def main_sync():
run(main())


if __name__ == "__main__":
main_sync()
Loading
Loading