Skip to content

Commit

Permalink
✨ Migrate from Poetry to UV for build System (#234)
Browse files Browse the repository at this point in the history
* ♻️ migrate from Poetry to Hatch for build system

* 🔥 remove Poetry configuration across multiple modules

* ♻️ update project dependencies to use direct paths and migrate to Hatch

* ♻️ migrate from Poetry to uv for dependency management and update related scripts and documentation

* update abis

* update abis

* 🐛 exclude JSON files from end-of-file fixer in pre-commit configuration

* 🐛 fix missing dependencies

* ♻️ update dependencies across multiple projects for consistency and compatibility

* ♻️ update dependency versions for consistency and compatibility

* 🐛 update pytest configuration for async fixtures and improve event loop fixture

* fix: checkpointer test

* 🐛 add pytest configuration for asyncio and improve event loop management

* 🐛 fix checkpointer tests

* 🐛 fix event loop scope in fixtures and update fixture parameters

* fix: deploy oracle fixture

* ✨ fix Linting issue

* fix: okx future fetcher test

* feat: add Docker image build workflow and integrate with pull request process

* 🐛 specify Dockerfile path in docker-test workflow

* ♻️ remove `merkle-maker` from docker-test workflow package matrix

* ✨ update Dockerfile to install pipx correctly and improve stage naming

* ♻️ streamline Dockerfile by consolidating dependency

* ♻️ update Dockerfile to install uv from GitHub and streamline commands

* ♻️ refactor Dockerfiles to standardize build stages and improve package version extraction

* ♻️ update workflows to standardize package version extraction by normalizing package paths

* ✨ fix the current version of the SDK

---------

Co-authored-by: 0xevolve <[email protected]>
  • Loading branch information
yezz123 and EvolveArt authored Dec 26, 2024
1 parent adb6bd0 commit 9ac4f8e
Show file tree
Hide file tree
Showing 171 changed files with 12,565 additions and 21,261 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
TESTNET_ACCOUNT_ADDRESS=
TESTNET_PRIVATE_KEY=
TESTNET_PRIVATE_KEY=
3 changes: 2 additions & 1 deletion .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ jobs:

- name: Extract package version
run: |
export PACKAGE_VERSION=$(grep 'version = "' ./${{ matrix.package }}/pyproject.toml | grep -m 1 -e '[0-9][0-9a-zA-Z]*[-.a-z0-9]*' -o)
PKG_PATH=$(echo ${{ matrix.package }} | tr '-' '_')
export PACKAGE_VERSION=$(grep -o '".*"' ./${{ matrix.package }}/$PKG_PATH/__init__.py | tr -d '"')
echo "PACKAGE_VERSION=$PACKAGE_VERSION" >> $GITHUB_ENV
echo $PACKAGE_VERSION
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/docker-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
name: Task - Build Docker Image

on:
workflow_dispatch:
workflow_call:

jobs:
build_containers:
strategy:
matrix:
package: [pragma-sdk, price-pusher, vrf-listener, checkpointer]
runs-on: ubuntu-latest
permissions:
checks: write
contents: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up QEMU
uses: docker/[email protected]
- name: Set up Docker Buildx
uses: docker/[email protected]
- name: Extract package version
if: matrix.package == 'pragma-sdk'
run: |
PKG_PATH=$(echo ${{ matrix.package }} | tr '-' '_')
export PACKAGE_VERSION=$(grep -o '".*"' ./${{ matrix.package }}/$PKG_PATH/__init__.py | tr -d '"')
echo "PACKAGE_VERSION=$PACKAGE_VERSION" >> $GITHUB_ENV
echo $PACKAGE_VERSION
- name: Build Docker Image
id: docker_build
uses: docker/[email protected]
with:
context: .
file: ./${{ matrix.package }}/Dockerfile
build-args: ${{ matrix.package == 'pragma-sdk' && format('PRAGMA_PACKAGE_VERSION={0}', env.PACKAGE_VERSION) || '' }}
56 changes: 14 additions & 42 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
@@ -1,57 +1,29 @@
---
name: Task - Lint, Format & Typecheck

on:
workflow_dispatch:
workflow_call:

env:
PYTHON_VERSION: 3.12.4
PYTHON_VERSION: 3.12

jobs:
lint-format-typecheck:
continue-on-error: true
lint:
runs-on: ubuntu-latest
strategy:
matrix:
package:
[
pragma-utils,
pragma-sdk,
price-pusher,
vrf-listener,
checkpointer,
merkle-maker,
lp-pricer,
]
fail-fast: false
steps:
- uses: actions/checkout@v3
- uses: CfirTsabari/actions-pipx@v1
- name: Install poetry
run: pipx install poetry
- name: Set up Python 3.12.4
uses: actions/setup-python@v4
- uses: actions/checkout@v4

- uses: astral-sh/setup-uv@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: "poetry"
enable-cache: true

- name: Install dependencies
run: |
cd ${{ matrix.package }}
poetry install
- name: Check poetry.lock
run: |
cd ${{ matrix.package }}
poetry lock --check
- name: Run lint
run: |
cd ${{ matrix.package }}
poetry run poe lint
- name: Run format
run: |
cd ${{ matrix.package }}
poetry run poe format_check
- name: Run typecheck
run: |
cd ${{ matrix.package }}
poetry run poe typecheck
run: uv sync --python ${{ env.PYTHON_VERSION }} --all-extras

- uses: pre-commit/[email protected]
with:
extra_args: --all-files --verbose
env:
SKIP: no-commit-to-branch
31 changes: 21 additions & 10 deletions .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,26 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: CfirTsabari/actions-pipx@v1
- name: Install poetry
run: pipx install poetry
- uses: actions/setup-python@v5

- name: set up python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: "poetry"
- run: pipx inject poetry poetry-monorepo-dependency-plugin
- run: poetry config repositories.test-pypi https://test.pypi.org/legacy/
- run: poetry config pypi-token.test-pypi ${{ secrets.TEST_PYPI_API_TOKEN }}
- run: poetry build -f sdist
- run: poetry publish -r test-pypi --skip-existing

- name: install
run: pip install -U build

- name: check version
id: check-tag
uses: samuelcolvin/[email protected]
with:
version_file_path: pragma_sdk/__init__.py

- name: build
run: python -m build

- name: Upload package to PyPI
uses: pypa/[email protected]
with:
repository-url: https://test.pypi.org/legacy/
password: ${{ secrets.PYPI_API_TOKEN }}
74 changes: 15 additions & 59 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,70 +8,26 @@ defaults:
run:
working-directory: pragma-sdk

env:
PYTHON_VERSION: 3.12.4

jobs:
bump_version:
release:
name: Pypi Publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
- uses: actions/checkout@v4

- uses: astral-sh/setup-uv@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install Commitizen
run: pip install --upgrade Commitizen
- name: Configure Git
run: |
git config user.name github-actions
git config user.email [email protected]
- name: Bump version
run: |
git fetch --tags
cz bump --retry || echo "probably nothing to do"
- name: Push changes
run: |
TAG=$(git tag --points-at HEAD)
if [[ $TAG ]]; then
echo "Version bumped to $TAG"
git push
git push --tags
else
echo "Version NOT bumped"
fi
enable-cache: true

pypi_publish:
needs: [bump_version]
name: Upload package to PyPI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: CfirTsabari/actions-pipx@v1
- name: Install poetry
run: pipx install poetry
- uses: actions/setup-python@v5
- name: check GITHUB_REF matches package version
uses: samuelcolvin/[email protected]
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: "poetry"
- run: pipx inject poetry poetry-monorepo-dependency-plugin
- run: poetry config pypi-token.pypi "${{ secrets.PYPI_API_KEY }}"
- run: poetry build -f sdist
- run: poetry publish --skip-existing
version_file_path: pragma_sdk/__init__.py

update_lock:
needs: [pypi_publish]
name: Update lock file
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: CfirTsabari/actions-pipx@v1
- name: Install poetry
run: pipx install poetry
- uses: actions/setup-python@v5
- run: uv build

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: "poetry"
- run: sh scripts/poetry_lock_update.sh
password: ${{ secrets.PYPI_API_KEY }}
skip-existing: true
4 changes: 4 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ jobs:
tests:
name: Build & Integration Tests
uses: ./.github/workflows/tests.yml

build_containers:
name: Build Docker Image
uses: ./.github/workflows/docker-test.yml
34 changes: 15 additions & 19 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
workflow_call:

env:
PYTHON_VERSION: 3.12.4
PYTHON_VERSION: 3.12

jobs:
tests:
Expand All @@ -26,27 +26,23 @@ jobs:
]
fail-fast: false
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: "true"
- uses: CfirTsabari/actions-pipx@v1
- name: Install poetry
run: pipx install poetry
- uses: actions/setup-python@v4
- uses: astral-sh/setup-uv@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: "poetry"
enable-cache: true
- name: Install dependencies
run: |
cd ${{ matrix.package }}
poetry install
uv sync --python ${{ env.PYTHON_VERSION }} --all-extras
- name: Cache contracts
id: cache-contracts
uses: actions/cache@v3
with:
path: ./pragma-oracle/pragma-oracle/target
key: ${{ runner.os }}-contracts-${{ hashFiles('./pragma-oracle/pragma-oracle/src', 'poetry.lock') }}
key: ${{ runner.os }}-contracts-${{ hashFiles('./pragma-oracle/pragma-oracle/src') }}

- uses: software-mansion/setup-scarb@v1
with:
Expand All @@ -66,7 +62,7 @@ jobs:
# Extract the relative path of the file for comparison
rel_path=${file#./pragma-oracle/pragma-oracle/target/dev}
# Use diff to compare the file with its counterpart in the SDK directory
diff "$file" "pragma-sdk/pragma_sdk/onchain/abis$rel_path" || (echo "Error: $rel_path in pragma-oracle/target does not match with pragma-sdk/pragma_sdk/onchain/abis/" && exit 1)
diff "$file" "pragma-sdk/pragma_sdk/onchain/abis$rel_path" || (echo "Error: $rel_path in pragma-oracle/target does not match with pragma-sdk/pragma_sdk/onchain/abis/" && exit 1)
done
- name: Install rust
run: |
Expand All @@ -87,19 +83,19 @@ jobs:
# See: https://github.com/astraly-labs/pragma-sdk/issues/153
cd ${{ matrix.package }}
if [ "${{ matrix.package }}" = "pragma-sdk" ]; then
poetry run poe test_client
poetry run poe test_vrf
poetry run poe test_fetchers
poetry run poe test_merkle_feed
poetry run poe test_unit
poetry run poe test_update_client
uv run poe test_client
uv run poe test_vrf
uv run poe test_fetchers
uv run poe test_merkle_feed
uv run poe test_unit
uv run poe test_update_client
else
poetry run poe test
uv run poe test
fi
- name: Generate coverage in XML
run: |
cd ${{ matrix.package }}
poetry run coverage xml
uv run coverage xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
env:
Expand Down
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "pragma-oracle"]
path = pragma-oracle
url = https://github.com/Astraly-Labs/pragma-oracle.git
url = https://github.com/Astraly-Labs/pragma-oracle.git
21 changes: 21 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-toml
- id: check-yaml
args: [ --allow-multiple-documents ]
- id: end-of-file-fixer
exclude: '.*\.json$'
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.1
hooks:
- id: ruff
args:
- --fix
- id: ruff-format
11 changes: 5 additions & 6 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ build:
python: "3.12"
jobs:
post_create_environment:
# Install poetry
# https://python-poetry.org/docs/#installing-manually
- python -m pip install poetry
# Install uv
# https://docs.astral.sh/uv/
- python -m pip install uv
post_install:
# Install only dependencies including docs
# https://python-poetry.org/docs/managing-dependencies/#dependency-groups
- cd pragma-sdk && VIRTUAL_ENV=$READTHEDOCS_VIRTUALENV_PATH poetry install --with docs && cd ..
- cd pragma-sdk && VIRTUAL_ENV=$READTHEDOCS_VIRTUALENV_PATH uv sync --all-extras && cd ..

sphinx:
configuration: pragma-sdk/docs/source/conf.py
fail_on_warning: true
fail_on_warning: true
Loading

0 comments on commit 9ac4f8e

Please sign in to comment.